private async void SolveRouteClick(object sender, EventArgs e) { // Create a new route task using the San Diego route service URI RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri); // Get the default parameters from the route task (defined with the service) RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync(); // Make some changes to the default parameters routeParams.ReturnStops = true; routeParams.ReturnDirections = true; // Set the list of route stops that were defined at startup routeParams.SetStops(_routeStops); // Solve for the best route between the stops and store the result RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams); // Get the first (should be only) route from the result Route firstRoute = solveRouteResult.Routes.First(); // Get the route geometry (polyline) Polyline routePolyline = firstRoute.RouteGeometry; // Create a thick purple line symbol for the route SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Purple, 8.0); // Create a new graphic for the route geometry and add it to the graphics overlay Graphic routeGraphic = new Graphic(routePolyline, routeSymbol); _routeGraphicsOverlay.Graphics.Add(routeGraphic); // Get a list of directions for the route and display it in the list box DirectionsListBox.ItemsSource = firstRoute.DirectionManeuvers.Select(direction => direction.DirectionText); }
private async void MenuFlyoutGotoButton_Click(object sender, RoutedEventArgs e) { try { panelResults.Visibility = Visibility.Visible; progress.Visibility = Visibility.Visible; RouteParameters routeParams = await _routeTask.GetDefaultParametersAsync(); routeParams.OutSpatialReference = MyMapView.SpatialReference; routeParams.ReturnDirections = true; routeParams.DirectionsLengthUnit = LinearUnits.Kilometers; routeParams.DirectionsLanguage = new CultureInfo("es"); // CultureInfo.CurrentCulture; routeParams.SetStops(_stopsOverlay.Graphics); var routeResult = await _routeTask.SolveAsync(routeParams); if (routeResult == null || routeResult.Routes == null || routeResult.Routes.Count() == 0) { throw new Exception("No se pude calcular la ruta"); } var route = routeResult.Routes.First(); _routesOverlay.Graphics.Add(new Graphic(route.RouteFeature.Geometry)); _directionsOverlay.GraphicsSource = route.RouteDirections.Select(rd => GraphicFromRouteDirection(rd)); var totalTime = route.RouteDirections.Select(rd => rd.Time).Aggregate(TimeSpan.Zero, (p, v) => p.Add(v)); var totalLength = route.RouteDirections.Select(rd => rd.GetLength(LinearUnits.Kilometers)).Sum(); txtRouteTotals.Text = string.Format("Tiempo: {0:h':'mm':'ss} / Distancia: {1:0.00} km", totalTime, totalLength); await MyMapView.SetViewAsync(route.RouteFeature.Geometry.Extent.Expand(1.80)); } catch (AggregateException ex) { var message = ex.Message; var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { message = innermostExceptions[0].Message; } var _x = new MessageDialog(message, "Error").ShowAsync(); } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Error").ShowAsync(); } finally { progress.Visibility = Visibility.Collapsed; if (_directionsOverlay.Graphics.Count() > 0) { panelResults.Visibility = Visibility.Visible; } } }
private async Task FindRoute() { // Manage Buttons AcceptNavigation.Visibility = Visibility.Visible; AcceptNavigation.IsEnabled = true; RefuseNavigation.Visibility = Visibility.Visible; RefuseNavigation.IsEnabled = true; CancelNavigation.Visibility = Visibility.Hidden; CancelNavigation.IsEnabled = false; TripRequestTB.Visibility = Visibility.Visible; try { _solveRouteTask = await RouteTask.CreateAsync(_transportationNetwork); _routeParameters = await _solveRouteTask.CreateDefaultParametersAsync(); var truckMode = from travelmode in _solveRouteTask.RouteTaskInfo.TravelModes where travelmode.Type == "TRUCK" select travelmode; _routeParameters.TravelMode = truckMode.Last(); _routeParameters.ReturnDirections = true; _routeParameters.ReturnStops = true; _routeParameters.ReturnRoutes = true; _routeParameters.OutputSpatialReference = SpatialReferences.Wgs84; List <Stop> stops = new List <Stop> { new Stop(_mapView.LocationDisplay.MapLocation), new Stop(_startPoint) }; _routeParameters.SetStops(stops); _routeResult = await _solveRouteTask.SolveRouteAsync(_routeParameters); _route = _routeResult.Routes.FirstOrDefault(); // Display UI info TimeTB = _route.TotalTime.ToString(@"hh\:mm\:ss"); DistanceTB = Math.Round(_route.TotalLength / 1000, 2).ToString(); // Diplay the route Polyline routePolyline = _route.RouteGeometry; SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.BlueViolet, 4.0f); Graphic routeGraphic = new Graphic(routePolyline, routeSymbol); _graphicsOverlay.Graphics.Add(routeGraphic); } catch (Exception ex) { MessageBox.Show(ex.Message); } setExtent(_mapView.LocationDisplay.MapLocation, _startPoint); //StartNavigation(); }
private async Task CalculateRouteAsync() { try { progress.Visibility = Visibility.Visible; RouteParameters routeParams = await _routeTask.GetDefaultParametersAsync(); routeParams.OutSpatialReference = MyMapView.SpatialReference; routeParams.ReturnDirections = false; routeParams.SetStops(_stopsGraphicsOverlay.Graphics); RouteResult routeResult = await _routeTask.SolveAsync(routeParams); if (routeResult.Routes.Count > 0) { _routeGraphicsOverlay.Graphics.Clear(); var route = routeResult.Routes.First().RouteFeature; _routeGraphicsOverlay.Graphics.Add(new Graphic(route.Geometry)); var meters = GeometryEngine.GeodesicLength(route.Geometry, GeodeticCurveType.Geodesic); txtDistance.Text = string.Format("{0:0.00} miles", LinearUnits.Miles.ConvertFromMeters(meters)); panelRouteInfo.Visibility = Visibility.Visible; } } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { MessageBox.Show(innermostExceptions[0].Message); } else { MessageBox.Show(ex.Message); } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.Message); } finally { progress.Visibility = Visibility.Collapsed; } }
private async void UpdateRoute(TravelMode selectedTravelMode) { try { // Create a list of stops. List <Stop> stops = new List <Stop>(); // Add a stop to the list for each graphic in the stops overlay. foreach (Graphic stopGraphic in _stopsOverlay.Graphics) { Stop stop = new Stop((MapPoint)stopGraphic.Geometry); stops.Add(stop); } if (stops.Count < 2) { // Don't route, there's no where to go (and the route task would throw an exception). return; } // Configure the route parameters with the list of stops. _offlineRouteParameters.SetStops(stops); // Configure the travel mode. _offlineRouteParameters.TravelMode = selectedTravelMode; // Solve the route. RouteResult offlineRouteResult = await _offlineRouteTask.SolveRouteAsync(_offlineRouteParameters); // Clear the old route result. _routeOverlay.Graphics.Clear(); // Get the geometry from the route result. Polyline routeGeometry = offlineRouteResult.Routes.First().RouteGeometry; // Note: symbology left out here because the symbology was set once on the graphics overlay. Graphic routeGraphic = new Graphic(routeGeometry); // Display the route. _routeOverlay.Graphics.Add(routeGraphic); } catch (Exception e) { Debug.WriteLine(e); ShowMessage("Couldn't update route", "There was an error updating the route. See debug output for details."); _selectedStopGraphic = null; } }
private async void SolveRouteButton_Click(object sender, EventArgs e) { try { // Create a new route task using the San Diego route service URI. RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri); // Get the default parameters from the route task (defined with the service). RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync(); // Make some changes to the default parameters. routeParams.ReturnStops = true; routeParams.ReturnDirections = true; // Set the list of route stops that were defined at startup. routeParams.SetStops(_routeStops); // Solve for the best route between the stops and store the result. RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams); // Get the first (should be only) route from the result. Route firstRoute = solveRouteResult.Routes.First(); // Get the route geometry (polyline). Polyline routePolyline = firstRoute.RouteGeometry; // Create a thick purple line symbol for the route. SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0); // Create a new graphic for the route geometry and add it to the graphics overlay. Graphic routeGraphic = new Graphic(routePolyline, routeSymbol) { ZIndex = 0 }; _routeGraphicsOverlay.Graphics.Add(routeGraphic); // Get a list of directions for the route and display it in the list box. _directionsList = firstRoute.DirectionManeuvers; // Enable the directions button. _directionsButton.Enabled = true; } catch (Exception ex) { new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
public async Task SolveRoute() { if (_stopGraphicsOverlay.Graphics.Count < 2) { return; } try { progress.Visibility = Visibility.Visible; _routeParams.SetStops(_stopGraphicsOverlay.Graphics); _routeParams.SetPointBarriers(_barrierGraphicsOverlay.Graphics); _routeParams.OutSpatialReference = MyMapView.SpatialReference; RouteResult routeResult = await _routeTask.SolveAsync(_routeParams); if (routeResult.Routes.Count > 0) { _routeGraphicsOverlay.Graphics.Clear(); var route = routeResult.Routes.First().RouteFeature; _routeGraphicsOverlay.Graphics.Add(new Graphic(route.Geometry)); } } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { MessageBox.Show(innermostExceptions[0].Message); } else { MessageBox.Show(ex.Message); } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.Message); } finally { progress.Visibility = Visibility.Collapsed; } }
private async void SolveRouteClick(object sender, EventArgs e) { try { // Create a new route task using the San Diego route service URI RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri); // Get the default parameters from the route task (defined with the service) RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync(); // Make some changes to the default parameters routeParams.ReturnStops = true; routeParams.ReturnDirections = true; // Set the list of route stops that were defined at startup routeParams.SetStops(_routeStops); // Solve for the best route between the stops and store the result RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams); // Get the first (should be only) route from the result Route firstRoute = solveRouteResult.Routes.First(); // Get the route geometry (polyline) Polyline routePolyline = firstRoute.RouteGeometry; // Create a thick purple line symbol for the route SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0); // Create a new graphic for the route geometry and add it to the graphics overlay Graphic routeGraphic = new Graphic(routePolyline, routeSymbol) { ZIndex = 0 }; _routeGraphicsOverlay.Graphics.Add(routeGraphic); // Get a list of directions for the route and display it in the list box CreateDirectionsDialog(firstRoute.DirectionManeuvers.Select(d => d.DirectionText)); _showHideDirectionsButton.Enabled = true; } catch (Exception ex) { new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show(); } }
private async void SolveRouteClick(object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { // Create a new route task using the San Diego route service URI RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri); // Get the default parameters from the route task (defined with the service) RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync(); // Make some changes to the default parameters routeParams.ReturnStops = true; routeParams.ReturnDirections = true; // Set the list of route stops that were defined at startup routeParams.SetStops(_routeStops); // Solve for the best route between the stops and store the result RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams); // Get the first (should be only) route from the result Route firstRoute = solveRouteResult.Routes.First(); // Get the route geometry (polyline) Polyline routePolyline = firstRoute.RouteGeometry; // Create a thick purple line symbol for the route SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0); // Create a new graphic for the route geometry and add it to the graphics overlay Graphic routeGraphic = new Graphic(routePolyline, routeSymbol) { ZIndex = 0 }; _routeGraphicsOverlay.Graphics.Add(routeGraphic); // Get a list of directions for the route and display it in the list box IReadOnlyList <DirectionManeuver> directionsList = firstRoute.DirectionManeuvers; DirectionsListBox.ItemsSource = directionsList; } catch (Exception ex) { await new MessageDialog(ex.ToString(), "Error").ShowAsync(); } }
private async void SolveRoute() { try { // Create route parameters and configure them to enable navigation. _routeParameters = await _routeTask.CreateDefaultParametersAsync(); _routeParameters.ReturnStops = true; _routeParameters.ReturnDirections = true; _routeParameters.ReturnRoutes = true; // Prefer walking directions if available. TravelMode walkingMode = _routeTask.RouteTaskInfo.TravelModes.FirstOrDefault(mode => mode.Name.Contains("Walk")) ?? _routeTask.RouteTaskInfo.TravelModes.First(); _routeParameters.TravelMode = walkingMode; // Set the stops for the route. Stop stop1 = new Stop(_startPoint); Stop stop2 = new Stop(_endPoint); _routeParameters.SetStops(new[] { stop1, stop2 }); // Calculate the route. _routeResult = await _routeTask.SolveRouteAsync(_routeParameters); // Get the first result. _route = _routeResult.Routes.First(); // Create and show a graphic for the route. Graphic routeGraphic = new Graphic(_route.RouteGeometry); _routeOverlay.Graphics.Add(routeGraphic); // Allow the user to start navigating. EnableNavigation(); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", "Failed to calculate route.", "OK"); Debug.WriteLine(ex); } }
private async void SolveRoute() { try { // Create route parameters and configure them to enable navigation. _routeParameters = await _routeTask.CreateDefaultParametersAsync(); _routeParameters.ReturnStops = true; _routeParameters.ReturnDirections = true; _routeParameters.ReturnRoutes = true; // Prefer walking directions if available. TravelMode walkingMode = _routeTask.RouteTaskInfo.TravelModes.FirstOrDefault(mode => mode.Name.Contains("Walk")) ?? _routeTask.RouteTaskInfo.TravelModes.First(); _routeParameters.TravelMode = walkingMode; // Set the stops for the route. Stop stop1 = new Stop(_startPoint); Stop stop2 = new Stop(_endPoint); _routeParameters.SetStops(new[] { stop1, stop2 }); // Calculate the route. _routeResult = await _routeTask.SolveRouteAsync(_routeParameters); // Get the first result. _route = _routeResult.Routes.First(); // Create and show a graphic for the route. Graphic routeGraphic = new Graphic(_route.RouteGeometry); _routeOverlay.Graphics.Add(routeGraphic); // Allow the user to start navigating. EnableNavigation(); } catch (Exception ex) { new Android.Support.V7.App.AlertDialog.Builder(this).SetMessage("Failed to calculate route.") .SetTitle("Error").Show(); System.Diagnostics.Debug.WriteLine(ex); } }
private async void OnSolveRouteClicked(object sender, RoutedEventArgs e) { var stopsLayer = mapView1.Map.Layers["MyStopsGraphicsLayer"] as GraphicsLayer; var barriersLayer = mapView1.Map.Layers["MyBarriersGraphicsLayer"] as GraphicsLayer; if (stopsLayer.Graphics.Count > 1) { try { OnlineRouteTask routeTask = new OnlineRouteTask (new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/Route")); RouteParameters routeParams = await routeTask.GetDefaultParametersAsync(); routeParams.SetStops(stopsLayer.Graphics); routeParams.UseTimeWindows = false; routeParams.OutSpatialReference = mapView1.SpatialReference; routeParams.SetPointBarriers(barriersLayer.Graphics); routeParams.OutputGeometryPrecision = 1; routeParams.DirectionsLengthUnit = LinearUnits.Miles; routeParams.DirectionsLanguage = new CultureInfo("en-Us"); // CultureInfo.CurrentCulture; var result = await routeTask.SolveAsync(routeParams); if (result != null) { GraphicsLayer routeLayer = mapView1.Map.Layers["MyRouteGraphicsLayer"] as GraphicsLayer; routeLayer.Graphics.Clear(); foreach (var route in result.Routes) { routeLayer.Graphics.Add(route.RouteFeature as Graphic); } } } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } } }
/// <summary> /// Returns a route between the specified stops. /// </summary> /// <param name="stops">The stops on the route.</param> /// <returns></returns> public async Task <SolveRouteResult> SolveRouteAsync(MapPoint from, MapPoint to) { RouteTask routeTask = null; RouteParameters routeParameters = null; RouteResult routeResult = null; try { // Ensure the sample data is ready to go await DataManager.EnsureDataPresent(); // Create a new route using the offline database routeTask = await RouteTask.CreateAsync(DataManager.GetDataFolder(_database), _networkName); // Configure the route and set the stops routeParameters = await routeTask.CreateDefaultParametersAsync(); routeParameters.SetStops(new[] { new Stop(from), new Stop(to) }); routeParameters.ReturnStops = true; routeParameters.ReturnDirections = true; routeParameters.RouteShapeType = RouteShapeType.TrueShapeWithMeasures; routeParameters.OutputSpatialReference = SpatialReferences.Wgs84; routeParameters.DirectionsDistanceUnits = UnitSystem.Metric; routeParameters.StartTime = DateTime.UtcNow; // Solve the route routeResult = await routeTask.SolveRouteAsync(routeParameters); } catch (Exception ex) { if (!(ex is ArcGISWebException web && web.Details.FirstOrDefault()?.Contains("Unlocated") == true)) { // There was some other error. throw; } } return(new SolveRouteResult { Route = routeResult, Task = routeTask, Parameters = routeParameters }); }
private async void SolveRoute() { try { // Create the route parameters and configure to enable navigation. _routeParameters = await _routeTask.CreateDefaultParametersAsync(); _routeParameters.ReturnStops = true; _routeParameters.ReturnDirections = true; _routeParameters.ReturnRoutes = true; // Prefer walking directions if available. TravelMode walkingMode = _routeTask.RouteTaskInfo.TravelModes.FirstOrDefault(mode => mode.Name.Contains("Walk")) ?? _routeTask.RouteTaskInfo.TravelModes.First(); _routeParameters.TravelMode = walkingMode; // Set the stops. Stop stop1 = new Stop(_startPoint); Stop stop2 = new Stop(_endPoint); _routeParameters.SetStops(new[] { stop1, stop2 }); // Solve the rotue. _routeResult = await _routeTask.SolveRouteAsync(_routeParameters); _route = _routeResult.Routes.First(); // Show the route on the map. Graphic routeGraphic = new Graphic(_route.RouteGeometry); _routeOverlay.Graphics.Add(routeGraphic); // Update the UI and allow the user to start navigating. _navigateButton.Enabled = true; _helpLabel.Text = "You're ready to start navigating!"; } catch (Exception ex) { _helpLabel.Text = "Routing failed, restart sample to retry."; new UIAlertView("Error", "Failed to calculate route", (IUIAlertViewDelegate)null, "OK", null).Show(); System.Diagnostics.Debug.WriteLine(ex); } }
/// <summary> /// Returns a route between the specified stops. /// </summary> /// <param name="stops">The stops on the route.</param> /// <returns></returns> public async Task <SolveRouteResult> SolveRouteAsync(MapPoint from, MapPoint to) { RouteTask routeTask = null; RouteParameters routeParameters = null; RouteResult routeResult = null; try { // Create a new route using the onling routing service routeTask = await RouteTask.CreateAsync(s_routeService, _credential); // Configure the route and set the stops routeParameters = await routeTask.CreateDefaultParametersAsync(); routeParameters.SetStops(new[] { new Stop(from), new Stop(to) }); routeParameters.ReturnStops = true; routeParameters.ReturnDirections = true; routeParameters.RouteShapeType = RouteShapeType.TrueShapeWithMeasures; routeParameters.OutputSpatialReference = SpatialReferences.Wgs84; routeParameters.DirectionsDistanceUnits = UnitSystem.Metric; routeParameters.StartTime = DateTime.UtcNow; // Solve the route routeResult = await routeTask.SolveRouteAsync(routeParameters); } catch (ArcGISWebException ex) { // Any error other than failure to locate is rethrown if (ex.Details.FirstOrDefault()?.Contains("Unlocated") != true) { throw ex; } } return(new SolveRouteResult { Route = routeResult, Task = routeTask, Parameters = routeParameters }); }
/// <summary> /// Solves routing problem for given input parameters /// </summary> /// <returns></returns> public async Task <RouteUtilityResult> Solve() { routeTask = (routeTask) ?? await RouteTask.CreateAsync(RouteServiceUri); var routInfo = routeTask.RouteTaskInfo; // get the default route parameters routeParams = (routeParams) ?? await routeTask.CreateDefaultParametersAsync(); // explicitly set values for some params // routeParams.ReturnDirections = true; // routeParams.ReturnRoutes = true; routeParams.OutputSpatialReference = SpatialRef; routeParams.SetStops(stopPoints); routeParams.SetPointBarriers(pointBarriers); var routeResult = await routeTask.SolveRouteAsync(routeParams); return(new RouteUtilityResult { RouteName = routeResult.Routes[0].RouteName, TotalTime = routeResult.Routes[0].TotalTime }); }
private async void SolveRouteClick(object sender, EventArgs e) { try { // Register a portal that uses OAuth authentication with the AuthenticationManager Esri.ArcGISRuntime.Security.ServerInfo serverInfo = new ServerInfo(new Uri("https://www.arcgis.com/sharing/rest")); serverInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials; serverInfo.OAuthClientInfo = new OAuthClientInfo { ClientId = ClientId, ClientSecret = ClientSecret, RedirectUri = new Uri(RedirectURI) }; AuthenticationManager.Current.RegisterServer(serverInfo); // Create a new route task using the San Diego route service URI RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri); // Get the default parameters from the route task (defined with the service) RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync(); routeParams.PreserveLastStop = false; routeParams.DirectionsStyle = DirectionsStyle.Navigation; //TravelMode travel = new TravelMode(); var travelModes = solveRouteTask.RouteTaskInfo.TravelModes.ToList(); // Make some changes to the default parameters routeParams.ReturnStops = true; routeParams.ReturnDirections = true; routeParams.FindBestSequence = true; routeParams.DirectionsDistanceUnits = Esri.ArcGISRuntime.UnitSystem.Imperial; // Set the list of route stops that were defined at startup routeParams.SetStops(_routeStops); // Solve for the best route between the stops and store the result RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams); // Get the first (should be only) route from the result var min = solveRouteResult.Routes.Min(x => x.TotalLength); Route firstRoute = solveRouteResult.Routes.FirstOrDefault(x => x.TotalLength == min); // Get the route geometry (polyline) Polyline routePolyline = firstRoute.RouteGeometry; // Create a thick purple line symbol for the route SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0); // Create a new graphic for the route geometry and add it to the graphics overlay Graphic routeGraphic = new Graphic(routePolyline, routeSymbol) { ZIndex = 0 }; _routeGraphicsOverlay.Graphics.Add(routeGraphic); // Get a list of directions for the route and display it in the list box DirectionsListBox.ItemsSource = firstRoute.DirectionManeuvers.Select(direction => direction.DirectionText); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK"); } }
private async void Initialize() { try { // Create the map view. _myMapView.Map = new Map(BasemapStyle.ArcGISNavigation); // Create the route task, using the routing service. _routeTask = await RouteTask.CreateAsync(_networkGeodatabasePath, "Streets_ND"); // Get the default route parameters. _routeParams = await _routeTask.CreateDefaultParametersAsync(); // Explicitly set values for parameters. _routeParams.ReturnDirections = true; _routeParams.ReturnStops = true; _routeParams.ReturnRoutes = true; _routeParams.OutputSpatialReference = SpatialReferences.Wgs84; // Create stops for each location. Stop stop1 = new Stop(_conventionCenter) { Name = "San Diego Convention Center" }; Stop stop2 = new Stop(_aerospaceMuseum) { Name = "RH Fleet Aerospace Museum" }; // Assign the stops to the route parameters. List <Stop> stopPoints = new List <Stop> { stop1, stop2 }; _routeParams.SetStops(stopPoints); // Get the route results. _routeResult = await _routeTask.SolveRouteAsync(_routeParams); _route = _routeResult.Routes[0]; // Add a graphics overlay for the route graphics. _myMapView.GraphicsOverlays.Add(new GraphicsOverlay()); // Add graphics for the stops. SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20); _myMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol)); _myMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol)); // Create a graphic (with a dashed line symbol) to represent the route. _routeAheadGraphic = new Graphic(_route.RouteGeometry) { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5) }; // Create a graphic (solid) to represent the route that's been traveled (initially empty). _routeTraveledGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3) }; // Add the route graphics to the map view. _myMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic); _myMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic); // Set the map viewpoint to show the entire route. await _myMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100); // Enable the navigation button. _navigateButton.Enabled = true; } catch (Exception e) { new UIAlertView("Error", e.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async Task ProcessRouteRequest(MapPoint tappedPoint) { // Clear any existing overlays. _routeOverlay.Graphics.Clear(); _myMapView.DismissCallout(); // Return if there is no network available for routing. if (_networkDataset == null) { await ShowGeocodeResult(tappedPoint); return; } // Set the start point if it hasn't been set. if (_startPoint == null) { _startPoint = tappedPoint; await ShowGeocodeResult(tappedPoint); // Show the start point. _waypointOverlay.Graphics.Add(await GraphicForPoint(_startPoint)); return; } if (_endPoint == null) { await ShowGeocodeResult(tappedPoint); // Show the end point. _endPoint = tappedPoint; _waypointOverlay.Graphics.Add(await GraphicForPoint(_endPoint)); // Create the route task from the local network dataset. RouteTask routingTask = await RouteTask.CreateAsync(_networkDataset); // Configure route parameters for the route between the two tapped points. RouteParameters routingParameters = await routingTask.CreateDefaultParametersAsync(); List <Stop> stops = new List <Stop> { new Stop(_startPoint), new Stop(_endPoint) }; routingParameters.SetStops(stops); // Get the first route result. RouteResult result = await routingTask.SolveRouteAsync(routingParameters); Route firstRoute = result.Routes.First(); // Show the route on the map. Note that symbology for the graphics overlay is defined in Initialize(). Polyline routeLine = firstRoute.RouteGeometry; _routeOverlay.Graphics.Add(new Graphic(routeLine)); return; } // Reset graphics and route. _routeOverlay.Graphics.Clear(); _waypointOverlay.Graphics.Clear(); _startPoint = null; _endPoint = null; }
private async Task <int> RunRouting() { try { _networkingToolView.ViewModel.PanelResultsVisibility = Visibility.Collapsed; _networkingToolView.ViewModel.ProgressVisibility = Visibility.Visible; RouteParameters routeParams = await _routeTask.GetDefaultParametersAsync(); routeParams.OutSpatialReference = _mapView.SpatialReference; routeParams.ReturnDirections = true; routeParams.DirectionsLengthUnit = LinearUnits.Miles; routeParams.DirectionsLanguage = new CultureInfo("en-Us"); // CultureInfo.CurrentCulture; routeParams.SetStops(_stopsOverlay.Graphics); var routeResult = await _routeTask.SolveAsync(routeParams); if (routeResult == null || routeResult.Routes == null || !routeResult.Routes.Any()) { throw new Exception("No route could be calculated"); } var route = routeResult.Routes.First(); _routesOverlay.Graphics.Add(new Graphic(route.RouteFeature.Geometry)); _directionsOverlay.GraphicsSource = route.RouteDirections.Select(rd => GraphicFromRouteDirection(rd)); _networkingToolView.ViewModel.Graphics = _directionsOverlay.Graphics; var totalTime = route.RouteDirections.Select(rd => rd.Time).Aggregate(TimeSpan.Zero, (p, v) => p.Add(v)); var totalLength = route.RouteDirections.Select(rd => rd.GetLength(LinearUnits.Miles)).Sum(); _networkingToolView.ViewModel.RouteTotals = string.Format("Time: {0:h':'mm':'ss} / Length: {1:0.00} mi", totalTime, totalLength); if (!route.RouteFeature.Geometry.IsEmpty) { await _mapView.SetViewAsync(route.RouteFeature.Geometry.Extent.Expand(1.25)); } } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { MessageBox.Show(innermostExceptions[0].Message, "Sample Error"); } else { MessageBox.Show(ex.Message, "Sample Error"); } Reset(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); Reset(); } finally { _networkingToolView.ViewModel.ProgressVisibility = Visibility.Collapsed; if (_directionsOverlay.Graphics.Any()) { _networkingToolView.ViewModel.PanelResultsVisibility = Visibility.Visible; } } return(0); }
public async void AddStops() { // If the user clicked the SolveRouteButton more than once, clear out any existing stops and routes graphics. routeGraphicsLayer.Graphics.Clear(); stopsGraphicsLayer.Graphics.Clear(); try { // Mouse click 1: setting the start point for the route // --------------------------------------------------- // Get the Editor from the MapView. Editor startPointEditor = this.mapView.Editor; // Get the MapPoint from where the user clicks in the Map Control. This will be the starting point for the route. MapPoint startLocationMapPoint = await startPointEditor.RequestPointAsync(); // Create a new Graphic and set it's geometry to the user clicked MapPoint Graphic startPointGraphic = new Graphic(); startPointGraphic.Geometry = startLocationMapPoint; // Add the start point graphic to the stops GraphicsLayer. stopsGraphicsLayer.Graphics.Add(startPointGraphic); // Mouse click 2: setting the end point for the route // --------------------------------------------------- // Get the Editor from the MapView. Editor endPointEditor = this.mapView.Editor; // Get the MapPoint from where the user clicks in the Map Control. This will be the ending point for the route. MapPoint endLocationMapPoint = await startPointEditor.RequestPointAsync(); // Create a new Graphic and set it's geometry to the user clicked MapPoint Graphic endPointGraphic = new Graphic(); endPointGraphic.Geometry = endLocationMapPoint; // Add the start point graphic to the stops GraphicsLayer. stopsGraphicsLayer.Graphics.Add(endPointGraphic); // Set the arguments for the RouteTask: // Get the RouteParameters from the RouteTask. RouteParameters routeParameters = await routeTask.GetDefaultParametersAsync(); // Define the settings for the RouteParameters. This includes setting the SpatialReference, // ReturnDirections, DirectionsLengthUnit and Stops. routeParameters.OutSpatialReference = this.mapView.SpatialReference; routeParameters.ReturnDirections = false; routeParameters.DirectionsLengthUnit = LinearUnits.Kilometers; // Define a List of Graphics based upon the user start and end clicks in the Map Control that will serve as input // parameters for the RouteTask operation. List <Graphic> graphicsStops = new List <Graphic>(); graphicsStops.Add(new Graphic(startLocationMapPoint)); graphicsStops.Add(new Graphic(endLocationMapPoint)); // Set the stops for the Route. routeParameters.SetStops(graphicsStops); // Call the asynchronous function to solve the RouteTask. RouteResult routeResult = await routeTask.SolveAsync(routeParameters); // Ensure we got at least one route back. if (routeResult.Routes.Count > 0) { // Get the first Route from the List of Routes Route firstRoute = routeResult.Routes[0]; // Get the Geometry from the Graphic in the first Route. Geometry routeGeometry = firstRoute.RouteFeature.Geometry; // Create a new Graphic based upon the Graphic. Graphic routeGraphic = new Graphic(routeGeometry); // Add the Graphic (a polyline) to the route GraphicsLayer. this.routeGraphicsLayer.Graphics.Add(routeGraphic); } } catch (System.AggregateException ex) { // There was a problem, display the results to the user. var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { Messenger.Default.Send <NotificationMessage>(new NotificationMessage((innermostExceptions[0].Message.ToString()))); } else { Messenger.Default.Send <NotificationMessage>(new NotificationMessage(ex.Message.ToString())); } } catch (System.Exception ex) { // There was a problem, display the results to the user. Messenger.Default.Send <NotificationMessage>(new NotificationMessage("Error: " + ex.Message.ToString())); } finally { } }
// Calculate the route private async void MyMapView_MapViewDoubleTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { if (!_isMapReady || _stopsOverlay.Graphics.Count() < 2) { return; } try { e.Handled = true; panelResults.Visibility = Visibility.Collapsed; progress.Visibility = Visibility.Visible; if (_routeTask == null) { _routeTask = await Task.Run <LocalRouteTask>(() => new LocalRouteTask(_localRoutingDatabase, _networkName)); } RouteParameters routeParams = await _routeTask.GetDefaultParametersAsync(); routeParams.OutSpatialReference = MyMapView.SpatialReference; routeParams.ReturnDirections = true; routeParams.DirectionsLengthUnit = LinearUnits.Miles; routeParams.DirectionsLanguage = new CultureInfo("en-US"); routeParams.SetStops(_stopsOverlay.Graphics); var routeResult = await _routeTask.SolveAsync(routeParams); if (routeResult == null || routeResult.Routes == null || routeResult.Routes.Count() == 0) { throw new ApplicationException("No route could be calculated"); } var route = routeResult.Routes.First(); _routesOverlay.Graphics.Add(new Graphic(route.RouteFeature.Geometry)); _directionsOverlay.GraphicsSource = route.RouteDirections.Select(rd => GraphicFromRouteDirection(rd)); var totalTime = route.RouteDirections.Select(rd => rd.Time).Aggregate(TimeSpan.Zero, (p, v) => p.Add(v)); var totalLength = route.RouteDirections.Select(rd => rd.GetLength(LinearUnits.Miles)).Sum(); txtRouteTotals.Text = string.Format("Time: {0:h':'mm':'ss} / Length: {1:0.00} mi", totalTime, totalLength); await MyMapView.SetViewAsync(route.RouteFeature.Geometry.Extent.Expand(1.2)); } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { MessageBox.Show(innermostExceptions[0].Message, "Sample Error"); } else { MessageBox.Show(ex.Message, "Sample Error"); } } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } finally { progress.Visibility = Visibility.Collapsed; if (_directionsOverlay.Graphics.Count() > 0) { panelResults.Visibility = Visibility.Visible; } } }
private async void OnView_Tapped(object sender, Esri.ArcGISRuntime.UI.GeoViewInputEventArgs e) { MapPoint geoPoint = getGeoPoint(e); geoPoint = (MapPoint)GeometryEngine.Project(geoPoint, SpatialReference.Create(3857)); if (QueryandBufferButton.Content == FindResource("LocationSelected")) { Polygon buffer = (Polygon)GeometryEngine.Buffer(geoPoint, 1000.0); GraphicCollection graphics = (threeD ? bufferAndQuerySceneGraphics : bufferAndQueryMapGraphics).Graphics; graphics.Clear(); graphics.Add(new Graphic(buffer, BUFFER_SYMBOL)); graphics.Add(new Graphic(geoPoint, CLICK_SYMBOL)); Esri.ArcGISRuntime.Data.QueryParameters query = new Esri.ArcGISRuntime.Data.QueryParameters(); query.Geometry = buffer; LayerCollection operationalLayers; if (threeD) { operationalLayers = sceneView.Scene.OperationalLayers; } else { operationalLayers = mapView.Map.OperationalLayers; } foreach (Layer layer in operationalLayers) { await((FeatureLayer)layer).SelectFeaturesAsync(query, SelectionMode.New); } } else if (RoutingButton.Content == FindResource("RoutingSelected")) { GraphicCollection graphics = (threeD ? sceneRouteGraphics : mapRouteGraphics).Graphics; if (originPoint == null) { originPoint = geoPoint; graphics.Clear(); graphics.Add(new Graphic(originPoint, ROUTE_ORIGIN_SYMBOL)); } else { graphics.Add(new Graphic(geoPoint, ROUTE_DESTINATION_SYMBOL)); if (routeParameters != null) { routeParameters.ReturnDirections = false; routeParameters.ReturnRoutes = true; routeParameters.ReturnStops = false; } else { RoutingButton_Click(null, null); } var stop1 = new Stop(originPoint); var stop2 = new Stop(geoPoint); var stopPoints = new List <Stop> { stop1, stop2 }; routeParameters.SetStops(stopPoints); var routeResult = await routeTask.SolveRouteAsync(routeParameters); // get the route from the results var route = routeResult.Routes[0]; // create a graphic (with a dashed line symbol) to represent the route var routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Colors.Yellow, 5); var routeGraphic = new Graphic(route.RouteGeometry, routeSymbol); graphics.Add(routeGraphic); originPoint = null; } } }
private async void Initialize() { try { // Add event handler for when this sample is unloaded. Unloaded += SampleUnloaded; // Create the map view. MyMapView.Map = new Map(Basemap.CreateNavigationVector()); // Create the route task, using the online routing service. RouteTask routeTask = await RouteTask.CreateAsync(_routingUri); // Get the default route parameters. RouteParameters routeParams = await routeTask.CreateDefaultParametersAsync(); // Explicitly set values for parameters. routeParams.ReturnDirections = true; routeParams.ReturnStops = true; routeParams.ReturnRoutes = true; routeParams.OutputSpatialReference = SpatialReferences.Wgs84; // Create stops for each location. Stop stop1 = new Stop(_conventionCenter) { Name = "San Diego Convention Center" }; Stop stop2 = new Stop(_memorial) { Name = "USS San Diego Memorial" }; Stop stop3 = new Stop(_aerospaceMuseum) { Name = "RH Fleet Aerospace Museum" }; // Assign the stops to the route parameters. List <Stop> stopPoints = new List <Stop> { stop1, stop2, stop3 }; routeParams.SetStops(stopPoints); // Get the route results. _routeResult = await routeTask.SolveRouteAsync(routeParams); _route = _routeResult.Routes[0]; // Add a graphics overlay for the route graphics. MyMapView.GraphicsOverlays.Add(new GraphicsOverlay()); // Add graphics for the stops. SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20); MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol)); MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_memorial, stopSymbol)); MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol)); // Create a graphic (with a dashed line symbol) to represent the route. _routeAheadGraphic = new Graphic(_route.RouteGeometry) { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5) }; // Create a graphic (solid) to represent the route that's been traveled (initially empty). _routeTraveledGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3) }; // Add the route graphics to the map view. MyMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic); MyMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic); // Set the map viewpoint to show the entire route. await MyMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100); // Enable the navigation button. StartNavigationButton.IsEnabled = true; } catch (Exception e) { MessageBox.Show(e.Message, "Error"); } }
async void Button_Clicked(System.Object sender, System.EventArgs e) { // Assign the map to the MapView. MainMapView.Map = new Map(BasemapStyle.ArcGISNavigation); await MainMapView.Map.LoadAsync(); //MapPoint mapCenterPoint = new MapPoint(, SpatialReferences.WebMercator); await MainMapView.SetViewpointAsync(new Viewpoint(52.0135053, 4.3367553, 72223.819286)); // Create the route task, using the online routing service. RouteTask routeTask = await RouteTask.CreateAsync(_routingUri); // Get the default route parameters. RouteParameters routeParams = await routeTask.CreateDefaultParametersAsync(); // Explicitly set values for parameters. routeParams.ReturnDirections = true; routeParams.ReturnStops = true; routeParams.ReturnRoutes = true; routeParams.OutputSpatialReference = SpatialReferences.Wgs84; // Create stops for each location. Stop stop1 = new Stop(_conventionCenter) { Name = "Delft Netherlands" }; Stop stop2 = new Stop(_memorial) { Name = "Rotterdam Netherlands" }; //Stop stop3 = new Stop(_aerospaceMuseum) { Name = "Amsterdam Netherlands" }; // Assign the stops to the route parameters. List <Stop> stopPoints = new List <Stop> { stop1, stop2 }; routeParams.SetStops(stopPoints); // Get the route results. _routeResult = await routeTask.SolveRouteAsync(routeParams); _route = _routeResult.Routes[0]; // Add a graphics overlay for the route graphics. MainMapView.GraphicsOverlays.Add(new GraphicsOverlay()); // Add graphics for the stops. SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20); MainMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol)); MainMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_memorial, stopSymbol)); //MainMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol)); // Create a graphic (with a dashed line symbol) to represent the route. _routeAheadGraphic = new Graphic(_route.RouteGeometry) { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5) }; // Create a graphic (solid) to represent the route that's been traveled (initially empty). _routeTraveledGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3) }; // Add the route graphics to the map view. MainMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic); MainMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic); // Set the map viewpoint to show the entire route. await MainMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100); // Enable the navigation button. StartNavigationButton.IsEnabled = true; }
private void ConfigureThenRoute() { // Guard against error conditions. if (_routeParameters == null) { ShowMessage("Not ready yet", "Sample isn't ready yet; define route parameters first."); return; } if (_stopsOverlay.Graphics.Count < 2) { ShowMessage("Not enough stops", "Add at least two stops before solving a route."); return; } // Clear any existing route from the map. _routeOverlay.Graphics.Clear(); // Configure the route result to include directions and stops. _routeParameters.ReturnStops = true; _routeParameters.ReturnDirections = true; // Create a list to hold stops that should be on the route. List <Stop> routeStops = new List <Stop>(); // Create stops from the graphics. foreach (Graphic stopGraphic in _stopsOverlay.Graphics) { // Note: this assumes that only points were added to the stops overlay. MapPoint stopPoint = (MapPoint)stopGraphic.Geometry; // Create the stop from the graphic's geometry. Stop routeStop = new Stop(stopPoint); // Set the name of the stop to its position in the list. routeStop.Name = $"{_stopsOverlay.Graphics.IndexOf(stopGraphic) + 1}"; // Add the stop to the list of stops. routeStops.Add(routeStop); } // Configure the route parameters with the stops. _routeParameters.ClearStops(); _routeParameters.SetStops(routeStops); // Create a list to hold barriers that should be routed around. List <PolygonBarrier> routeBarriers = new List <PolygonBarrier>(); // Create barriers from the graphics. foreach (Graphic barrierGraphic in _barriersOverlay.Graphics) { // Get the polygon from the graphic. Polygon barrierPolygon = (Polygon)barrierGraphic.Geometry; // Create a barrier from the polygon. PolygonBarrier routeBarrier = new PolygonBarrier(barrierPolygon); // Add the barrier to the list of barriers. routeBarriers.Add(routeBarrier); } // Configure the route parameters with the barriers. _routeParameters.ClearPolygonBarriers(); _routeParameters.SetPolygonBarriers(routeBarriers); // If the user allows stops to be re-ordered, the service will find the optimal order. _routeParameters.FindBestSequence = AllowReorderStopsCheckbox.IsToggled; // If the user has allowed re-ordering, but has a definite start point, tell the service to preserve the first stop. _routeParameters.PreserveFirstStop = PreserveFirstStopCheckbox.IsToggled; // If the user has allowed re-ordering, but has a definite end point, tell the service to preserve the last stop. _routeParameters.PreserveLastStop = PreserveLastStopCheckbox.IsToggled; // Calculate and show the route. CalculateAndShowRoute(); }
private async void GetRoute() { try { // what do i need to do to get credentials token ? Automatically done when a request to a secure service by Chanllengehandler. _routeTask = await RouteTask.CreateAsync(_carRoutingUri); // Get the default route parameters. _routeParams = await _routeTask.CreateDefaultParametersAsync(); // Explicitly set values for parameters. _routeParams.ReturnDirections = true; _routeParams.ReturnStops = true; _routeParams.ReturnRoutes = true; _routeParams.OutputSpatialReference = SpatialReferences.Wgs84; // Create stops for each location. Stop stop1 = new Stop(_conventionCenter) { Name = "Canal St." }; Stop stop2 = new Stop(_aerospaceMuseum) { Name = "Oxford Ln, The Villages" }; // Assign the stops to the route parameters. List <Stop> stopPoints = new List <Stop> { stop1, stop2 }; _routeParams.SetStops(stopPoints); // Get the route results. _routeResult = await _routeTask.SolveRouteAsync(_routeParams); _route = _routeResult.Routes[0]; // Add a graphics overlay for the route graphics. MyMapView.GraphicsOverlays.Add(new GraphicsOverlay()); // Add graphics for the stops. SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20); MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol)); MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol)); // Create a graphic (with a dashed line symbol) to represent the route. _routeAheadGraphic = new Graphic(_route.RouteGeometry) { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5) }; // Create a graphic (solid) to represent the route that's been traveled (initially empty). _routeTraveledGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3) }; // Add the route graphics to the map view. MyMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic); MyMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic); // Set the map viewpoint to show the entire route. await MyMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100); CenterBtn.IsEnabled = true; StartBtn.IsEnabled = true; } catch (Exception e) { await DisplayAlert("Error", e.Message, "OK"); } }