private async void SolveRoutesClick(object sender, EventArgs e) { // Holds locations of hospitals around San Diego. List <Facility> facilities = new List <Facility>(); // Holds locations of hospitals around San Diego. List <Incident> incidents = new List <Incident>(); // Create query parameters to select all features. QueryParameters queryParams = new QueryParameters() { WhereClause = "1=1" }; // Query all features in the facility table. FeatureQueryResult facilityResult = await _facilityTable.QueryFeaturesAsync(queryParams); // Add all of the query results to facilities as new Facility objects. facilities.AddRange(facilityResult.ToList().Select(feature => new Facility((MapPoint)feature.Geometry))); // Query all features in the incident table. FeatureQueryResult incidentResult = await _incidentTable.QueryFeaturesAsync(queryParams); // Add all of the query results to facilities as new Incident objects. incidents.AddRange(incidentResult.ToList().Select(feature => new Incident((MapPoint)feature.Geometry))); // Set facilities and incident in parameters. ClosestFacilityParameters closestFacilityParameters = await _task.CreateDefaultParametersAsync(); closestFacilityParameters.SetFacilities(facilities); closestFacilityParameters.SetIncidents(incidents); try { // Use the task to solve for the closest facility. ClosestFacilityResult result = await _task.SolveClosestFacilityAsync(closestFacilityParameters); for (int i = 0; i < incidents.Count; i++) { // Get the index of the closest facility to incident. (i) is the index of the incident, [0] is the index of the closest facility. int closestFacility = result.GetRankedFacilityIndexes(i)[0]; // Get the route to the closest facility. ClosestFacilityRoute route = result.GetRoute(closestFacility, i); // Display the route on the graphics overlay. _myMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(route.RouteGeometry, _routeSymbols[i % _routeSymbols.Count])); } // Disable the solve button. _solveRoutesButton.Enabled = false; // Enable the reset button. _resetButton.Enabled = true; } catch (Esri.ArcGISRuntime.Http.ArcGISWebException exception) { CreateErrorDialog("An ArcGIS web exception occurred.\n" + exception.Message); } }
private async void Initialize() { // Web マップの Id を指定してマップを作成 ArcGISPortal portal = await ArcGISPortal.CreateAsync(); PortalItem webmapItem = await PortalItem.CreateAsync(portal, "285f619f75e64d3681ba101b006d2f65"); Map myMap = new Map(webmapItem); await myMap.LoadAsync(); // マップビューのマップに設定 MyMapView.Map = myMap; // マップがロードされた際の処理 if (MyMapView.Map.LoadStatus == LoadStatus.Loaded) { // 最寄り施設の検出解析の設定 var uri = new Uri("https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World"); closestFacilityTask = await ClosestFacilityTask.CreateAsync(uri); closestFacilityTask.Credential = credential; // パラメータの設定 closestFacilityParameters = await closestFacilityTask.CreateDefaultParametersAsync(); closestFacilityParameters.ReturnRoutes = true; closestFacilityParameters.OutputSpatialReference = MyMapView.SpatialReference; // マップビューのタップ イベントを登録 MyMapView.GeoViewTapped += OnMapViewTapped; // 検索対象のレイヤーの取得 foreach (FeatureLayer featureLayer in MyMapView.Map.OperationalLayers) { if (featureLayer.Name == "室蘭市 - 避難場所") { shelterLayer = featureLayer; } } // マップビューにグラフィック表示用のオーバレイを追加 MyMapView.GraphicsOverlays.Add(myGraphicsOverlay); } }
private async void PopulateParametersAndSolveRouteAsync() { try { // Set facilities and incident in parameters. ClosestFacilityParameters closestFacilityParameters = await _task.CreateDefaultParametersAsync(); closestFacilityParameters.SetFacilities(_facilities); closestFacilityParameters.SetIncidents(new List <Incident> { new Incident(_incidentPoint) }); // Use the task to solve for the closest facility. ClosestFacilityResult result = await _task.SolveClosestFacilityAsync(closestFacilityParameters); // Get the index of the closest facility to incident. (0) is the index of the incident, [0] is the index of the closest facility. int closestFacility = result.GetRankedFacilityIndexes(0)[0]; // Get route from closest facility to the incident and display to mapview. ClosestFacilityRoute route = result.GetRoute(closestFacility, 0); // Add graphics for the incident and route. _incidentGraphicsOverlay.Graphics.Add(new Graphic(_incidentPoint, _incidentSymbol)); _incidentGraphicsOverlay.Graphics.Add(new Graphic(route.RouteGeometry, _routeSymbol)); } catch (Esri.ArcGISRuntime.Http.ArcGISWebException exception) { if (exception.Message.Equals("Unable to complete operation.")) { CreateErrorDialog("Incident not within San Diego area!"); } else { CreateErrorDialog("An ArcGIS web exception occurred. \n" + exception.Message); } } }