Any idea how to get the Circumference length of the shapes in a layer in MapBox/Leaflet.js? I managed to get the area using this example (even though it is sometimes negative!?). It does not have circumference/perimeter though.
Thanks!
Any idea how to get the Circumference length of the shapes in a layer in MapBox/Leaflet.js? I managed to get the area using this example (even though it is sometimes negative!?). It does not have circumference/perimeter though.
Thanks!
For
L.Circle
you can calculate the circumference from it's radius:For
L.Polyline
you'll need to sum the distances between theL.LatLng
objects:For
L.Polygon
which is extended fromL.Polyline
you call the length function ofL.Polyline
and add the distance between the first and lastL.LatLng
objects:Thanks for the answers and comments. Seems like turf.js is the way to go, as suggested by @ghybs. It still requires some coding for anything that's not a LineString, but at least the algorithms are efficient.