popup - 打开地图上可见的所有标记的弹出窗口,缩放 > 10
问题描述
我需要在 Zoom, 10 处打开地图上可见的所有标记。我还使用 Leaflet.markercluster。
初始化地图:
initMap() {
this.map = L.map('map', {
center: [55.55, 37.61],
zoom: 9,
layers: this.layer
})
this.tileLayer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution:
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, ©'
})
this.tileLayer.addTo(this.map)
this.map.on('zoom', function(ev) {
???
})
添加标记层:
this.markerLayer = new L.LayerGroup() // layer contain searched elements
// this.map.addLayer(this.markerLayer)
for (const i in data) {
...
const marker = new L.Marker(new L.latLng(loc), { title: title, icon: icon })// se property searched
marker.bindPopup(title)
this.markerLayer.addLayer(marker)
}
使用传单标记集群:
this.markersLayer = L.markerClusterGroup({
iconCreateFunction: function(cluster) { ... },
singleMarkerMode: false
})
this.markersLayer.addLayer(this.markerLayer)
this.map.addLayer(this.markersLayer)
解决方案
You should add your markers to an array before / after adding them to the map to access them easily.
var markers = [];
for (const i in data) {
const marker = new L.Marker(new L.latLng(loc), { title: title, icon: icon })
marker.bindPopup(title)
this.markerLayer.addLayer(marker)
markers.push(marker);
}
after that you can just loop through your markers array and use openPopUp function of marker to open popups of your markers programmatically.
for(i = 0; i< markers.length;i++){
markers[i].openPopup();
}
推荐阅读
- javascript - 将列表从视图上下文传递到模板并将其分配为模板中的数组
- python-3.x - Python - 线程占用过多的 CPU
- keras - 在给定非文本序列数据的情况下,用于多类分类的 LSTM 的 y-train 的形状应该是什么?
- python - 如何根据列表给出的键获取嵌套字典中的值?
- c - SIMD - AVX - 使用非零值而不是最高位进行掩码
- c++ - 在解压可变参数模板直到运行时条件时避免“递归”函数调用
- android - 将测试应用程序 ID 与 adMob 一起使用时出现无效应用程序 ID 错误
- css - 为什么这个 CSS 代码在我的内盒中溢出,即使它适合我的外盒?
- node.js - 从 mongodb 的嵌套文档数组中删除一条记录
- python - odoo 10 打印 XLSX 报告时访问被拒绝