一、定位中心点:
1、有动画效果 滑动 飞翔
let point = new BMapGL.Point(lng, lat)
map.flyTo(
point, // 中心点
19, // 缩放等级
{
tilt: 50, // 设置地图倾斜角
heading: 18 // 调整地图方向
})
2、静态定位 无动画
let center = new BMapGL.Point(lng, lat)
map.centerAndZoom(center, 8)
map.setTilt(50) // 设置地图初始倾斜角
map.setHeading(18) // 调整地图方向
map.setMapStyleV2({ // 设置地图风格主题
styleId: '自己调的主题key'
})
二、销毁地图:
if (map) {
map.destroy()
map = null
}
三、删除地图marker标注点:
// 1、一次性删除所有
map.clearOverlays();
// 2、、
const allOverlay = map.getOverlays();
allOverlay.forEach((item, index) => {
if (item.iconType) {
console.log(item, 'item')
} else {
state.map.removeOverlay(item);
}
})
四、marker 标注相关:
const icon = new URL('@/路径.png', import.meta.url).href // 引用图标
const point = new BMapGL.Point(lng,lat)
// 创建标注
const marker = new BMapGL.Marker(point, { icon,
type: 'marker1' ,// 设置marker类型
offset: new BMapGL.Size(0, 12) // 设置偏移位置
})
const label = new BMapGL.Label("<p>测试</p>", { offset });
const imgLabel = new URL('@/label.png', import.meta.url).href //引用图标
label.setStyle({
fontSize: '12px',
background: "url(" + imgLabel + ") no-repeat center center",
width: '300px',
height: '300px',
padding: '10px 24px',
lineHeight: '26px',
color: '#fff',
border: 'none',
boxSizing: 'border-box'
})
marker['_myLabel'] = label; // 添加类型标识 等同于 type: 'marker1'的设置
marker.setLabel(label);
marker.setTop(); // 类似于z-index
// 动态设置icon 常用于点击事件 改变当前图标
marker.setIcon(new BMapGL.Icon(activeIcon, new BMapGL.Size(20, 50)))
map.addOverlay(marker)
五、寄语:
嗨,我在乎的人,工作再忙,也要记得吃饭;事情再多,也尽量别熬夜;有空就出去走一走,锻炼一下身体。只有保持良好的身体状态,才能有精力去追求梦想,去享受生活。
当你学会了照顾好自己,才会更懂得如何去关爱他人。你以最好的状态出现在你爱的人面前,就是对他们最好的报答。
嗨,我在乎的人,照顾好自己这件事上,请你不遗余力。你的身体健健康康,心情快乐舒畅,爱你的人才会安心。