AGSGraphicsLayer not showing

2489
4
Jump to solution
03-19-2014 02:09 AM
AhmedElAshker
New Contributor II
1- After creating the basemap layer
self.graphicsLayer = [AGSGraphicsLayer graphicsLayer]; [self.mapView addMapLayer:self.graphicsLayer withName:@"Graphics Layer"];


2- I'm using GeoTrigger service and I call the "trigger/list" instruction. I use the code in the "Turn a trigger region into an AGSGeometry object" from this link https://developers.arcgis.com/geotrigger-service/guide/using-geotrigger-sdk-with-arcgis-runtime-sdk/...

CLLocation *location = self.locations[0];      NSDictionary *params = @{@"geoFormat": @"esrijson", @"geo":                                  @{@"latitude": @(location.coordinate.latitude), @"longitude": @(location.coordinate.longitude), @"distance": @100}};      [[AGSGTApiClient sharedClient] postPath:@"trigger/list"                                  parameters:params                                     success:^(id responseObject) {                                         if (responseObject != nil) {                                                                                          NSArray *triggers = responseObject[@"triggers"];                                             for (NSDictionary *trigger in triggers) {                                                 NSDictionary *condition = trigger[@"condition"];                                                 NSDictionary *geo = condition[@"geo"];                                                 NSDictionary *esriJson = geo[@"esrijson"];                                                                                                  AGSGeometry *geometry = AGSGeometryWithJSONAndSR(esriJson, [self.mapView spatialReference]);                                                                                                  // Do stuff with geometry!                                                                                                  AGSFillSymbol* symbol = [AGSSimpleFillSymbol simpleFillSymbol];                                                 symbol.color = [UIColor redColor];                                                                                                  //Create the AGSSimpleLineSymbol used for the outline                                                 AGSSimpleLineSymbol* myOutlineSymbol = [AGSSimpleLineSymbol simpleLineSymbol];                                                 myOutlineSymbol.color = [UIColor redColor];                                                 myOutlineSymbol.width = 2;                                                                                                  //set the outline property to myOutlineSymbol                                                 symbol.outline = myOutlineSymbol;                                                                                                  AGSGraphic *LocationDisplay = [[AGSGraphic alloc] initWithGeometry:geometry symbol:symbol attributes:nil];                                                                                                  [self.graphicsLayer addGraphic:LocationDisplay];                                                                                                  [self.graphicsLayer refresh];                                                                                                  [self.mapView zoomToGeometry:[LocationDisplay geometry] withPadding:0 animated:YES];                                             }                                         }                                     }                                     failure:^(NSError *error) {                                         NSLog(@"Error listing triggers: %@", error);                                     }];


The codes zooms me to desired trigger area successfully, but it never shows the symbol for the graphic.

I refer to the following link regarding graphics layers https://developers.arcgis.com/ios/guide/creating-a-graphics-layer.htm#ESRI_SECTION1_782802E7EF1E479C...

I've tried with a simpleFillSymbol, then with this outlineSymbol. I then tried using a TextSymbol instead, I even swiped away the whole basemap layer after zooming and still nothing shows from the graphicsLayer.

What am I not doing right here?
0 Kudos
1 Solution

Accepted Solutions
DiveshGoyal
Esri Regular Contributor
I suspect this may be due to a mismatching spatial reference.

Can you print the value of esriJson that contains your geometries?
You are converting these into a geometry using AGSGeometryWithJSONAndSR() but passing in the map's spatial reference. If the spatial reference of your geometries does not  match the map's spatial reference, they might get drawn at the wrong location.

View solution in original post

0 Kudos
4 Replies
AhmedElAshker
New Contributor II
FYI, I also tried applying a renderer for the whole graphics layer. Twice. (in the viewDidLoad of course after initialising the layer and before adding the layer to the mapView)

First
AGSFillSymbol* symbol = [AGSSimpleFillSymbol simpleFillSymbol];
symbol.color = [UIColor redColor];

AGSSimpleRenderer* mySimpleRenderer = [AGSSimpleRenderer simpleRendererWithSymbol:symbol];
    
self.graphicsLayer.renderer = mySimpleRenderer;

Then
AGSFillSymbol* symbol = [AGSSimpleFillSymbol simpleFillSymbol];
symbol.color = [UIColor redColor];

AGSUniqueValueRenderer *cityRenderer = [[AGSUniqueValueRenderer alloc] init];
cityRenderer.defaultSymbol = symbol;
    
self.graphicsLayer.renderer = cityRenderer;

And still nothing.
0 Kudos
AhmedElAshker
New Contributor II
I've downloaded Esri's iOS GraphicsSample, the one with the segmented control and it's working just fine. It's very helpful specially with the callout feature implemented.

I've looked through to compare the sample code with mine, there are hardly differences to notice but I'm suspicious over this line.
self.mapView.layerDelegate = self;


When I tried to copy it my app immediately responded with this warning.
Assigning to 'id<AGSMapViewLayerDelegate>' from incompatible type 'ViewController_iPad *const __strong'


Despite the warning I ran the app and I still get what I may call an invisible graphicsLayer, although I checked it's visibility is set to YES (true).

I thought you should know this as well.
0 Kudos
DiveshGoyal
Esri Regular Contributor
I suspect this may be due to a mismatching spatial reference.

Can you print the value of esriJson that contains your geometries?
You are converting these into a geometry using AGSGeometryWithJSONAndSR() but passing in the map's spatial reference. If the spatial reference of your geometries does not  match the map's spatial reference, they might get drawn at the wrong location.
0 Kudos
AhmedElAshker
New Contributor II
Well well, that seems to be about right. I didn't think that was it because the map was getting me to the correct location only without the symbol. I also believed that AGSGeometryWithJSONAndSR() would set the desired SR for the geometry. But after checking on the wkid for both the geometry and the map it was clear they are not the same.

I resorted to [AGSGeometryEngine projectGeometrytoSpatialReference] to create a new geometry with the map's SR. Works like a charm now.

Many thanks.
0 Kudos