Exemple #1
0
        private void DrawRoute(CalculateRouteCompletedEventArgs e)
        {
            var points = e.Result.Result.RoutePath.Points;

            GetTextDetailsOfRoute(e.Result.Result.Legs[0]);

            SpeakText(routeText[0]);
            var coordinates = points.Select(x => new GeoCoordinate(x.Latitude, x.Longitude));

            var routeColor = Colors.Blue;
            var routeBrush = new SolidColorBrush(routeColor);

            var routeLine = new MapPolyline()
            {
                Locations       = new LocationCollection(),
                Stroke          = routeBrush,
                Opacity         = 0.65,
                StrokeThickness = 5.0,
            };

            foreach (var location in points)
            {
                routeLine.Locations.Add(location);
            }

            RouteLayer.Children.Add(routeLine);
        }
        private void Route_Complete(object sender, CalculateRouteCompletedEventArgs args)
        {
            myDrawObject.IsEnabled = true;
            routeResultsGraphicsLayer.ClearGraphics();
            waypointGraphicsLayer.ClearGraphics();

            StringBuilder directions = new StringBuilder();

            ObservableCollection <RouteLeg> routeLegs = args.Result.Result.Legs;
            int numLegs          = routeLegs.Count;
            int instructionCount = 0;

            for (int n = 0; n < numLegs; n++)
            {
                if ((n % 2) == 0)
                {
                    AddStopPoint(mercator.FromGeographic(new MapPoint(routeLegs[n].ActualStart.Longitude, routeLegs[n].ActualStart.Latitude)) as MapPoint);
                    AddStopPoint(mercator.FromGeographic(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)) as MapPoint);
                }
                else if (n == (numLegs - 1))
                {
                    AddStopPoint(mercator.FromGeographic(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)) as MapPoint);
                }

                directions.Append(string.Format("--Leg #{0}--\n", n + 1));

                foreach (ItineraryItem item in routeLegs[n].Itinerary)
                {
                    instructionCount++;
                    directions.Append(string.Format("{0}. {1}\n", instructionCount, item.Text));
                }
            }

            Regex regex = new Regex("<[/a-zA-Z:]*>",
                                    RegexOptions.IgnoreCase | RegexOptions.Multiline);

            DirectionsContentTextBlock.Text = regex.Replace(directions.ToString(), string.Empty);
            DirectionsGrid.Visibility       = Visibility.Visible;

            RoutePath routePath = args.Result.Result.RoutePath;

            Polyline line = new Polyline();

            line.Paths.Add(new PointCollection());

            foreach (ESRI.ArcGIS.Client.Bing.RouteService.Location location in routePath.Points)
            {
                line.Paths[0].Add(mercator.FromGeographic(new MapPoint(location.Longitude, location.Latitude)) as MapPoint);
            }

            Graphic graphic = new Graphic()
            {
                Geometry = line,
                Symbol   = LayoutRoot.Resources["RoutePathSymbol"] as Symbol
            };

            routeResultsGraphicsLayer.Graphics.Add(graphic);
        }
 private void client_RouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
 {
     if (e.Result.ResponseSummary.StatusCode == Bing.Route.ResponseStatusCode.Success)
     {
         // Raise the found event on the UI thread.
         _uiDispatcher.BeginInvoke(() => _routeFound(e.Result));
     }
     else
     {
         // Report route error.
         _uiDispatcher.BeginInvoke(() => Error(new RouteCalculationError(e)));
     }
 }
        internal RouteCalculationError(CalculateRouteCompletedEventArgs e)
        {
            if (e.Result == null ||
                e.Result.ResponseSummary == null ||
                string.IsNullOrEmpty(e.Result.ResponseSummary.FaultReason))
            {
                Reason = NoResults;
            }
            else
            {
                Reason = e.Result.ResponseSummary.FaultReason;
            }

            Exception = e.Error;
        }
