Getting the count of markers in a layer in leaflet

柔情痞子 提交于 2019-12-06 10:47:54

Reference: https://leafletjs.com/reference-1.3.4.html#geojson

Methods inherited from LayerGroup:

getLayers() Layer[]

Returns an array of all the layers added to the group.

var pins = L.geoJson(geojsonFeature, {}).addTo(map); var totalPins = pins.getLayers().length;

If you are using L.geoJson for geoJSON loading, you can use the onEachFeature to count the number of objects in the geoJSON layer. Something like:

var counter = 0;

function onEachFeature(feature, layer) {
counter++;
}

L.geoJson(geojsonFeature, {
onEachFeature: onEachFeature
}).addTo(map);

See http://leafletjs.com/examples/geojson.html for more information.

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