簡體   English   中英

如何通過 Leaflet 中的彈出窗口解決此問題

[英]How to solve this problem with pop-ups in Leaflet

我有一個網站,其中包含一個 map 和不同景點的標記。 我正在使用下面完美運行的 js 代碼:

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);
        
//.  t is an array containing gps positions of the different places
for(i=0;i<t.length;i++){
    var marker = L.marker([t[i][lat], t[i][lon]]).addTo(mymap);
}

但是當我嘗試使用下面的代碼為每個標記添加一個彈出窗口時,整個 map 被移到左側,並且不再以 setView 定義的初始 position 為中心:

for(i=0;i<t.length;i++){
    var marker = L.marker([t[i][lat], t[i][lon]]).addTo(mymap);
    marker.bindPopup("<b>mon titre"</b><br>mon texte").openPopup();
}

知道發生了什么以及解決問題的最佳方法嗎? 先感謝您。

我找到了解決方案:問題在於彈出窗口是打開的。 使用以下代碼行有效:

marker.bindPopup("<b>mon titre"</b><br>mon texte").closePopup();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM