- 首先初始化地图时,需要初始化设置地图绘制方式 drawer
this.Map = new BMap.Map(this.$refs.map, {
drawMargin: 100,
drawer: BMAP_SVG_DRAWER_FIRST,
});
- 监听地图touseend方法,并且给覆盖物图层添加自定义事件
this.Map.addEventListener("touchmove", function (e) {
that.Map.enableDragging();
});
this.Map.addEventListener("touchend", function (e) {
that.Map.disableDragging();
if (e.overlay && e.overlay.customClickHandler_) {
e.overlay.customClickHandler_.call(e.overlay, e);
}
});
- 绘制多边形,并且实现多边形的点击事件
let polygon = new BMap.Polygon(points, {
strokeColor: "blue",
strokeWeight: 2,
strokeOpacity: 0.5,
fillOpacity: 0.5,
});
this.Map.addOverlay(polygon);
polygon.customClickHandler_ = function (e) {
console.log(e);
that.highlightPolygon(polygon);
};