Exemple #5
0
        internal RouteCalculationError(CalculateRouteCompletedEventArgs e)
        {
            if (e.Result == null ||
                e.Result.ResponseSummary == null ||
                string.IsNullOrEmpty(e.Result.ResponseSummary.FaultReason))
            {
                Reason = NoResults;
            }
            else
            {
                Reason = e.Result.ResponseSummary.FaultReason;
            }

            Exception = e.Error;
        }
        void routeClient_CalculateRouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
        {
            string outString;
            try
            {
                if (e.Result.ResponseSummary.StatusCode != RouteService.ResponseStatusCode.Success)
                {
                    outString = "error routing ... status <" + e.Result.ResponseSummary.StatusCode.ToString() + ">";
                }
                else if (0 == e.Result.Result.Legs.Count)
                {
                    outString = "Cannot find route";
                }
                else
                {
                    LocationCollection coll = new LocationCollection();
                    foreach (Location p in e.Result.Result.RoutePath.Points)
                    {
                        coll.Add(new Location(p.Latitude, p.Longitude));
                    }

                    Messenger.Default.Send<Messages.RouteDoneMessage>(new Messages.RouteDoneMessage { Legs = e.Result.Result.Legs, Locations = coll}, "RouteDone");

                }
            }
            catch (Exception)
            {
                outString = "Exception raised routine";
            }

            // ToOutput.Text = outString;
        }
Exemple #7
0
        void routeService_CalculateRouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
        {
            RouteResponse response = e.Result;

            if ((response.ResponseSummary.StatusCode == Panda.Phone.Publisher.RouteServiceReference.ResponseStatusCode.Success) && (response.Result.Legs.Count != 0))
            {
                Color color = Colors.Blue;
                // SolidColorBrush brush = new SolidColorBrush(color);
                SolidColorBrush brush = new SolidColorBrush(new Color()
                {
                    R = 6, G = 128, B = 67, A = 255
                });
                MapPolyline line = new MapPolyline();
                line.Locations       = new LocationCollection();
                line.Opacity         = 0.6;
                line.StrokeThickness = 10;
                line.Stroke          = brush;
                //DispatcherTimer timer = new DispatcherTimer();
                //timer.Interval = TimeSpan.FromMilliseconds(200);
                //timer.Tick += new EventHandler(timer_Tick);
                //timer.Start();
                MapLayer layer = new MapLayer();
                layer.Children.Add(line);
                map.Children.Add(layer);
                foreach (Location l in response.Result.RoutePath.Points)
                {
                    line.Locations.Add(l);
                }

                //foreach (GeocodeResult r in Georesults)
                //{
                //    Ellipse ellipse = new Ellipse();
                //    ellipse.Height = 10;
                //    ellipse.Width = 10;
                //    ellipse.Fill = new SolidColorBrush(Colors.Red);
                //    Location location = new Location()
                //    {
                //        Latitude = r.Locations[0].Latitude,
                //        Longitude = r.Locations[0].Longitude
                //    };
                //    layer.AddChild(ellipse, location);
                //}

                foreach (UserModel user in list_User_Choosed)
                {
                    Ellipse ellipse = new Ellipse();
                    ellipse.Height = 10;
                    ellipse.Width  = 10;
                    ellipse.Fill   = new SolidColorBrush(new Color()
                    {
                        A = 0
                    });
                    Location location = new Location()
                    {
                        Latitude  = user.Latitude,
                        Longitude = user.Longitude
                    };
                    layer.AddChild(ellipse, location);
                }
                //GeoCoordinate p = new GeoCoordinate(Georesults[1].Locations[0].Latitude, Georesults[1].Locations[0].Longitude);
                // var routeModel = new RouteModel(e.Result.Result.RoutePath.Points);
                //  LocationRect rect = LocationRect.CreateLocationRect(routeModel.Locations);

                // Set the map view using the rectangle which bounds the rendered route.
                // map.SetView(p, 8);
            }
        }
