Select to view content in your preferred language

How to draw a circle on map without toolbar?

2292
2
12-28-2010 09:34 PM
YardenCochav
Deactivated User
Hello,

I am facing a big issue while using the ArcGIS JS API 2.0 when drawing circle zone on map according to a given center point and radius.
I received From My database centerPoint in LAT/LON and Radius in meters and need to draw circle zone accordingly. Unfortunately I found that the only way to draw circle without toolbar is by calling my geometryService.buffer function which returns a buffer polygon.
When I draw the buffer on the map, it shows a polygon shaped like a circle - But that's unacceptable by our customers.
What should I do?
I need your assistance urgently. thanks for any help.

Regards,
Jordan.
0 Kudos
2 Replies
Ranga_Tolapi
Frequent Contributor
function createCircleGeometry(map, pt, radius) {
    var polygon = new esri.geometry.Polygon();

    var points = [];
    for ( var i = 0; i <= 360; i += 10) {
     var radian = i * (Math.PI / 180.0);
     var x = pt.x + radius * Math.cos(radian);
     var y = pt.y + radius * Math.sin(radian);
     points.push(new esri.geometry.Point(x, y));
    }

       polygon.addRing(points);
       polygon.spatialReference = map.spatialReference;

       return polygon;   
   }
0 Kudos
GuyUrban
Emerging Contributor
I use this to draw circles. I posted a VB version on the forum as well.

Draw a circle on arcmap using java

    static void drawCircle2(IActiveView activeView) throws Exception
    {
    double Px;
    double Py;
    double Radius;

    IGraphicsContainer graphicsContainer = activeView.getGraphicsContainer();

    // set up the color
    IRgbColor rgbColor = new RgbColor();
    rgbColor.setRed(0);
    rgbColor.setGreen(255);
    rgbColor.setBlue(0);

    IColor color = rgbColor;

    // make the line and define its color, style and width
    ISimpleLineSymbol LineSymbol = new SimpleLineSymbol();
    LineSymbol.setColor(color);
    LineSymbol.setStyle(esriSimpleLineStyle.esriSLSSol id);
    LineSymbol.setWidth(2);

    ISymbol symbol = (ISymbol)LineSymbol;

    //create circle element
    ILineElement pCircleLineElement = new LineElement();
    pCircleLineElement.setSymbol(LineSymbol);
    IElement pCircleElement = (IElement)pCircleLineElement;

    // create point and radius
    Px = 0.0;
    Py = 0.0;
    Radius = 10.0;

    // Create circle geometry
    IPoint centerPoint = new Point();
    centerPoint.putCoords(Px,Py);

    IConstructCircularArc pCircularArc = new CircularArc();

    pCircularArc.constructCircle(centerPoint,Radius,tr ue);


    ISegment Seg = (ISegment)pCircularArc;
    ISegmentCollection SegCollection = new Polyline();
    SegCollection.addSegment(Seg,null,null);

    pCircleElement.setGeometry((IGeometry)SegCollection);

    //add the element to the map and draw it.
    graphicsContainer.addElement(pCircleElement,0);

    activeView.partialRefresh(esriViewDrawPhase.esriVi ewGraphics,null,null);

    }

Hope this helps.
0 Kudos