leaflet 地图放大的时候固定中心点
可能有些事件禁用一下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const _this = this;
// 在缩放时设置缩放中心
this.map.on("zoom", function () {
const center = _this.center; // 自定义缩放中心点
const zoomLevel = _this.map.getZoom(); // 获取当前缩放级别
_this.map.setView(center, zoomLevel, { animate: true }); // 缩放至指定点
});
// 在点击时围绕点击位置进行缩放
this.map.on("click", function (e) {
const zoomLevel = _this.map.getZoom() + 1; // 增加缩放级别
_this.map.setView(e.latlng, zoomLevel, { animate: true }); // 在点击位置缩放
});
this.map.on("click", (e) => {
const latlng = e.latlng; // 获取点击位置的经纬度
console.log(`Lat: ${latlng.lat}, Lng: ${latlng.lng}`);
});
This post is licensed under CC BY 4.0 by the author.