Google Map's Double Click Event Propagation

放肆的年华 提交于 2019-11-30 11:21:16
Oliver

UPDATE: Unfortunately, I had to find out that Firefox does not make the current event accessible via window.event thus this code won't work there. I haven't found a workaround for that, yet.


It turns out the fix to your code is minimal: just remove the event parameter from your event handler function, thus accessing the global window.event object inside the handler.

The following example code worked for me in IE and Chrome, but not Firefox:

google.maps.event.addListener(map, "dblclick", function(googleMapsEvent) {
    console.debug("caught double click");
    // reference the global event object
    // ignore the googleMapsEvent passed in by Google Maps!
    event.preventDefault();
});

This answer put me on the right track!

Not a solution but some ideas, as requested ...

event.stopPropagation() is not a generalised panacea for issues of this type for two reasons :

  • your event handler may be responding to an already bubbled event, ie it too late to prevent event handling (zoom in this case) which was triggered earlier in the bubbling cycle.
  • it may not be a bubbling issue but an event being handled by at the same level. .addListener() implements an observer pattern, meaning that new additions are added to the element's "concrete observer" queue without removing any handlers previously added by the same mechanism.

A workaround is almost undoubtedly available for both of these situations but would probably require "inside knowledge" of Google Maps to solve.

Maybe someone else knows more than I.

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