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

本文介绍了如何在Vue项目中利用百度地图API创建并删除特定类型的覆盖物,例如PoiMarker。通过实例化覆盖物,监听点击事件,并在点击时遍历地图上的所有覆盖物,删除非目标覆盖物,实现对地图上指定覆盖物的管理。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值