Solved! Go to Solution.
//iterate through the closest facility results array in the closestFacilityTaskResult returned by the task for (AGSClosestFacilityResult *cfResult in closestFacilityTaskResult.closestFacilityResults) { if (cfResult) { //First, add route graphic to map cfResult.routeGraphic.symbol = [self routeSymbol]; [self.graphicsLayer addGraphic:cfResult.routeGraphic]; //Then, query to select the closest facility AGSQuery *query = [AGSQuery query]; query.where = [NSString stringWithFormat:@"OBJECTID = %@",[cfResult.routeGraphic attributeAsStringForKey:@"FacilityID"]]; [self.facilitiesLayer selectFeaturesWithQuery:query selectionMethod:AGSFeatureLayerSelectionMethodAdd]; self.facilitiesLayer.queryDelegate = self; } }
Hi,
I am finding the route for the Closest Facility from a user defined location. Able to do it successfully and the route is drawn as required, but however I want to select the closest facility as well after the route is drawn. Please find the screen shot for the route display to the closest faclity from the user's location.
Is it possible to do it and can anybody help me with the code for selection for the closest facility. Please find the code below...
// update the status message
self.statusMessageLabel.text = @"Finding closest facilities";
// if we have a sketch layer on the map, remove it
if ([self.mapView.mapLayers containsObject:self.sketchLayer]) {
[self.mapView removeMapLayerWithName:self.sketchLayer.name];
self.mapView.touchDelegate = nil;
self.sketchLayer = nil;
//also disable the sketch control so that user cannot sketch
self.sketchModeSegCtrl.selectedSegmentIndex = -1;
for (int i =0; i<self.sketchModeSegCtrl.numberOfSegments; i++) {
[self.sketchModeSegCtrl setEnabled:NO forSegmentAtIndex:i];
}
}
//retrieves the default parameters for the closest facility task from the server
//the caOp property will keep tract of the operation in case we need to cancel it at any point.
self.cfOp = [self.cfTask retrieveDefaultClosestFacilityTaskParameters];
//showing activity indicator
[self.activityAlertView show];
self.mapView.touchDelegate = self;
Regards,
Saurabh.
//iterate through the closest facility results array in the closestFacilityTaskResult returned by the task for (AGSClosestFacilityResult *cfResult in closestFacilityTaskResult.closestFacilityResults) { if (cfResult) { //First, add route graphic to map cfResult.routeGraphic.symbol = [self routeSymbol]; [self.graphicsLayer addGraphic:cfResult.routeGraphic]; //Then, query to select the closest facility AGSQuery *query = [AGSQuery query]; query.where = [NSString stringWithFormat:@"OBJECTID = %@",[cfResult.routeGraphic attributeAsStringForKey:@"FacilityID"]]; [self.facilitiesLayer selectFeaturesWithQuery:query selectionMethod:AGSFeatureLayerSelectionMethodAdd]; self.facilitiesLayer.queryDelegate = self; } }