获取传单中图层的标记数 [英] Getting the count of markers in a layer in leaflet

查看:81
本文介绍了获取传单中图层的标记数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Leaflet地图,其中包含一个称为flickrpics的图层,该图层基于当前地图视图的bbox动态加载到geojson中.我想简单地计算该图层中标记的数量,以便可以将其显示在图层控件中的图层标签旁边.我已经尝试过flickrpics.length之类的东西,但是它是未定义的.

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.

道歉,对Leaflet和javascript来说还很新!

Apologies, pretty new to Leaflet and javascript!

推荐答案

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

从LayerGroup继承的方法:

Methods inherited from LayerGroup:

getLayers()图层[]

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;

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

这篇关于获取传单中图层的标记数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