1

在覆盖(ExtInfoWindow)上处理 mousedown 事件后,我需要确保地图点击事件处理程序不执行,或者在地图点击事件处理程序中,我需要确定事件来自覆盖点击,而不是处理它。所以,某种方式我不需要处理两次。我在下面做错了什么?它用于 ExtInfoWindow 库,所以我不会在这里发布整个内容。带地图的页面在这里。点击信息窗口。在extinfowindow.js中搜索“console.log”以查看问题所在。

  // Initialization:

  var stealEvents = ['mousedown', 'dblclick', 'DOMMouseScroll', 'onmousewheel'];
  for( i=0; i < stealEvents.length; i++ ){
        google.maps.event.addDomListener(this.container_, stealEvents[i], this.onClick_.bind(this));
  }



    if (map.ClickListener_ == null) {
      //listen for map click, close ExtInfoWindow if open
      map.ClickListener_ = google.maps.event.addListener(map, 'click',
        function(event) {
            if( map.getExtInfoWindow() != null ){
                    // problem: This executes even if the click is on the overlay!
                map.closeExtInfoWindow();
            }
            }
      );
    }


// overlay click event handler
ExtInfoWindow.prototype.onClick_ = function(e) {
   var evt = e ? e:window.event;

   evt.cancelBubble = true;
   evt.returnValue = false;

   if (evt.stopPropagation) {
      evt.stopPropagation();
   }

   if (evt.preventDefault) {
      evt.preventDefault();
   }

   evt.stop(); // from google.maps.MouseEvent

};
4

2 回答 2

3

MouseEvent.stop();在第一个处理程序中执行。IE:

google.maps.event.addListener(myOverlay, 'click', function(mouseEvent){
    mouseEvent.stop();
//Handle the click here
});

有关 MouseEvent,请参阅 Google 地图文档

于 2013-01-18T15:01:40.060 回答
1

没关系... dom 侦听器正在侦听 mousedown 事件而不是单击事件,因此单击不会被取消。我应该让它监听点击事件。

var stealEvents = ['click', 'dblclick', 'DOMMouseScroll', 'onmousewheel'];
for( i=0; i < stealEvents.length; i++ ){
    google.maps.event.addDomListener(this.container_, stealEvents[i], this.onClick_.bind(this));
}
于 2013-02-04T22:59:26.187 回答