Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pan event for Google Maps?

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?

like image 781
3D-kreativ Avatar asked Dec 04 '22 17:12

3D-kreativ


2 Answers

Yes, there are.

pan  -> 'center_changed'
zoom -> 'zoom_changed'
like image 176
Engineer Avatar answered Dec 24 '22 22:12

Engineer


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;
});
like image 44
John Atwood Avatar answered Dec 24 '22 21:12

John Atwood