How to add a circle with a radius in meters to a graphics layer?

1548
1
Jump to solution
06-12-2014 07:18 AM
SjorsProvoost
New Contributor II
I built a feature which searches documents within a certain range (in meters) around a coordinate. I would like to show this range to the user by drawing a circle. I think I go the individual pieces, through e.g. this post, but I can't fit them together.

graphicsLayer is an instance of ASGraphicsLayer, which is already displaying a bunch of items. latitude and longitude are in decimal degrees. The graphics layer is in web mercator.

AGSPoint* centerPoint =  [AGSPoint pointWithX:longitude                                y:latitude                 spatialReference:[AGSSpatialReference wgs84SpatialReference]];               AGSPoint *webMercatorPoint = (AGSPoint *)[[AGSGeometryEngine defaultGeometryEngine] projectGeometry:centerPoint toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]];              AGSPolygon *polygon = [self circleWithCenter:webMercatorPoint radius:rangeInMeters];                          AGSGraphic *graphic = [AGSGraphic graphicWithGeometry:polygon symbol:nil attributes:nil];              [self.markerGraphicsLayer addGraphic:graphic];


I don't see a circle on the map when I do this.
0 Kudos
1 Solution

Accepted Solutions
SjorsProvoost
New Contributor II
It turns out I needed to add a filler symbol. I was also needlessly converting back and forth between projections and I forgot to mention part of my code in my post. Here's the new code:

AGSPoint* centerPoint =  [AGSPoint pointWithX:longitude                                y:latitude                 spatialReference:[AGSSpatialReference wgs84SpatialReference]];              AGSPolygon *polygon = [self circleWithCenter:webMercatorPoint radius:rangeInMeters];                          AGSGraphic *graphic = [AGSGraphic graphicWithGeometry:polygon symbol:[AGSSimpleFillSymbol simpleFillSymbol] attributes:nil];              [self.markerGraphicsLayer addGraphic:graphic];

-(AGSPolygon*) circleWithCenter:(AGSPoint*)point radius:(double)radiusInMeters {     AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine];          AGSPoint *pointToBufferAround = (AGSPoint *)[ge projectGeometry:point toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]];          AGSPolygon *circle = [ge bufferGeometry:pointToBufferAround byDistance:radiusInMeters];          return circle; } 

View solution in original post

0 Kudos
1 Reply
SjorsProvoost
New Contributor II
It turns out I needed to add a filler symbol. I was also needlessly converting back and forth between projections and I forgot to mention part of my code in my post. Here's the new code:

AGSPoint* centerPoint =  [AGSPoint pointWithX:longitude                                y:latitude                 spatialReference:[AGSSpatialReference wgs84SpatialReference]];              AGSPolygon *polygon = [self circleWithCenter:webMercatorPoint radius:rangeInMeters];                          AGSGraphic *graphic = [AGSGraphic graphicWithGeometry:polygon symbol:[AGSSimpleFillSymbol simpleFillSymbol] attributes:nil];              [self.markerGraphicsLayer addGraphic:graphic];

-(AGSPolygon*) circleWithCenter:(AGSPoint*)point radius:(double)radiusInMeters {     AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine];          AGSPoint *pointToBufferAround = (AGSPoint *)[ge projectGeometry:point toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]];          AGSPolygon *circle = [ge bufferGeometry:pointToBufferAround byDistance:radiusInMeters];          return circle; } 
0 Kudos