Hi,
I am drawing a circle in a code behind using following code.:
code:
[PHP]
private ESRI.ArcGIS.Client.Geometry.Polygon createCirclePolygon(MapPoint ptCenter,
double dRadius, int n, ESRI.ArcGIS.Client.Map map)
{
//create new point collection
ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection();
//center point in pixels
System.Windows.Point ptCenterScreen = map.MapToScreen(ptCenter);
n = n <= 0 ? 32 : n;
for (int i = 0; i < n; i++)
{
//ecah point on the circle, counterclockwise
double angle = (Math.PI * 2) / n * i;
System.Windows.Point p = new System.Windows.Point()
{
X = ptCenterScreen.X + dRadius * Math.Cos(angle),
Y = ptCenterScreen.Y + dRadius * Math.Sin(angle)
};
pc.Add(map.ScreenToMap(p));
};
//add the last, which is exact the first, point.
pc.Add(map.ScreenToMap(new System.Windows.Point()
{
X = ptCenterScreen.X + dRadius,
Y = ptCenterScreen.Y
}));
ESRI.ArcGIS.Client.Geometry.Polygon polyg = new ESRI.ArcGIS.Client.Geometry.Polygon();
polyg.SpatialReference = map.SpatialReference;
polyg.Rings.Add(pc);
return polyg;
}
[/PHP]
I am seeing an issue in above code.If I draw a circle, it is drawn. Now, if I zoom out and again draw a circle with same radius, it should be drawn a little smaller than previous one. But it is getting drawn bigger.So, when map extent is changed, size of the circle (though radius is same) is getting changed.
I think there is some scrren coordinates issue and I am not being able to spot it. Can anybody help me on this issue? I would appreciate any help.
Regards,
Sanjay.