// import loadBMap from '@/utils/loadBMap.js' // 具体代码看百度聚合
initMapc() {
let that = this
loadBMap(that.baiduMapKey).then(() => {
map = new BMap.Map('mapContainer')
const centerPoint = new BMap.Point(this.longitude, this.latitude)
map.centerAndZoom(centerPoint, this.zoom)
// 创建标记
var isDragging = false;
var timer = null;
marker = new BMap.Marker(centerPoint);
// 将标记添加到地图中
map.addOverlay(marker);
// map.panTo(position.point, 15) //让指定位置移动到地图中心
// 监听地图拖动事件
var isDragging = false;
var timer = null;
map.addEventListener('dragend', () => {
isDragging = true;
// 如果已经设置了一个定时器,则清除它
if (timer) {
clearTimeout(timer);
}
// 创建一个新的定时器,延迟一段时间后执行
timer = setTimeout(function() {
if (isDragging) {
// 如果仍然处于拖动状态,则认为拖动已经停止
isDragging = false;
const newCenter = map.getCenter();
marker.setPosition(newCenter); // 更新标记点位置
console.log(newCenter)
// console.log(newCenter.lng )
that.latitude = newCenter.lat
that.longitude = newCenter.lng
}
}, 300); // 设置延迟时间,单位为毫秒
});
})
},
09-21
2541
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-13
4160
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-05
2173
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-07
1283
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-29
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交