在Google地图上激活drawingManager时如何捕获“点击”事件

时间:2019-05-13 13:20:06

标签: google-maps google-maps-api-3

我想在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

0 个答案:

没有答案