Answer the question
In order to leave comments, you need to log in
How to store polygon coordinates in leaflet?
How to get the coordinates of created polygons in a format like [-145.59082, 81.56997],[-149.80957, 81.4988],[-150.60059, 82.46607],[-146.25, 82.50629]?
or convert from format like "M253 207L450 290L684 178z"
Answer the question
In order to leave comments, you need to log in
polygons are created as objects and can be exported to GeoJSON
var polygon = L.polygon([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]
]).addTo(mymap);
JSON.stringify(polygon.toGeoJSON().geometry.coordinates[0])
""
var a = [];
mymap.eachLayer(l=>'toGeoJSON' in l && a.push(l.toGeoJSON()));
var result = {"type":"FeatureCollection","features":a};
console.log(JSON.stringify(result,"\n",4))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question