我想在Google地图中通过click
创建的每个多边形上添加一个DrawingManager
事件。但是它们不会被DrawingManager
代码如下:
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 3,
maxZoom: 8,
minZoom: 2,
center: {
lat: 0,
lng: -180
},
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYGON,
drawingControl: false
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
const shape = event.overlay;
console.log(event.overlay);
google.maps.event.addListener(shape, 'click', event => {
console.log(event);
event.stopPropagation();
});
});
这里是代码的link。