AGSGraphicsLayer with manual added graphics, all graphics are located at 0,0

485
2
09-20-2011 05:39 AM
ReneNijkamp
New Contributor
Hi all,

I retrieve some data from a webserver, through JSON. This works flawless.
In this data is the latitude, longitude and a name.

I want to add this data to my mapview, i've added a AGSGraphicsLayer to do this.

I add the graphics layer with the following code:

    self.trackLayer = [AGSGraphicsLayer graphicsLayer];
    [self.mapView addMapLayer:self.trackLayer withName:@"trackLayer"];


This works. As expected.

When i push a button the data is received, and added to the map:


    NSArray *locations = [_locationService getLocations];
    
    for (NSDictionary* loc in locations) {
        NSLog(@"%@", loc);
        float lat = [[loc objectForKey:@"lat"] floatValue];
        float lon = [[loc objectForKey:@"lon"] floatValue];
        AGSSimpleMarkerSymbol *pointMarker = [AGSSimpleMarkerSymbol simpleMarkerSymbolWithColor:[UIColor redColor]];
        pointMarker.size = 10.00;
        pointMarker.style = AGSSimpleMarkerSymbolStyleCircle;    

        AGSPoint *point = [AGSPoint pointWithX:lat y:lon spatialReference:self.mapView.spatialReference];

        AGSGraphic *location = [[AGSGraphic alloc] initWithGeometry:point symbol:pointMarker attributes:Nil infoTemplateDelegate:Nil];
        NSLog(@"%@", location);
        [_trackLayer addGraphic:location];
    }
   [_trackLayer dataChanged];



The NSLog produces the following:
geometry: AGSPoint: x = 52.322800, y = 4.879720, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null], symbol: { AGSSimpleMarkerSymbol: style: esriSMSCircle, size: 10.000000, outline: <AGSSimpleLineSymbol: 0x8c0b50> }, attributes: (null)

When i print the description of the geometry within the Graphics layer:
AGSPoint: x = 52.317799, y = 4.879200, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null]


So, the coordinates are in the point. For all the testdata. But they are still shown at 0,0!
Whats wrong here? The only thing i saw was that the renderer and initialEnvelope  of the GraphicsLayer is 0x0...


Many thanks!
0 Kudos
2 Replies
PaulLohr
Occasional Contributor III
I bet you are using a base layer for your AGSMapView that has a spatial reference of something other than 4326 (WGS 1984). If this is the case, try using a base layer that uses the 4326 spatial reference. Or you can use AGSGeometryEngine to convert your points to the coordinate system of your map.

Hope this helps,
Paul Lohr
0 Kudos
ReneNijkamp
New Contributor
Of course! That did the trick 🙂 Thanks!
0 Kudos