setCenter and panBy dont work in zoom_changed handler

498 views
Skip to first unread message

Ivan Abragimovich

unread,
Sep 13, 2010, 10:48:47 AM9/13/10
to Google Maps JavaScript API v3
Hi, all.
I found strange behavior of 'setCenter' and 'panBy' function.
When i add event handler to 'zoom_changed' event, something like this:

google.maps.event.addListener(map, 'zoom_changed', function() {
map.panBy(300, 300);
});

Code above doesn't work.
But if I use 'setTimeout' function like this:

google.maps.event.addListener(map, 'zoom_changed', function() {
setTimeout(moveMap, 10);
});

function moveMap() {
map.panBy(300, 300);
}

This code works fine.
Could anybody explain me, why first code snippet doesn't work?

P.S. Sorry for my terrible English.

Rossko

unread,
Sep 13, 2010, 12:12:58 PM9/13/10
to Google Maps JavaScript API v3
> Could anybody explain me, why first code snippet doesn't work?

Lots of things happen asynchronously in v3.
Using a short setTimeout puts your code in the execution queue behind
map workings, rather than getting executed immediately ahead of the
map workings associated with whatever caused the zoom change.

Ivan Abragimovich

unread,
Sep 13, 2010, 1:10:01 PM9/13/10
to Google Maps JavaScript API v3
Thank you for explanation:)

Of course it's very pure, but it's enough.

Ela

unread,
Sep 13, 2010, 2:26:43 PM9/13/10
to Google Maps JavaScript API v3
use the idle event instead of zoom_changed, this works perfectly for
me (without timeouts...)
Reply all
Reply to author
Forward
0 new messages