思路:
一、获取百度地图上已有的标注:
getOverlays()
const makers = this.map.getOverlays();
二、找出point相同的标注
for (let ind = 0; ind < light_list.length; ind++) {const ele = light_list[ind];const point = light_list[ind].point;for (let index = 0; index < makers.length; index++) {const element = makers[index];const lat = element.point && element.point.lat;const lng = element.point && element.point.lng;if (point.lat === lat && point.lng === lng) {this.map.removeOverlay(makers[index]);}}}
三、删除标注:
removeOverlay
this.map.removeOverlay(makers[index]);
四、添加标注;
const marker = new BMap.Marker(point, { icon: myIcon }); // 创建标注this.map.addOverlay(marker);