private async void Initialize() { // Hook up the DrawStatusChanged event. MyMapView.DrawStatusChanged += OnDrawStatusChanged; // Construct the map and set the MapView.Map property. Map map = new Map(BasemapStyle.ArcGISLightGray); MyMapView.Map = map; try { // Create a ClosestFacilityTask using the San Diego Uri. _task = await ClosestFacilityTask.CreateAsync(new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ClosestFacility")); // List of facilities to be placed around San Diego area. _facilities = new List <Facility> { new Facility(new MapPoint(-1.3042129900625112E7, 3860127.9479775648, SpatialReferences.WebMercator)), new Facility(new MapPoint(-1.3042193400557665E7, 3862448.873041752, SpatialReferences.WebMercator)), new Facility(new MapPoint(-1.3046882875518233E7, 3862704.9896770366, SpatialReferences.WebMercator)), new Facility(new MapPoint(-1.3040539754780494E7, 3862924.5938606677, SpatialReferences.WebMercator)), new Facility(new MapPoint(-1.3042571225655518E7, 3858981.773018156, SpatialReferences.WebMercator)), new Facility(new MapPoint(-1.3039784633928463E7, 3856692.5980474586, SpatialReferences.WebMercator)), new Facility(new MapPoint(-1.3049023883956768E7, 3861993.789732541, SpatialReferences.WebMercator)) }; // Center the map on the San Diego facilities. Envelope fullExtent = GeometryEngine.CombineExtents(_facilities.Select(facility => facility.Geometry)); await MyMapView.SetViewpointGeometryAsync(fullExtent, 50); // Create a symbol for displaying facilities. _facilitySymbol = new PictureMarkerSymbol(new Uri("https://static.arcgis.com/images/Symbols/SafetyHealth/Hospital.png")) { Height = 30, Width = 30 }; // Incident symbol. _incidentSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, Color.FromArgb(255, 0, 0, 0), 30); // Route to hospital symbol. _routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.FromArgb(255, 0, 0, 255), 5.0f); // Create Graphics Overlays for incidents and facilities. _incidentGraphicsOverlay = new GraphicsOverlay(); _facilityGraphicsOverlay = new GraphicsOverlay(); // Create a graphic and add to graphics overlay for each facility. foreach (Facility facility in _facilities) { _facilityGraphicsOverlay.Graphics.Add(new Graphic(facility.Geometry, _facilitySymbol)); } // Add each graphics overlay to MyMapView. MyMapView.GraphicsOverlays.Add(_incidentGraphicsOverlay); MyMapView.GraphicsOverlays.Add(_facilityGraphicsOverlay); } catch (Exception e) { MessageBox.Show(e.ToString(), "Error"); } }
private async void Initialize() { try { // Construct the map and set the MapView.Map property. MyMapView.Map = new Map(Basemap.CreateLightGrayCanvasVector()); // Add a graphics overlay to MyMapView. (Will be used later to display routes) MyMapView.GraphicsOverlays.Add(new GraphicsOverlay()); // Create a ClosestFacilityTask using the San Diego Uri. _task = await ClosestFacilityTask.CreateAsync(_closestFacilityUri); // Create a symbol for displaying facilities. PictureMarkerSymbol facilitySymbol = new PictureMarkerSymbol(new Uri("https://static.arcgis.com/images/Symbols/SafetyHealth/FireStation.png")) { Height = 30, Width = 30 }; // Incident symbol. PictureMarkerSymbol incidentSymbol = new PictureMarkerSymbol(new Uri("https://static.arcgis.com/images/Symbols/SafetyHealth/esriCrimeMarker_56_Gradient.png")) { Height = 30, Width = 30 }; // Create a list of line symbols to show unique routes. Different colors help make different routes visually distinguishable. _routeSymbols = new List <SimpleLineSymbol>() { new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(125, 25, 45, 85), 5.0f), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(125, 35, 65, 120), 5.0f), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(125, 55, 100, 190), 5.0f), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(125, 75, 140, 255), 5.0f) }; // Create a table for facilities using the FeatureServer. _facilityTable = new ServiceFeatureTable(_facilityUri); // Create a feature layer from the table. _facilityLayer = new FeatureLayer(_facilityTable) { Renderer = new SimpleRenderer(facilitySymbol) }; // Create a table for facilities using the FeatureServer. _incidentTable = new ServiceFeatureTable(_incidentUri); // Create a feature layer from the table. _incidentLayer = new FeatureLayer(_incidentTable) { Renderer = new SimpleRenderer(incidentSymbol) }; // Add the layers to the map. MyMapView.Map.OperationalLayers.Add(_facilityLayer); MyMapView.Map.OperationalLayers.Add(_incidentLayer); // Wait for both layers to load. await _facilityLayer.LoadAsync(); await _incidentLayer.LoadAsync(); // Zoom to the combined extent of both layers. Envelope fullExtent = GeometryEngine.CombineExtents(_facilityLayer.FullExtent, _incidentLayer.FullExtent); await MyMapView.SetViewpointGeometryAsync(fullExtent, 50); // Enable the solve button. SolveRoutesButton.IsEnabled = true; } catch (Exception exception) { await Application.Current.MainPage.DisplayAlert("Error", "An exception has occurred.\n" + exception.Message, "OK"); } }