gpt4 book ai didi

javascript - Leaflet:是否有像 panTo 或 setView 这样的方法在缩小或放大时不居中

转载 作者:行者123 更新时间:2023-11-30 19:06:18 25 4
gpt4 key购买 nike

我有一个 zoomend 函数,在它里面,是一个 if else 缩放值,我使用 panTo 或 setView 来缩放 latlng。但我不想在缩小时将其居中?

findMapNo(no).map.on("zoomend", function (e) {
zoom = this.getZoom();
console.log("zoomValue:",zoom);
var diff = Oldzoom - zoom;

if(diff > 0 || diff < 0){
//console.log('zoomed out');
findMapNo(no).map.removeLayer(markersLayer);
findMapNo(no).map.addLayer(markersCluster);
findMapNo(no).map.closePopup(popup);

diff = 0;
} else if(diff == 0){
//console.log('no change');
findMapNo(no).map.removeLayer(markersCluster);
findMapNo(no).map.addLayer(markersLayer);
findMapNo(no).map.panTo(latLng);
findMapNo(no).map.openPopup(popup);
}
findMapNo(no).map.panTo(latLng);
});

最佳答案

将您的代码更新为:

findMapNo(no).on("zoomend", function (e) {
zoom = this.getZoom();
console.log("zoomValue:",zoom);
var diff = Oldzoom - zoom;

if(diff > 0 || diff < 0){
if(diff > 0){
console.log('zoomed out');
}else{
console.log('zoomed in');
findMapNo(no).map.panTo(latLng);
}
findMapNo(no).map.removeLayer(markersLayer);
findMapNo(no).map.addLayer(markersCluster);
findMapNo(no).map.closePopup(popup);
} else if(diff == 0){
console.log('no change');
findMapNo(no).map.removeLayer(markersCluster);
findMapNo(no).map.addLayer(markersLayer);
findMapNo(no).map.panTo(latLng);
findMapNo(no).map.openPopup(popup);
}
// I don't know if you do this elsewhere
Oldzoom = zoom;
});

如果您不想让 map 居中,请不要使用 panTo 或 setView。当您不想将 map 居中时,为什么要设置 latlng?

关于javascript - Leaflet:是否有像 panTo 或 setView 这样的方法在缩小或放大时不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58951180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com