javascript-使用传单获取geojson大陆/国家/州的中心

有没有一种方法可以找到由多个多边形对象组成的国家/地区的中心(例如美国,加拿大,除主要陆地部分外还有其他岛屿)?我试图使用传单的Layer.getCenter()甚至Layer.getBounds().getCenter(),但这些方法对于此类国家/地区当然不起作用,并返回“ no-go”结果.

通过以下链接(传单游乐场)可以看到示例.只需滚动并单击美国或加拿大,然后查看circleMarker出现的位置.然后尝试点击较小的实体,例如美国南部的一些岛屿,它们会将这个标记精确地放置在’em’的中心:

http://playground-leaflet.rhcloud.com/voyi/1/edit?html,output

解决方法:

传单只能计算要素边界框的中心.在其他库(例如Turf.js)的帮助下,您可以计算多边形或(multipolygon)的centroid.

无论如何,您会感到困惑,因为有时质心不在多边形(或多面体)内:

http://postgis.net/docs/images/st_centroid03.png

(图1.根据PostGIS’s ST_Centroid documentation的多边形质心)

所以我想您真正想问的是:

Given a polygon or multipolygon, how can I calculate a center (or center-like point) which is guaranteed to be within the polygon and looks visually in the center of it, in order to add symbolizers to that point with Leaflet?

为此,答案是“pole of inaccessibility”(由polylabel实现):“距多边形轮廓最远的内部点”.

上一篇:vue中视频标点


下一篇:Open CV系列学习笔记(二十三)分水岭算法2021-02-15