get coordinates of the polygon

1559
2
Jump to solution
09-20-2016 01:39 PM
GeorgeCastell
New Contributor

Hello,

I am new to using ArcGIS API, I need your help. someone can help me, I'm doing a project where the user draws a polygon and need to capture the coordinates of the polygon drawn.

I am leading this example
https://developers.arcgis.com/javascript/3/jssamples/util_label_point.html

Thank you...

0 Kudos
1 Solution

Accepted Solutions
EvelynHernandez
Occasional Contributor III
I think here u can get them: 
function addToMap(evtObj) {
      map.graphics.clear();
      var geometry = evtObj.geometry;
      // add the drawn graphic to the map
      var symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0]), 2),
        new Color([0, 0, 255, 0.5]));
      var graphic = new Graphic(geometry, symbol);
     
 // u will have the geometry itself so u can get the coords for the polygon drawn but u need to use a for loop to get them all.
       console.log(geometry.rings);  //<-- array of coords. 

      map.graphics.add(graphic);

      // simplify polygon so it can be used in the get label points request
      geometryService.simplify([geometry], getLabelPoints);
    }

View solution in original post

2 Replies
EvelynHernandez
Occasional Contributor III
I think here u can get them: 
function addToMap(evtObj) {
      map.graphics.clear();
      var geometry = evtObj.geometry;
      // add the drawn graphic to the map
      var symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0]), 2),
        new Color([0, 0, 255, 0.5]));
      var graphic = new Graphic(geometry, symbol);
     
 // u will have the geometry itself so u can get the coords for the polygon drawn but u need to use a for loop to get them all.
       console.log(geometry.rings);  //<-- array of coords. 

      map.graphics.add(graphic);

      // simplify polygon so it can be used in the get label points request
      geometryService.simplify([geometry], getLabelPoints);
    }
GeorgeCastell
New Contributor

Thank you very much, I'll try.

0 Kudos