4
votes

There are some event listeners like mouseover, mouseout and click to use on the Google Map, but is there an event that respond when a user pan or zoom the map?

EDIT:

I used the 'center_changed', but this didn't work the way I was hoping! If I move the mouse above the map and then pan the map the event is acitvated, but the event is activated all the time, even when I'm not use pan, just move the mouse cursor on the map. The mouse cursor is a fist, not a hand, all the time!? What is wrong?

2
Maybe idle event can resolve your problem. Check here: developers.google.com/maps/documentation/javascript/…Engineer
2 and a bit years later.. :-) I used dragend event to do something similar.Ads

2 Answers

14
votes

Yes, there are.

pan  -> 'center_changed'
zoom -> 'zoom_changed'
2
votes

You can use the mousedown and mouseup events to keep track of whether the mouse is being used to pan the map. If the mouse is not down, then a center_changed event originates from the user clicking the pan button:

//only reload on center_changed if the mouse is not down. This is equivalent to panning
this.addListener("center_changed", function() {
    if (!this.mouseDown) {
        //user has clicked the pan button
    }            
});

this.addListener("mouseup", function() {
    this.mouseDown = false;
});

this.addListener("mousedown", function() {
    this.mouseDown = true;
});