How can I listen for the start of a user drawing a polygon in Google Maps v3?

痞子三分冷 提交于 2019-12-05 18:29:22

I was wrestling with the problem of listening for clicks on the Google Map canvas today, and I may have discovered an ugly hack/workaround using jQuery:

setTimeout( function() {
  var gmDomHackSelect = $('.gm-style').children().eq(0);
  gmDomHackSelect.click(handleMapCanvasClick);
}, 3000);

This fragment of code was from my map initialisation function, so I needed a timer to select the element a little while later.

The advantage of this listener is that it listens for click directly on the canvas, ie. clicks on map controls (eg zoom) do not trigger it.

This won't work because according to docs: Note that google.maps.Map events, such as click and mousemove are disabled while drawing on the map.

That could be also tested setting map event listeners for click, dblclick... events. After activating drawing manager there is no response from those listeners if you click on the map. Drawing manager is intercepting them. Exception is map rightclick event which is still enabled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!