如何使用Leaflet.Draw GeometryUtil计算多边形的面积 [英] how to calculate area of polygon using Leaflet.Draw GeometryUtil
本文介绍了如何使用Leaflet.Draw GeometryUtil计算多边形的面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于如何计算多边形的面积,我阅读了此答案,我正在尝试实现相同的效果.但是,该区域的值始终为0(零).
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小提琴位于此处. 我的代码的关键是:
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
我始终在控制台上获得area is: 0
.
I consistently get area is: 0
on the console.
推荐答案
您应该添加.getLatLngs()
参见此小提琴
L.GeometryUtil.geodesicArea(polygon.getLatLngs()));
这篇关于如何使用Leaflet.Draw GeometryUtil计算多边形的面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文