I am trying to get polygon points as Lat and Long coordinates, but cannot find doco that explains how.
this is how far i got to:
var polygonGeo = graphicGeometry as Polygon;
console.log(polygonGeo.rings.toString());
for (var i = 0; i < polygonGeo.rings.length; i++) {
for (var p = 0; p < polygonGeo.rings[i].length; p++) {
var LatLon = String(polygonGeo.rings[i][p]);
console.log(LatLon);
}
}
All this does it outputs it as:
16816274.629485022,-4041754.114785292,16822695.33986097,-4041754.114785292,16822695.33986097,-4045050.461630086,16816274.629485022,-4045050.461630086
How can i get to convert it to Lat and Long?
Solved! Go to Solution.
Something like this
Also do not forget to add WebmercatorUtils on your require statements and function statements
for (var i = 0; i < gra.geometry.rings.length; i++) { for (var p = 0; p < gra.geometry.rings[i].length; p++) { var pnt = gra.geometry.getPoint(i, p); crmLatitude = String(pnt.latitude); crmLongitude = String(pnt.longitude); var LatLon = String(pnt); console.log(LatLon); console.log(crmLatitude); console.log(crmLongitude); latlon = LatLon; }
Hi @Aeseir , remember, you are drawing a polygon and a polygon has multiple vertices, to this output is a longitude and latitude of each vertex (corner). You can try using WebmercatorUtils to convert the geometry to Geographic .
What would this look like for this example then?
Something like this
Also do not forget to add WebmercatorUtils on your require statements and function statements
for (var i = 0; i < gra.geometry.rings.length; i++) { for (var p = 0; p < gra.geometry.rings[i].length; p++) { var pnt = gra.geometry.getPoint(i, p); crmLatitude = String(pnt.latitude); crmLongitude = String(pnt.longitude); var LatLon = String(pnt); console.log(LatLon); console.log(crmLatitude); console.log(crmLongitude); latlon = LatLon; }
Interesting approach, any advice on how to reverse the process?
I just discovered webMercatorUtils.xyToLngLat as well
I have a utility that might help too if you don't want to manually pull vertices out, will convert polygons to points you can pull lat/lon off too. https://github.com/odoe/explode