Select to view content in your preferred language

Saving points while drawing a polygon

812
3
04-23-2013 11:16 AM
RichardDeVita
Emerging Contributor
I downloaded the sample cod: Add graphics to a map
http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/graphics_add.html

I want to save the points (lat and lon)  of a polygon as its being drawn or at "ondrawend"   and get a list of all the points.
Not a free style line drawing,  just a straight line polygon.

In the function addGraphic (geometry)   is there   a way to do this

var points[] =  geometry.getPoints();


I need to save the points to a jsonstore.

Thank You
0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Richard,

You could use the onDrawComplete event to do this.  Ex:

dojo.connect(tb, "onDrawComplete", function(geometry){
            console.log(geometry.geometry.rings);
            });
0 Kudos
RichardDeVita
Emerging Contributor
Thank You.  This is a start. 

ran this
console.log(geometry.rings);

got this
[[[-13459684.212552793, 4676535.610062524], [-13453282.61143392, 4673535.456702335], [-13459588.666267438, 4670917.488483570], 2 more...]

how do I convert these numbers to latitude and longitude ?

Also I drew a triangle,  but I get 5 points ?

Thank You for the help
0 Kudos
JakeSkinner
Esri Esteemed Contributor
If your map's spatial reference is Web Mercator or Geographic, you can use the geographicGeometry property of the onDrawComplete event.  This will return the XY coordinates in lat/long.

console.log(geometry.geographicGeometry.rings);


When creating a triangle you should get 4 points.  The 4th point will be a duplicate of the first point.  When you digitizing, double-click the 3rd point and the triangle will auto-complete.  If you are trying to close the triangle yourself by double-clicking on the 4th point, it will create a 5th point unless you are exactly clicking on the starting point.
0 Kudos