最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pan event for Google Maps? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Apr 8, 2012 at 6:10 Engineer 48.8k12 gold badges90 silver badges92 bronze badges asked Mar 22, 2012 at 7:32 3D-kreativ3D-kreativ 9,29737 gold badges105 silver badges162 bronze badges 2
  • 2 Maybe idle event can resolve your problem. Check here: developers.google.com/maps/documentation/javascript/… – Engineer Commented Mar 22, 2012 at 8:17
  • 2 and a bit years later.. :-) I used dragend event to do something similar. – Ads Commented Jan 9, 2015 at 6:04
Add a comment  | 

2 Answers 2

Reset to default 16

Yes, there are.

pan  -> 'center_changed'
zoom -> 'zoom_changed'

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;
});
发布评论

评论列表(0)

  1. 暂无评论