Capture events in custom Overlays

3,006 views
Skip to first unread message

Geoff

unread,
Nov 16, 2009, 8:18:02 AM11/16/09
to Google Maps JavaScript API v3
How do you capture events in custom overlays and stop them from
propagating to the map? For example I would like to select the "Hello
world!" text in this demo gallery example and a click and drag moves
the map rather than selecting the text. I appreciate any pointers.

http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow_custom/infowindow-custom.html

Susannah (Google Employee)

unread,
Nov 24, 2009, 1:19:16 AM11/24/09
to Google Maps JavaScript API v3
Hi Geoff,

This should cancel the event clicks for you. I'll work on updating
the demo to include event cancelling.

function cancelEvent(e) {
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}

google.maps.event.addDomListener(div, 'mousedown', cancelEvent); //
cancels drag/click
google.maps.event.addDomListener(div, 'click',
cancelEvent); // cancels click
google.maps.event.addDomListener(div, 'dblclick',
cancelEvent); // cancels double click
google.maps.event.addDomListener(div, 'contextmenu', cancelEvent); //
cancels double right click

(where div is the custom overlay)

Hope this helps,
Susannah

Esa

unread,
Nov 24, 2009, 7:11:24 AM11/24/09
to Google Maps JavaScript API v3
I thought that IE returns the event by window.event

function cancelEvent(e) {
var e = e || window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();
}

Hopefully my information is ancient.

Ben Appleton

unread,
Nov 24, 2009, 5:03:34 PM11/24/09
to google-map...@googlegroups.com

Correct, but the API hides this from you in .addDomListener

-- You received this message because you are subscribed to the Google Groups "Google Maps JavaScri...

Reply all
Reply to author
Forward
0 new messages