bounds_changed vs. dragend

428 views
Skip to first unread message

Cameron F

unread,
Sep 12, 2009, 4:38:19 PM9/12/09
to Google Maps JavaScript API v3
Do these events fire with deterministic behavior? In other words,
does the last bounds_changed event reliably happen after the dragend?
I'm seeing weird behavior where the bounds I'm getting by doing a
get_bounds in my dragend handler aren't the actual bounds of the
screen about 5% of the time. (If it were more deterministic, and I
wasn't having the other issue I'm working on then I would post the
sample). I was thinking about sitting on bounds_changed instead of
dragend, but then of course I'm firing all the time while people are
dragging the map. If I know that one event fired later reliably, then
I could try to code around the problem I'm seeing.

Esa

unread,
Sep 12, 2009, 5:14:05 PM9/12/09
to Google Maps JavaScript API v3


On Sep 12, 11:38 pm, Cameron F wrote:

> does the last bounds_changed event reliably happen after the dragend?

It seems to me that it is just the opposite, but not reliably. It is
not a good idea to trust in order of events. The order is not
documented and it may change.

Esa

unread,
Sep 12, 2009, 6:11:32 PM9/12/09
to Google Maps JavaScript API v3
dragend is triggered when user releases the mouse button. It would be
a good event for server request. However it is not triggered when zoom
setting is changed. There is 'zoom_changed' event but it is not
triggered if zoom is changed by scrollwheel or dblclick. I think it
should be triggered. It might be a good idea to report that.

So it seems that you have to choose 'bounds_changed' and filter the
repeating requests by a delay.


google.maps.event.addListener(map, 'bounds_changed', function(){
function finished(){
google.maps.event.trigger(map, 'moveend');
}
clearTimeout(this.timeout);
this.timeout = setTimeout(finished, 200);
});

A series of 'bounds_changed' triggers a single 'moveend' 200 ms after
last 'bounds_changed'.
Reply all
Reply to author
Forward
0 new messages