Passed arguments for 'click' event of Markers suddenly changed.

869 views
Skip to first unread message

Steffen

unread,
Mar 5, 2011, 10:35:27 AM3/5/11
to Google Maps JavaScript API v3
I was using since months the click event of a marker for displaying a
custom overlay.
This was easy since the click event passes the native mouse event
which includes the "target" element.

Therefore, something like this was possible:

google.maps.event.addListener(marker, 'click', function (e, info) {
console.log(e.target);
});

This conforms to the documentation, which says the click event gets
passed the "Event".

Suddenly I recognized, that this is not working anymore, but the
documentation still says "Event".
Now, it gets passed the Google Maps "MouseEvent", which just passes
the x and y coordinates of the location of the link.

What is happening?

The rolled back to my code version where I implemented that stuff and
where I'm 100% sure that it worked.
Another project of mine is affected as well, and I haven't changed the
code since the last time I saw it working.


Anybody any ideas??

Thanks!!

bratliff

unread,
Mar 6, 2011, 12:10:40 PM3/6/11
to Google Maps JavaScript API v3
"Click" events are delivered to a CANVAS tile rather than to
individual IMG DOM elements. "this" refers to the entire CANVAS tile.

The event listener must determine which marker of many candidates in
the tile is the intended target. Potentially, it might be more than
one marker or perhaps none. If the marker is circular, distance from
its center could be used. If the marker is irregular, point in poly
analysis could be required.

The event listener model with a separate "function closure" for every
marker is seriously flawed. For a few dozen markers, it may not be
important. For several hundred or several thousand markers, it will
never work. Google will have to offer a central event listener able
to handle many similar markers.

Ben Appleton (Google Employee)

unread,
Mar 6, 2011, 6:14:07 PM3/6/11
to Google Maps JavaScript API v3
Hi Steffen,

I'll take a look. Meanwhile to avoid surprising changes, you can
specify an API version like:
http://maps.googleapis.com/maps/api/js?sensor=false&v=3.3

See the versioning documentation for more details:
http://code.google.com/apis/maps/documentation/javascript/basics.html#Versioning

Cheers
Ben

Steffen

unread,
Mar 6, 2011, 6:14:43 PM3/6/11
to Google Maps JavaScript API v3
A quick additional info, I used e.target to get the position of the
target element and display and align my custom info overlay above the
marker.

Ben Appleton

unread,
Mar 6, 2011, 6:26:30 PM3/6/11
to google-map...@googlegroups.com, Steffen
In v3.4 we've just released fast markers, which are painted into canvas tiles. So e.target will not be a marker DOM element. Instead I'd suggest getting the marker's position and placing your content accordingly.

- Ben


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Reply all
Reply to author
Forward
0 new messages