OverlayView.draw() not called when map.getCenter() changed

345 views
Skip to first unread message

Kegan Gan

unread,
Sep 29, 2009, 8:13:32 PM9/29/09
to Google Maps JavaScript API v3
-----This is a repost from
http://groups.google.com/group/google-maps-api/browse_thread/thread/bbbdd1fd64c799a9/3f0b863fb66690be#3f0b863fb66690be

Hi,

I am creating a custom overlay to show an image in the middle of the
map, that does not moved when the map is zoomed, dragged, etc.

It worked perfectly in Google Map API version 2. The example code is
here (view source) http://junk.kegan.info/gmap/version2.html.

However, using the same method, it does not work in Google Map API
version 3. See example code here (view source) http://junk.kegan.info/gmap/version3.html.

It seems like in version 3, the OverlayView.draw() method is not
called "every time" when the map center changed. To show this, I have
added a 'counter' at the bottom of the page that will increment every
time OverlayView.draw() is called (in version 2, it's GOverlay.redraw
()).

Is this a bug in the API? Or am I doing something wrong?

Susannah (Google Employee)

unread,
Sep 29, 2009, 9:09:24 PM9/29/09
to Google Maps JavaScript API v3
Hi Kegan,

Please star this issue:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=1635

You can force your Overlay to be redrawn when the center changes by
adding this code to your onAdd method:
var overlay = this;
google.maps.event.addListener(overlay.getMap(), 'center_changed',
function() {
overlay.draw();
});

Note that this has potential to make dragging sluggish on some
browsers. For this reason, we only trigger draw when the result from
fromLatLngToDivPixel would change.

Hope this helps!
Susannah
Reply all
Reply to author
Forward
0 new messages