return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Getting the count of markers in a layer in leaflet - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting the count of markers in a layer in leaflet - Stack Overflow

programmeradmin2浏览0评论

I have a Leaflet map with a layer called flickrpics that is loaded dynamically in geojson based on the bbox of the current map view. I would like to get a simple count of the number of markers in that layer, so that I can display it next to the layer label in the layer control. I've tried things like flickrpics.length but it's saying undefined.

Apologies, pretty new to Leaflet and javascript!

I have a Leaflet map with a layer called flickrpics that is loaded dynamically in geojson based on the bbox of the current map view. I would like to get a simple count of the number of markers in that layer, so that I can display it next to the layer label in the layer control. I've tried things like flickrpics.length but it's saying undefined.

Apologies, pretty new to Leaflet and javascript!

Share Improve this question asked Sep 1, 2014 at 8:09 jamesinealingjamesinealing 5928 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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./examples/geojson.html for more information.

Reference: https://leafletjs./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;

发布评论

评论列表(0)

  1. 暂无评论