how to calculate area of polygon using Leaflet.Draw GeometryUtil

对着背影说爱祢 提交于 2020-07-10 08:09:07

问题


I read this answer on how to calculate the area of a polygon and I am trying to achieve the same. However, I consistently get 0 (zero) for the area.

JS fiddle is here. The crux of my code is:

var map = L.map('map').setView([19.04469, 72.9258], 12).addLayer(osm);
var latlngs = [[19.04469, 72.9258], [19.07459, 72.9358], [19.08469, 72.4758]];
var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
console.log('area is: '+L.GeometryUtil.geodesi

I consistently get area is: 0 on the console.


回答1:


You should add .getLatLngs() see this fiddle

L.GeometryUtil.geodesicArea(polygon.getLatLngs()));


来源:https://stackoverflow.com/questions/60827549/how-to-calculate-area-of-polygon-using-leaflet-draw-geometryutil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!