Baidu Map API deletes the specified overlay Marker

Part of the idea code:

1. Add a covering Marker to the map. Pay attention to setting a unique representation for the marker. I use the id passed from the backend here.

const point = new BMap.Point(item.lng, item.lat)
const marker = new BMap.Marker(point)
marker.id = item.number
this.map.addOverlay(marker)

2. Obtain all overlays on the map according to the getOverlays() method, and determine whether the id of the overlay is consistent with the id that needs to be deleted. If so, delete the specified overlay through removeOverlay().

// 移除地图覆盖点
removeOverlay(lng, lat) {
    
    
  const allOverlays = this.map.getOverlays()
  for (let i = 0; i < allOverlays.length; i++) {
    
    
    if (allOverlays[i].id && allOverlays[i].id === this.rowData.id) {
    
    
      this.map.removeOverlay(allOverlays[i])
    }
  }
}

Guess you like

Origin blog.csdn.net/qq_43651168/article/details/127801930