AnsweredAssumed Answered

Draw a circle with width in meter

Question asked by nviot64 on Apr 3, 2014
Latest reply on Apr 3, 2014 by geonetadmin
Hi everyone,

I would like to draw a circle on a point with width in meter.

To do that, I've tried to use the scale of the map.
Assuming that scale = ft / pixel (i'm not sure that this formula is correct)
And ft = m * 3.2808

sizeInPixel = sizeInMeter / MyMap.Scale * 3.2808;

To draw the circle I use a class inheriting from polygon :
    public class Circle : Polygon     {         private double radius = double.NaN;         private MapPoint center = null;         private int pointCount = 360;          public double Radius         {             get { return radius; }             set { radius = value; CreateRing(); }         }          [System.ComponentModel.TypeConverter(typeof(MapPointConverter))]         public MapPoint Center         {             get { return center; }             set { center = value; CreateRing(); }         }          public int PointCount         {             get { return pointCount; }             set { pointCount = value; CreateRing(); }         }          private void CreateRing()         {             this.Rings.Clear();             if (!double.IsNaN(Radius) && Radius > 0 && Center != null && PointCount > 2)             {                 PointCollection pnts = new PointCollection();                 for (int i = 0; i <= PointCount; i++)                 {                     double rad = 2 * Math.PI / PointCount * i;                     double x = Math.Cos(rad) * radius + Center.X;                     double y = Math.Sin(rad) * radius + Center.Y;                     pnts.Add(new MapPoint(x, y));                 }                 this.Rings.Add(pnts);             }         }     }


And to define the width of my crircle :
            var buffer = new _2gDataRoomViewer.MyGeoms.Circle();             buffer.Center = new MapPoint(lon, lat);             buffer.Radius = bufferSize / (MyMap.Scale * 3.2808);//bufferSize is the width in meter              GraphicsLayer bufferPuitsLayer = MyMap.Layers["BufferPuitsLayer"] as GraphicsLayer;              var symbol = new SimpleFillSymbol();             symbol.BorderThickness = 3;             SolidColorBrush color = new SolidColorBrush(Colors.Violet);             symbol.Fill = color;             symbol.Fill.Opacity = 0.3;             symbol.BorderBrush = color;              Graphic graphic = new Graphic()             {                 Geometry = mercator.FromGeographic(buffer),                 Symbol = symbol             };             bufferPuitsLayer.Graphics.Add(graphic);


But it doesn't works And the size change when I try to recalculate it on a zoom/dezoom
When I zoom in :
[ATTACH=CONFIG]32760[/ATTACH]
When I zoom out :
[ATTACH=CONFIG]32761[/ATTACH]

Thanks

Attachments

Outcomes