# L.Geometryutil – How To Calculate Area Of Polygon Using Leaflet

var area = L.GeometryUtil.geodesicArea(layer.getLatLngs());In your example, you are trying to access a control itself, which is what the variable createPolygon is assigned to. Instead, you want to take the area of the layer that got drawn.

Đang xem: L.geometryutil

map.on(“draw:created”, function (e) { var type = e.layerType, layer = e.layer; if (type === “polygon”) { polygons.addLayer(layer); var seeArea = L.GeometryUtil.geodesicArea(layer.getLatLngs()); console.log(seeArea); }}Once you verify you are getting the area, you can just assign it to the variables that populate the table next to the map.

Note: area will be in squareMeters by default

I found that none of the above answers worked for calculating the area of non-contiguous polygons. Here”s an example polygon where the above functions returned an area of 0:

For anyone who needs to do that, here is the code that worked for me (using the L.GeometryUtil function from Leaflet.draw):

var poly = // Your polygon layer here; may or may not be contiguousvar area = 0;for (island of poly.getLatLngs()) { // If the polygon is non-contiguous, access the island if (island.length

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.

Xem thêm:

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

See also  Fsa Geometry Eoc Study Guide S), Fsa Geometry Eoc Review

## Related

Android – Is there a way to use Userscripts / Greasemonkey Scripts on the Android Browser or Dolphin HD?Android – Is there a way to use PC browser bookmarklets with the Android Browser or Dolphin HD?Drupal – Why does js click function run multiple times?Drupal – Get current language of Drupal 8 in javascript?Drupal – How to load content in a div with ajax?Drupal – Loading a library only for the front pageDrupal – How can I create a node via ajax call?Drupal – How do I include JavaScript on a single page in a way that is amenable to scaleDrupal – How do I get a module path?Drupal – What version of jQuery does Drupal 8 use?

### Recent Posts

How to combine two windows as one in Terminal? Do certificates need to be stored as encrypted? Volume password challenge in Migration AssistantCrystal URI.reserved?Crystal OptionParser#banner= example