jir*_*ovo 4 javascript leaflet leaflet.markercluster
当触发特定事件(clustermouseover或clusterclick)时,我需要在集群内获取标记.我e在开发人员控制台中检查事件对象,但是e.layer._markers是一个空数组.
group_markers.on('clustermouseover', function (e) {
console.log('clustermouseover');
console.log(e);
});
Run Code Online (Sandbox Code Playgroud)
group_markers是L.markerClusterGroup对象.
在此先感谢您的帮助!
使用getAllChildMarkers图层对象(e.layer)的方法.例:
markers.on('clustermouseover', function (e) {
console.log('Number of markers: ' + e.layer.getAllChildMarkers().length);
});
Run Code Online (Sandbox Code Playgroud)
getAllChildMarkers:返回该集群中包含的总标记数组.
下划线(_)通常用于表示对象属性(例如_markers)或方法是私有的.通常,您不希望访问私有对象成员,因为它们只应在内部使用.
边注:
如果您在控制台中搜索事件的属性,请查看layer对象的原型,然后您将找到该getAllChildMarkers方法:
| 归档时间: |
|
| 查看次数: |
1827 次 |
| 最近记录: |