How to get the area string from a polygon using leaflet.draw

后端 未结 4 1533
温柔的废话
温柔的废话 2020-12-18 21:58

I am trying to get the area measurements of polygons so I can list them in a table to the side of the map, next to the name of the polygon. This is what I have tried with n

4条回答
  •  攒了一身酷
    2020-12-18 22:07

    L.GeometryUtil.geodesicArea(layer.getLatLngs())[0] should get you the area.

    But I ended up using leaflet-geoman-free to do the drawing and use turf.js to get the area.

    map.pm.enableDraw('Polygon', {
       snappable: true,
       snapDistance: 20,
    });
    
    map.on('pm:create', e => {
       const layer = e.layer
       alert(turf.area(layer.toGeoJSON()))
    });
    

提交回复
热议问题