Esempio n. 1
0
        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 Initialize()
        {
            try
            {
                // Update interface state.
                UpdateInterfaceState(SampleState.NotReady);

                // Create the map with a basemap.
                Map sampleMap = new Map(Basemap.CreateTopographicVector());
                sampleMap.InitialViewpoint = new Viewpoint(32.7157, -117.1611, 1e5);
                _myMapView.Map             = sampleMap;

                // Create the graphics overlays. These will manage rendering of route, direction, stop, and barrier graphics.
                _routeOverlay    = new GraphicsOverlay();
                _stopsOverlay    = new GraphicsOverlay();
                _barriersOverlay = new GraphicsOverlay();

                // Add graphics overlays to the map view.
                _myMapView.GraphicsOverlays.Add(_routeOverlay);
                _myMapView.GraphicsOverlays.Add(_stopsOverlay);
                _myMapView.GraphicsOverlays.Add(_barriersOverlay);

                // Create and initialize the route task.
                _routeTask = await RouteTask.CreateAsync(new Uri(RouteServiceUrl));

                // Get the route parameters from the route task.
                _routeParameters = await _routeTask.CreateDefaultParametersAsync();

                // Prepare symbols.
                _routeSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _barrierSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Red, null);

                // Configure directions display.
                _directionsViewModel = new DirectionsViewModel(_directions);

                // Create the table view controller for displaying directions.
                _directionsController = new UITableViewController(UITableViewStyle.Plain);

                // The table view content is managed by the view model.
                _directionsController.TableView.Source = _directionsViewModel;

                // Create the view controller for configuring the route.
                _routeSettingsController = new RouteSettingsViewController();

                // Enable the UI.
                UpdateInterfaceState(SampleState.Ready);
            }
            catch (Exception e)
            {
                UpdateInterfaceState(SampleState.NotReady);
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't load sample", "Couldn't start the sample. See the debug output for detail.");
            }
        }
        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();
        }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
        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();
            }
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 9
0
        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 Initialize()
        {
            try
            {
                // Update interface state.
                UpdateInterfaceState(SampleState.NotReady);

                // Create the map with a basemap.
                Map sampleMap = new Map(BasemapStyle.ArcGISTopographic);
                sampleMap.InitialViewpoint = new Viewpoint(32.7157, -117.1611, 1e5);
                MyMapView.Map = sampleMap;

                // Create the graphics overlays. These will manage rendering of route, direction, stop, and barrier graphics.
                _routeOverlay    = new GraphicsOverlay();
                _stopsOverlay    = new GraphicsOverlay();
                _barriersOverlay = new GraphicsOverlay();

                // Add graphics overlays to the map view.
                MyMapView.GraphicsOverlays.Add(_routeOverlay);
                MyMapView.GraphicsOverlays.Add(_stopsOverlay);
                MyMapView.GraphicsOverlays.Add(_barriersOverlay);

                // Create and initialize the route task.
                _routeTask = await RouteTask.CreateAsync(new Uri(RouteServiceUrl));

                // Get the route parameters from the route task.
                _routeParameters = await _routeTask.CreateDefaultParametersAsync();

                // Prepare symbols.
                _routeSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _barrierSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Red, null);

                // Enable the UI.
                UpdateInterfaceState(SampleState.Ready);
            }
            catch (Exception e)
            {
                UpdateInterfaceState(SampleState.NotReady);
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't load sample", "Couldn't start the sample. See the debug output for detail.");
            }
        }
Esempio n. 11
0
        /// <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
            });
        }
Esempio n. 12
0
        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 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();
            }
        }
Esempio n. 16
0
        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 Initialize()
        {
            try
            {
                // Get the paths to resources used by the sample.
                string basemapTilePath        = DataManager.GetDataFolder("567e14f3420d40c5a206e5c0284cf8fc", "streetmap_SD.tpk");
                string networkGeodatabasePath = DataManager.GetDataFolder("567e14f3420d40c5a206e5c0284cf8fc", "sandiego.geodatabase");

                // Create the tile cache representing the offline basemap.
                TileCache tiledBasemapCache = new TileCache(basemapTilePath);

                // Create a tiled layer to display the offline tiles.
                ArcGISTiledLayer offlineTiledLayer = new ArcGISTiledLayer(tiledBasemapCache);

                // Create a basemap based on the tile layer.
                Basemap offlineBasemap = new Basemap(offlineTiledLayer);

                // Create a new map with the offline basemap.
                Map theMap = new Map(offlineBasemap);

                // Set the initial viewpoint to show the routable area.
                theMap.InitialViewpoint = new Viewpoint(_routableArea);

                // Show the map in the map view.
                _myMapView.Map = theMap;

                // Create overlays for displaying the stops and the calculated route.
                _stopsOverlay = new GraphicsOverlay();
                _routeOverlay = new GraphicsOverlay();

                // Create a symbol and renderer for symbolizing the calculated route.
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _routeOverlay.Renderer = new SimpleRenderer(routeSymbol);

                // Add the stops and route overlays to the map.
                _myMapView.GraphicsOverlays.Add(_stopsOverlay);
                _myMapView.GraphicsOverlays.Add(_routeOverlay);

                // Create the route task, referring to the offline geodatabase with the street network.
                _offlineRouteTask = await RouteTask.CreateAsync(networkGeodatabasePath, "Streets_ND");

                // Get the list of available travel modes.
                _availableTravelModes = _offlineRouteTask.RouteTaskInfo.TravelModes.ToList();

                // Update the UI with the travel modes list.
                ArrayAdapter <string> spinnerListAdapter = new ArrayAdapter <string>(this,
                                                                                     Android.Resource.Layout.SimpleSpinnerItem, _availableTravelModes.Select(travelMode => travelMode.Name).ToArray());
                _travelModeSpinner.Adapter = spinnerListAdapter;
                _travelModeSpinner.SetSelection(0);

                // Create the default parameters.
                _offlineRouteParameters = await _offlineRouteTask.CreateDefaultParametersAsync();

                // Display the extent of the road network on the map.
                DisplayBoundaryMarker();

                // Now that the sample is ready, hook up the tapped and hover events.
                _myMapView.GeoViewTapped        += MapView_Tapped;
                _travelModeSpinner.ItemSelected += TravelMode_SelectionChanged;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't start sample", "There was a problem starting the sample. See debug output for details.");
            }
        }
Esempio n. 18
0
        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");
            }
        }
        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;
        }
Esempio n. 20
0
        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");
            }
        }
Esempio n. 21
0
        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");
            }
        }