leafletjs - marker.bindPopup - keep all popups open(Leafletjs - marker.bindPopup - 保持所有弹出窗口打开)
问题描述
我在使用传单打开所有弹出窗口时遇到了一些困难.
I am having some difficulty keeping all the popups open with leaflet.
我在 a 循环中有以下代码,用于向 LayerGroup 添加标记(ajax 自动更新).
I have the following code in the a loop to add markers to a LayerGroup (ajax auto-updating).
var marker = L.marker([value.position.lat, value.position.lon],options).addTo(markers);
allpoints.push([value.position.lat, value.position.lon]);
marker.bindPopup("InfoWindow",{closeOnClick:false,closeButton:false}).openPopup();
它工作得很好,除了它只保持最后一个弹出窗口打开.我想保持所有这些开放.我确实在这里(stackoverflow)上找到了一篇关于使用不同标记名称这样做的文章,但是我有这个循环.我确实尝试将 L.marker 放入数组中,但传单不喜欢那样.
It works great, except it only keeps the last popup open. I would like to keep all of them open. I did find an article on here (stackoverflow) regarding doing so with different marker names, however I have this in a loop. I did try putting L.marker into an array, but leaflet did not like that.
有什么想法吗?
推荐答案
你需要重写 Leaflet Map 上的 openpopup 方法,用这个方法的副本替换它,只注释掉调用 this.closePopup();
You will need to override the openpopup method on the Leaflet Map, replacing it with a copy of this method, only comment out the line that calls this.closePopup();
在您的页面上添加
L.Map = L.Map.extend({
openPopup: function (popup, latlng, options) {
if (!(popup instanceof L.Popup)) {
var content = popup;
popup = new L.Popup(options).setContent(content);
}
if (latlng) {
popup.setLatLng(latlng);
}
if (this.hasLayer(popup)) {
return this;
}
// NOTE THIS LINE : COMMENTING OUT THE CLOSEPOPUP CALL
//this.closePopup();
this._popup = popup;
return this.addLayer(popup);
}
});
http://jsfiddle.net/yVLJf/37/
您可以在此处找到原始 Leaflet openPopup 方法:https://github.com/Leaflet/Leaflet/blob/1acffc5a3d31010b7d613382ab2a5830ecee5dd5/src/layer/Popup.js#L290
You can find the original Leaflet openPopup method here: https://github.com/Leaflet/Leaflet/blob/1acffc5a3d31010b7d613382ab2a5830ecee5dd5/src/layer/Popup.js#L290
这篇关于Leafletjs - marker.bindPopup - 保持所有弹出窗口打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Leafletjs - marker.bindPopup - 保持所有弹出窗口打开
基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01