Because there are many types of overlays in a map, because of an overlay (which is generally custom), only one occurrence is allowed throughout the map
The first thing to think about is that each time you create this type of overlay, clear this type of covering, a simple way to judge the type of cover instanceof, part of the code is as follows (red code is the focus):
Poimarker.prototype =NewBmap.overlay (); PoiMarker.prototype.initialize=function(map) { This. _map =map; Const DIV= This. _div = document.createelement ("div"); Div.style.zIndex= BMap.Overlay.getZIndex (500); Div.style.position= "Absolute"; Div.style.background= "url (http://s.xxx.com/images/bcg-green.png) no-repeat Bottom"; Div.style.cursor= "Pointer"; Div.style.height= "42px"; Const IMG= Document.createelement ("img"); IMG.SRC= This. _img Div.style.zIndex= BMap.Overlay.getZIndex (400); Img.style.height= "36PX"; Img.style.width= "36PX"; Img.style.borderRadius= "26PX"; Img.style.border= "2px solid #72b80a"; Div.appendchild (IMG); //POI Click eventDiv.onclick = (e) = = { //Suppress event bubblingConst Oevent = e | |event; Oevent.cancelbubble=true; //Delete other Poiinfowindowmarker //get all the overlays on the map Const Alloverlay = This._map.getoverlays (); For (const item of Alloverlay) {if (item instanceof Poiinfowindowmarker) { this . _map.removeoverlay (item); }} Const Poiinfowindowmarker=NewPoiinfowindowmarker ( This. _point, This. _img); //Add a node number overlay to the map (and register the overlay) This. _map.addoverlay (Poiinfowindowmarker); }; Map.getpanes (). Labelpane.appendchild (Div); returnDiv; }; PoiMarker.prototype.draw=function() {const map= This. _map; Const Pixel= Map.pointtooverlaypixel ( This. _point); This. _div.style.left = (pixel.x-18) + "px"; This. _div.style.top = (pixel.y-40) + "px"; }; This. Poimarker = Poimarker
Comes with a GIF plot:
Baidu Map gives the content of the label according to the comparison after deleting the overlay (not quite fit my needs of the scene)
Http://lbsyun.baidu.com/jsdemo.htm#c1_17
function Deletepoint () { var alloverlay = map.getoverlays (); for (var i = 0; i < alloverlay.length-1; i++) { if(Alloverlay[i].getlabel (). Content = = "I am id=1") { map.removeoverlay (alloverlay[i]); return false ; } } }
Baidu map JavaScript How to clear the specified type of overlay