【发布时间】:2021-12-30 19:14:19
【问题描述】:
我有一个网站,上面有一张地图,上面有不同景点的标记。我正在使用下面完美运行的 js 代码:
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <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);
}
但是当我尝试使用下面的代码为每个标记添加一个弹出窗口时,整个地图向左移动,不再以 setView 定义的初始位置为中心:
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();
}
知道发生了什么以及解决问题的最佳方法吗? 提前谢谢你。
【问题讨论】:
标签: javascript dictionary leaflet