Exemple #8
0
 void routeClient_CalculateRouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
 {
     _wayPoints = e.Result.Result.RoutePath.Points;
 }
        void routeService_CalculateRouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
        {
            RouteResponse response = e.Result;
            if ((response.ResponseSummary.StatusCode == Panda.Phone.Publisher.RouteServiceReference.ResponseStatusCode.Success) && (response.Result.Legs.Count != 0))
            {
                Color color = Colors.Blue;
                // SolidColorBrush brush = new SolidColorBrush(color);
                SolidColorBrush brush = new SolidColorBrush(new Color() { R = 6, G = 128, B = 67, A = 255 });
                MapPolyline line = new MapPolyline();
                line.Locations = new LocationCollection();
                line.Opacity = 0.6;
                line.StrokeThickness = 10;
                line.Stroke = brush;
                //DispatcherTimer timer = new DispatcherTimer();
                //timer.Interval = TimeSpan.FromMilliseconds(200);
                //timer.Tick += new EventHandler(timer_Tick);
                //timer.Start();
                MapLayer layer = new MapLayer();
                layer.Children.Add(line);
                map.Children.Add(layer);
                foreach (Location l in response.Result.RoutePath.Points)
                {
                    line.Locations.Add(l);
                }

                //foreach (GeocodeResult r in Georesults)
                //{
                //    Ellipse ellipse = new Ellipse();
                //    ellipse.Height = 10;
                //    ellipse.Width = 10;
                //    ellipse.Fill = new SolidColorBrush(Colors.Red);
                //    Location location = new Location()
                //    {
                //        Latitude = r.Locations[0].Latitude,
                //        Longitude = r.Locations[0].Longitude
                //    };
                //    layer.AddChild(ellipse, location);
                //}

                foreach (UserModel user in list_User_Choosed)
                {
                    Ellipse ellipse = new Ellipse();
                    ellipse.Height = 10;
                    ellipse.Width = 10;
                    ellipse.Fill = new SolidColorBrush(new Color() { A = 0 });
                    Location location = new Location()
                    {
                        Latitude = user.Latitude,
                        Longitude = user.Longitude
                    };
                    layer.AddChild(ellipse, location);
                }
                //GeoCoordinate p = new GeoCoordinate(Georesults[1].Locations[0].Latitude, Georesults[1].Locations[0].Longitude);
                // var routeModel = new RouteModel(e.Result.Result.RoutePath.Points);
                //  LocationRect rect = LocationRect.CreateLocationRect(routeModel.Locations);

                // Set the map view using the rectangle which bounds the rendered route.
                // map.SetView(p, 8);
            }

        }
Exemple #10
0
        private void DrawRoute(CalculateRouteCompletedEventArgs e)
        {
            var points = e.Result.Result.RoutePath.Points;

            GetTextDetailsOfRoute(e.Result.Result.Legs[0]);

           SpeakText(routeText[0]);
            var coordinates = points.Select(x => new GeoCoordinate(x.Latitude, x.Longitude));

            var routeColor = Colors.Blue;
            var routeBrush = new SolidColorBrush(routeColor);

            var routeLine = new MapPolyline()
            {
                Locations = new LocationCollection(),
                Stroke = routeBrush,
                Opacity = 0.65,
                StrokeThickness = 5.0,
            };

            foreach (var location in points)
            {
                routeLine.Locations.Add(location);
            }
           
            RouteLayer.Children.Add(routeLine);
        }
