draw circles on the graphics layer

5671
3
02-07-2013 08:09 AM
RussellEgypt
New Contributor II
Hi

I'm new to ArcGIS Runtime. Just looking for a solution to programmatically draw circles on the map within the graphics layer, having a file with center points and the circle radius.

Thanks
0 Kudos
3 Replies
AaronNoriega
New Contributor III
Since you have the center and radius, you can derive the points along the circumference and produce a polygon.


private ESRI.ArcGIS.Client.Geometry.Polygon DrawCircle(ESRI.ArcGIS.Client.Geometry.MapPoint center, double radius, int pointsCount = 360) {
ESRI.ArcGIS.Client.Geometry.Polygon p = new ESRI.ArcGIS.Client.Geometry.Polygon();
ESRI.ArcGIS.Client.Geometry.PointCollection pcol = new ESRI.ArcGIS.Client.Geometry.PointCollection();
double slice = 2 * Math.PI / pointsCount;
for (int i = 0; i <= pointsCount; i++) {
  double rad = slice * i;
  double px = center.X + radius * Math.Cos(rad);
  double py = center.Y + radius * Math.Sin(rad);
  pcol.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(px, py));
}
p.Rings.Add(pcol);
return p;
}
0 Kudos
dotMorten_esri
Esri Frequent Contributor
Here's a slightly different approach, which is done by subclassing Polygon:http://forums.esri.com/Thread.asp?c=213&f=2455&t=289039#898885

Basically allows you to write :
         var polygon = new Circle() { Center=new MapPoint(-117,34), Radius = 2 };
0 Kudos
RussellEgypt
New Contributor II
Thankyou for the response and your working solutions!

I've used Aaron Noriega solution!
0 Kudos