private async void CalculateAndShowRoute() { try { // Calculate the route. RouteResult calculatedRoute = await _routeTask.SolveRouteAsync(_routeParameters); // Get the first returned result. Route firstResult = calculatedRoute.Routes.First(); // Get the route geometry - this is the line that shows the route. Polyline calculatedRouteGeometry = firstResult.RouteGeometry; // Create the route graphic from the geometry and the symbol. Graphic routeGraphic = new Graphic(calculatedRouteGeometry, _routeSymbol); // Clear any existing routes, then add this one to the map. _routeOverlay.Graphics.Clear(); _routeOverlay.Graphics.Add(routeGraphic); // Add the directions to the textbox. PrepareDirectionsList(firstResult.DirectionManeuvers); } catch (Exception e) { System.Diagnostics.Debug.Write(e); ShowMessage("Routing error", $"Couldn't calculate route. See debug output for details. Message: {e.Message}"); } }
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 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(); }
public async Task <RouteResult> GetRoute(IEnumerable <MapPoint> stops, CancellationToken cancellationToken) { if (stops == null) { throw new ArgumentNullException("stops"); } List <Stop> stopList = new List <Stop>(); foreach (var stop in stops) { stopList.Add(new Stop(stop)); } if (stopList.Count < 2) { throw new ArgumentException("Not enough stops"); } string svc = routeService; try { //Calculate route RouteTask task = await RouteTask.CreateAsync(new Uri(svc), credential).ConfigureAwait(false); var parameters = await task.CreateDefaultParametersAsync().ConfigureAwait(false); parameters.SetStops(stopList); parameters.ReturnStops = true; parameters.ReturnDirections = true; parameters.RouteShapeType = RouteShapeType.TrueShapeWithMeasures; parameters.OutputSpatialReference = SpatialReferences.Wgs84; parameters.DirectionsDistanceUnits = Esri.ArcGISRuntime.UnitSystem.Metric; parameters.StartTime = DateTime.UtcNow; return(await task.SolveRouteAsync(parameters)); } catch (System.Exception ex) { if (ex is Esri.ArcGISRuntime.Http.ArcGISWebException) { var webex = (Esri.ArcGISRuntime.Http.ArcGISWebException)ex; if (webex.Details.FirstOrDefault()?.Contains("Unlocated") == true) { //This occurs if the server couldn't find a route to the location return(null); } } throw; } }
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(); } }
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); } }
/// <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 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"); } }
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"); } }
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 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; } } }
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; }