Exemple #11
0
        private void routeService_CalculateRouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
        {
            // If the route calculate was a success and contains a route, then draw the route on the map.
            if ((e.Result.ResponseSummary.StatusCode == ResponseStatusCode.Success) & (e.Result.Result.Legs.Count != 0))
            {
                // Set properties of the route line you want to draw.
                Color routeColor = Colors.Blue;
                SolidColorBrush routeBrush = new SolidColorBrush(routeColor);
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Stroke = routeBrush;
                routeLine.Opacity = 0.65;
                routeLine.StrokeThickness = 5.0;

                // Retrieve the route points that define the shape of the route.
                foreach (Location p in e.Result.Result.RoutePath.Points)
                {
                    routeLine.Locations.Add(new GeoCoordinate() { Latitude = p.Latitude, Longitude = p.Longitude });
                }

                if (!(map.Children.Contains(myRouteLayer)))
                {
                    // Add a map layer in which to draw the route.
                    map.Children.Add(myRouteLayer);
                    if (!(myRouteLayer.Children.Contains(routeLine)))
                    {
                        // Add the route line to the new layer.
                        myRouteLayer.Children.Add(routeLine);
                    }
                }

                // Figure the rectangle which encompasses the route. This is used later to set the map view.
                double x = 0;
                double y = 0;
                double h = 0;
                double w = 0;

                if(watcher.Position.Location.Latitude < final.Location.Latitude && watcher.Position.Location.Longitude > final.Location.Longitude)
                {
                    x = watcher.Position.Location.Latitude + (final.Location.Latitude - watcher.Position.Location.Latitude) / 2;
                    y = watcher.Position.Location.Longitude - (watcher.Position.Location.Longitude - final.Location.Longitude)/2;
                    w = final.Location.Latitude - watcher.Position.Location.Latitude;
                    h = watcher.Position.Location.Longitude - final.Location.Longitude;
                }
                else if(watcher.Position.Location.Latitude < final.Location.Latitude && watcher.Position.Location.Longitude < final.Location.Longitude)
                {
                    x = watcher.Position.Location.Latitude + (final.Location.Latitude - watcher.Position.Location.Latitude) / 2;
                    y = watcher.Position.Location.Longitude + (final.Location.Longitude - watcher.Position.Location.Longitude) / 2;
                    w = final.Location.Latitude - watcher.Position.Location.Latitude;
                    h = final.Location.Longitude - watcher.Position.Location.Longitude;
                }
                else if(watcher.Position.Location.Latitude > final.Location.Latitude && watcher.Position.Location.Longitude > final.Location.Longitude)
                {
                    x = watcher.Position.Location.Latitude - (watcher.Position.Location.Latitude - final.Location.Latitude) / 2;
                    y = watcher.Position.Location.Longitude - (watcher.Position.Location.Longitude - final.Location.Longitude) / 2;
                    w = watcher.Position.Location.Latitude - final.Location.Latitude;
                    h = watcher.Position.Location.Longitude - final.Location.Longitude;
                }
                else
                {
                    x = watcher.Position.Location.Latitude - (watcher.Position.Location.Latitude - final.Location.Latitude) / 2;
                    y = watcher.Position.Location.Longitude + (final.Location.Longitude - watcher.Position.Location.Longitude) / 2;
                    w = watcher.Position.Location.Latitude - final.Location.Latitude;
                    h = final.Location.Longitude - watcher.Position.Location.Longitude;
                }
                GeoCoordinate centro = new GeoCoordinate(x, y);
                LocationRect rect = new LocationRect(centro,w,h);
                // For each geocode result (which are the waypoints of the route), draw a dot on the map.
                /*foreach (GeocodeService.GeocodeResult gr in geocodeResults)
                {
                    Ellipse point = new Ellipse();
                    point.Width = 10;
                    point.Height = 10;
                    point.Fill = new SolidColorBrush(Colors.Red);
                    point.Opacity = 0.65;
                    Location location = new Location(gr.Locations[0].Latitude, gr.Locations[0].Longitude);
                    MapLayer.SetPosition(point, location);
                    MapLayer.SetPositionOrigin(point, PositionOrigin.Center);

                    // Add the drawn point to the route layer.
                    myRouteLayer.Children.Add(point);
                }*/

                // Set the map view using the rectangle which bounds the rendered route.
                map.SetView(rect);
            }
        }
        private void Route_Complete(object sender, CalculateRouteCompletedEventArgs args)
        {
            myDrawObject.IsEnabled = true;
            routeResultsGraphicsLayer.ClearGraphics();
            waypointGraphicsLayer.ClearGraphics();

            StringBuilder directions = new StringBuilder();

            ObservableCollection<RouteLeg> routeLegs = args.Result.Result.Legs;
            int numLegs = routeLegs.Count;
            int instructionCount = 0;
            for (int n = 0; n < numLegs; n++)
            {
                if ((n % 2) == 0)
                {
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualStart.Longitude, routeLegs[n].ActualStart.Latitude)));
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
                }
                else if (n == (numLegs - 1))
                {
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
                }

                directions.Append(string.Format("--Leg #{0}--\n", n + 1));

                foreach (ItineraryItem item in routeLegs[n].Itinerary)
                {
                    instructionCount++;
                    directions.Append(string.Format("{0}. {1}\n", instructionCount, item.Text));
                }
            }

            Regex regex = new Regex("<[/a-zA-Z:]*>",
                RegexOptions.IgnoreCase | RegexOptions.Multiline);

            DirectionsContentTextBlock.Text = regex.Replace(directions.ToString(), string.Empty);
            DirectionsGrid.Visibility = Visibility.Visible;

            RoutePath routePath = args.Result.Result.RoutePath;

            Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline();
            line.Paths.Add(new ESRI.ArcGIS.Client.Geometry.PointCollection());

            foreach (ESRI.ArcGIS.Client.Bing.RouteService.Location location in routePath.Points)
                line.Paths[0].Add(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(location.Longitude, location.Latitude)));

            Graphic graphic = new Graphic()
            {
                Geometry = line,
                Symbol = LayoutRoot.Resources["RoutePathSymbol"] as Symbol
            };
            routeResultsGraphicsLayer.Graphics.Add(graphic);
        }
 private void client_RouteCompleted(object sender, CalculateRouteCompletedEventArgs e)
 {
     if (e.Result.ResponseSummary.StatusCode == Bing.Route.ResponseStatusCode.Success)
     {
         // Raise the found event on the UI thread.
         _uiDispatcher.BeginInvoke(() => _routeFound(e.Result));
     }
     else
     {
         // Report route error.
         _uiDispatcher.BeginInvoke(() => Error(new RouteCalculationError(e)));
     }
 }
