コード例 #1
0
        private void ShowRoute()
        {
            if (webBrowserLoaded)
            {
                if (this.DataContext == null)
                {
                    return;
                }

                if (lastRoute == this.DataContext)
                {
                    return;
                }

                lastRoute = this.DataContext;

                IEnumerable <RouteMapViewResult> route = this.DataContext as IEnumerable <RouteMapViewResult>;

                IEnumerable <RouteMapViewResult> sortedRoute =
                    from RouteMapViewResult stop in route
                    orderby stop.StopSequenceNumber
                    select stop;


                List <MapLocation> mapLocations = new List <MapLocation>();

                foreach (RouteMapViewResult line in sortedRoute)
                {
                    double latitude, longitude;

                    if (!string.IsNullOrEmpty(line.Latitude) &&
                        !line.Latitude.Contains(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
                    {
                        line.Latitude = line.Latitude.Replace(",", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                        line.Latitude = line.Latitude.Replace(".", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                    }

                    if (!string.IsNullOrEmpty(line.Longitude) &&
                        !line.Longitude.Contains(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
                    {
                        line.Longitude = line.Longitude.Replace(",", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                        line.Longitude = line.Longitude.Replace(".", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                    }

                    if (double.TryParse(line.Latitude, out latitude) &&
                        double.TryParse(line.Longitude, out longitude))
                    {
                        try
                        {
                            //LatLong position = StringToLatLongConverter.ToLatLong(line.Instructions1);

                            LatLong position = new LatLong();
                            position.Latitude  = latitude;
                            position.Longitude = longitude;

                            mapLocations.Add(new MapLocation()
                            {
                                PushPin = new PushPin
                                {
                                    Identity    = line.NodeId,
                                    Title       = string.Format("{0}. {1}", line.StopSequenceNumber, line.NodeDescription),
                                    Description = string.Format("{0} {1}", line.TypeOfStopText, line.Instructions1),
                                },
                                Position = position
                            }
                                             );
                        }
                        catch (Exception)
                        {
                            // Suppress
                        }
                    }
                }

                mapController.InitMap();

                if (mapLocations.Count > 0)
                {
                    mapController.ShowRoute(mapLocations);
                }
                else
                {
                    mapController.SetDefaultMapLocation(StringToLatLongConverter.ToLatLong("N56 09 22.37 E13 45 58.82"));
                }
            }
        }