Howdy,
I have been trying (quite unsuccessfully) to turn the results of a feature layer query (polygons) into graphics to be added to a graphics layer. I have checked several times that the returned FeatureSet contains the correct amount of features per the WHERE clause of the query. Yet every time I iterate through the FeatureSet, create graphics, and add said graphics to the GraphicsLayer, nothing appears. Here is what I have so far.
Layer I am querying
NSURL* fenceUrl = [NSURL URLWithString: fenceAddress];
self.fenceLayer = [AGSFeatureLayer featureServiceLayerWithURL: fenceUrl mode:AGSFeatureLayerModeSelection];
The query
AGSQuery *pQuery = [AGSQuery query];
pQuery.where = @"USEREMAIL LIKE 'madeUpEmail@gmail.com'";
pQuery.outFields = [NSArray arrayWithObjects:@"*", nil];
pQuery.returnGeometry = YES;
[self.fenceLayer selectFeaturesWithQuery:pQuery selectionMethod:AGSFeatureLayerSelectionMethodAdd];
This is the result of NSLog-ing the graphics I am trying to add to the layer
geometry: AGSPolygon: [envelope: AGSEnvelope: xmin = -96.650200, ymin = 29.600216, xmax = -96.029897, ymax = 30.117631, spatial reference: [AGSSpatialReference: wkid = 4326, wkt = null]], symbol: <AGSSimpleFillSymbol: 0xde7f030>, attributes: {
OBJECTID = 801;
USEREMAIL = "madeUpEmail@gmail.com";
USERID = "1";
channelID = "<null>";
}, visible: 1
My only thought is this could be a incorrect SpatialReference problem. I have already defined the spatial reference for the graphics to both webMercatorSpatialReference (same as the base map) and wgs84SpatialReference (same as the FeatureLayer) to no success. I tried to add the polygon Nimesh made here https://community.esri.com/thread/28467 but even that failed to show up on my map. Any thoughts or ideas would be greatly appreciated.
Thanks,
Aaron.
Solved! Go to Solution.
I figured out my issue. I was initializing my AGSGraphicLayer with [AGSGraphicLayer graphicslayer] instead of [initWithSpatialReference]. Once I had that I was about to see my polygons as a single red pixel off the coast of Africa. Then I created the graphic using [AGSGraphic graphicWithGeometry:symbol:attributes:] while using [AGSGeometryGeographicToWebMercator(). This combination finally created the graphics right where I needed.
Thanks anyway Gagan!
Hi Aaron Harmon,
Did you try setting the 'outSpatialReference' to the mapView's spatialReference, once the mapView has loaded? It might be the case that the two spatial references are different.
Let me know if this helps.
Gagan
I figured out my issue. I was initializing my AGSGraphicLayer with [AGSGraphicLayer graphicslayer] instead of [initWithSpatialReference]. Once I had that I was about to see my polygons as a single red pixel off the coast of Africa. Then I created the graphic using [AGSGraphic graphicWithGeometry:symbol:attributes:] while using [AGSGeometryGeographicToWebMercator(). This combination finally created the graphics right where I needed.
Thanks anyway Gagan!