Exemple #14
0
        /// <summary>
        /// Event executed when the calculation is finished.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Route_Complete(object sender, CalculateRouteCompletedEventArgs args)
        {
            try
            {
                gisOperations.EnableDrawMode();
                RoutingEventArgs routeArgs = new RoutingEventArgs();
                List<string> directions = new List<string>();
                if (args.Error != null)
                {
                    directions.Add(args.Error.Message);
                    routeArgs.RoutingResult.Directions = directions;
                }
                else
                {
                    ObservableCollection<RouteLeg> routeLegs = args.Result.Result.Legs;
                    int numLegs = routeLegs.Count;
                    int instructionCount = 0;
                    for (int n = 0; n < numLegs; n++)
                    {
                        directions.Add(string.Format("--Leg #{0}--\n", n + 1));

                        foreach (ItineraryItem item in routeLegs[n].Itinerary)
                        {
                            instructionCount++;
                            directions.Add(string.Format("{0}. {1}\n", instructionCount, item.Text));
                        }
                    }

                    Regex regex = new Regex("<[/a-zA-Z:]*>",
                    RegexOptions.IgnoreCase | RegexOptions.Multiline);

                    RoutePath routePath = args.Result.Result.RoutePath;

                    Polyline line = new Polyline();
                    line.Paths.Add(new PointCollection());

                    foreach (Location location in routePath.Points)
                        line.Paths[0].Add(mercator.FromGeographic(new MapPoint(location.Longitude, location.Latitude)) as MapPoint);

                    Graphic graphic = new Graphic()
                    {
                        Geometry = line,
                        Symbol = this.lineRouteSymbol as Symbol
                    };
                    graphicsRouteLayer.Graphics.Add(graphic);

                    routeArgs.RoutingResult.Directions = directions;
                    routeArgs.RoutingResult.RouteLine = line;
                }
                gisOperations.DisableDrawMode();
                OnRoutingCalcComplete(routeArgs);

            }
            catch (Exception ex)
            {
                messageBoxCustom.Show(String.Format("Route_Complete /{0}", ex.Message),
                    GisTexts.SevereError,
                    MessageBoxCustomEnum.MessageBoxButtonCustom.Ok);
            }
        }