vuebaidumap 删除覆盖物_百度地图JavaScript如何清除指定类型的覆盖物

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:45   1277   0

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点击事件

div.onclick = (e) =>{//禁止事件冒泡

const oEvent = e ||event;

oEvent.cancelBubble= true;//删除其它的 poiInfoWindowMarker

//获取地图上所有的覆盖物

const allOverlay = this._map.getOverlays();

for (const item of allOverlay) {

if (item instanceof PoiInfoWindowMarker) {

this._map.removeOverlay(item);

}

}

const poiInfoWindowMarker= new PoiInfoWindowMarker(this._point, this._img);//添加节点数覆盖物到地图上(并将覆盖物注册)

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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP