self.queryTask = [AGSQueryTask queryTaskWithURL:featureURL]; self.queryTask.delegate = self; AGSQuery *query = [AGSQuery query]; query.where = @"OBJECTID <= 100"; query.outFields = [NSArray arrayWithObject:@"*"]; query.returnGeometry = YES; [self.queryTask executeWithQuery:query];
- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet { [self.graphicsLayer removeAllGraphics]; for (AGSGraphic *graphic in featureSet.features) { graphic.visible = YES; [self.graphicsLayer addGraphic:graphic]; } [self.graphicsLayer dataChanged]; }
AGSGraphic* myGraphic =[AGSGraphic graphicWithGeometry:myMarkerPoint symbol:myMarkerSymbol attributes:nodeDict infoTemplateDelegate:template]; //Add the graphic to the Graphics layer [self.graphicsLayer addGraphic:myGraphic];
Solved! Go to Solution.
- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet { [self.graphicsLayer removeAllGraphics]; AGSSimpleFillSymbol *simpleFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; for (AGSGraphic *graphic in featureSet.features) { graphic.visible = YES; graphic.symbol = simpleFillSymbol; [self.graphicsLayer addGraphic:graphic]; } [self.graphicsLayer dataChanged]; }
self.graphicsLayer.renderer = [[AGSSimpleRenderer simpleRendererWithSymbol:[AGSSimpleFillSymbol simpleFillSymbol]] retain];
- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet { NSLog ( @"Renderer: %@", [self.graphicsLayer.renderer description]); NSLog( @" featureSet: %@", [featureSet description]); [self.graphicsLayer removeAllGraphics]; AGSSimpleFillSymbol *simpleFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; for (AGSGraphic *graphic in featureSet.features) { graphic.visible = YES; graphic.symbol = simpleFillSymbol; [self.graphicsLayer addGraphic:graphic]; NSLog(@" graphic: %@", [graphic description]); } [self.graphicsLayer dataChanged]; }
Renderer: (null) featureSet: AGSFeatureSet: display name: SEGMENT_PREFIX geometry type: esriGeometryPolyline num features: 100 spatial reference: AGSSpatialReference: wkid = 4326, wkt = null graphic: geometry: AGSPolyline: [envelope: AGSEnvelope: xmin = -83.691725, ymin = 36.763704, xmax = -83.378514, ymax = 36.886530, spatial reference: [AGSSpatialReference: wkid = 4326, wkt = null]], symbol: <AGSSimpleFillSymbol: 0xacc3110>, attributes: { "ENG_REGION" = SOUTH; OBJECTID = 25; "SEGMENT_PREFIX" = 0SC; "SHAPE.LEN" = "41502.858489515296"; }, visible: 1
What type of renderer is set for the graphics layer? The returned graphics from query task ash which type of geometry? If render set on the graphics layer does not support geometry returned by query task then you should set symbol on each graphic before adding them to the graphics layer and it should draw it.
If returned graphics has polygon geometry then do this.- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet { [self.graphicsLayer removeAllGraphics]; AGSSimpleFillSymbol *simpleFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; for (AGSGraphic *graphic in featureSet.features) { graphic.visible = YES; graphic.symbol = simpleFillSymbol; [self.graphicsLayer addGraphic:graphic]; } [self.graphicsLayer dataChanged]; }
Hope this helps!
Regards,
Nimesh
- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet { [self.graphicsLayer removeAllGraphics]; AGSSimpleFillSymbol *simpleFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; for (AGSGraphic *graphic in featureSet.features) { if ([graphic.geometry isKindOfClass:[AGSPoint class]] || [graphic.geometry isKindOfClass:[AGSMultipoint class]]) { graphic.symbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol]; } else if ([graphic.geometry isKindOfClass:[AGSPolyline class]]) { graphic.symbol = [AGSSimpleLineSymbol simpleLineSymbol]; } else if ([graphic.geometry isKindOfClass:[AGSPolygon class]]) { graphic.symbol = [AGSSimpleFillSymbol simpleFillSymbol]; } graphic.visible = YES; [self.graphicsLayer addGraphic:graphic]; } [self.graphicsLayer dataChanged]; }
AGSMutablePolyline *polyline = [[AGSMutablePolyline alloc] initWithSpatialReference:self.mapView.spatialReference]; [polyline addPathToPolyline]; [polyline addPointToPath:myPoint1]; [polyline addPointToPath:myPoint2]; AGSGraphic *poly = [[AGSGraphic alloc] initWithGeometry:polyline symbol:[AGSSimpleLineSymbol simpleLineSymbolWithColor:[UIColor blackColor]] attributes:nil infoTemplateDelegate:nil]; [self.graphicsLayer addGraphic:poly]; [poly release];
I said, "If returned graphics has polygon geometry then do this." but since geometry is polyline you should create simple line symbol. Just use below code and it will handle all type of geometry.- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet { [self.graphicsLayer removeAllGraphics]; AGSSimpleFillSymbol *simpleFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; for (AGSGraphic *graphic in featureSet.features) { if ([graphic.geometry isKindOfClass:[AGSPoint class]] || [graphic.geometry isKindOfClass:[AGSMultipoint class]]) { graphic.symbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol]; } else if ([graphic.geometry isKindOfClass:[AGSPolyline class]]) { graphic.symbol = [AGSSimpleLineSymbol simpleLineSymbol]; } else if ([graphic.geometry isKindOfClass:[AGSPolygon class]]) { graphic.symbol = [AGSSimpleFillSymbol simpleFillSymbol]; } graphic.visible = YES; [self.graphicsLayer addGraphic:graphic]; } [self.graphicsLayer dataChanged]; }
Also, go through working with symbols and renderer documentation. That'll help you understand everything.
Regards,
Nimesh
Okay, what is the spatial reference of the map (self.mapView.spatialReference)? What is the spatial reference of the geometries returned by query task?
If they are different then you should set out spatial reference to self.mapView.spatialReference of the query so server return geometries in map's spatial reference.
query.outSpatialReference = self.mapView.spatialReference;
Regards,
Nimesh