[GIS] Calculate distance and surface with mapbox api

javascriptmapbox

Is there a way to draw lines and polygons (with geojson) and calculate distance and polygon surface with the mapbox api or leaflet?
I wish to have the same tools as in geojson.io with the extra ability to calculate line length and polygon surface.
For lines I will use the Leaflet method distanceTo but for the polygon surface I have no clue.

Best Answer

Lines and polygons can be drawn in Leaflet either by the user of the application with Leaflet Draw

Or programmatically, with geojson - or other leaflet or mapbox classes

For distances and length you might look into Leaflet GeometryUtil

And you can calculate the area of a polygon with geojson-area