Select to view content in your preferred language

GPX Viewer

2079
7
06-23-2010 07:30 AM
CraigPerreault
New Contributor II
Does anyone have a code sample to view GPX files using the Silverlight API. 

In the code gallery for JAVA there is an example to read GPX files at:
http://resources.esri.com/arcgisserver/adf/java/index.cfm?fa=codeGalleryDetails&scriptID=16775
0 Kudos
7 Replies
DanielWalton
Occasional Contributor
Wait a few days. I suspect Morten is cooking something up...
0 Kudos
dotMorten_esri
Esri Notable Contributor
Haha Dan. Unfortunately I"m not working on what you think I'm working on.

Craig: You can use the GPX layer posted here: http://esrislcontrib.codeplex.com/
0 Kudos
CraigPerreault
New Contributor II
Bummer.  I have downloaded the latest from that post, but have not been able to get it to work.
There is an event but no code behind it (looks like this):

        private void btnLoadGPX_Click( object sender, RoutedEventArgs e )
        {

        }

I would really like to read a .GPX file by selecting one from the client machine.
0 Kudos
CraigPerreault
New Contributor II
For anyone interested in code that reads a GPX file from the client machine.

       private void btnLoadGPX_Click(object sender, RoutedEventArgs e)
        {
            //Create the dialog allowing the user to select a "*.GPX" file
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "GPX Files|*.gpx";
            ofd.Multiselect = false;

            if (!(ofd.ShowDialog() ?? false))
                return;

            StreamReader reader = new StreamReader(ofd.File.OpenRead());
            Stream contents = reader.BaseStream;

            gpxType _source = GPXReader.ReadGPX(contents);
            GraphicCollection graphicCollection = GPXHelper.LoadGraphics(_source);

            GraphicsLayer graphicsLayer = MyMap.Layers["gpxLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();

            foreach (Graphic gr in graphicCollection)
            {
                graphicsLayer.Graphics.Add(gr);
            }

            reader.Close();
        }
0 Kudos
ErikEngstrom
Occasional Contributor II
How are you folks handling the reprojection from WGS84 to Web Mercator?
Assuming most gpx tracks and waypoints are not in Web Mercator.

I'm assuming you could use the GeographicToWebMercator Method, but where specifically?
0 Kudos
ErikEngstrom
Occasional Contributor II
Nevermind, I figured it out...
For those that care:

In the GPXHelper.cs file of the Vishcious.ArcGIS.SLContrib GPXTypes folder..
I changed:
        
         public static MapPoint LoadWayPointGeometry( wptType wpt )
        {
            wpt.RequireArgument<wptType>( "wpt" ).NotNull<wptType>();
            return new MapPoint( ( double ) wpt.lon, ( double ) wpt.lat );
        }


To:
        public static MapPoint LoadWayPointGeometry( wptType wpt )
        {
                        wpt.RequireArgument<wptType>( "wpt" ).NotNull<wptType>();
   
                        MapPoint g = new MapPoint((double)wpt.lon, (double)wpt.lat);
   MapPoint mpGeom = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(g);
   return mpGeom;
        }
0 Kudos
OlgaDupont
New Contributor
Hi,

This is a old post but... is there a API to add GXP file to ArcGis server 10.2 using Silverlight

TY
0 Kudos