1

我在谷歌地球中使用气球时遇到问题。我在地图上有一些标记,单击标记后,会显示一个包含一些数据的气球弹出窗口,现在当我单击该气球的关闭按钮时,也会触发地图的单击事件,这真的很烦人有一个与地图点击事件相关的处理程序。

我尝试了所有方法,包括在 htmlDivBalloon 的 'beforeclose' 事件中使用 event.stopPropagation() ,但仍然没有任何效果。有人对此有想法吗?

最好的问候约翰·塔德罗斯

4

1 回答 1

0

您可能没有处理默认事件,或者您没有筛选事件在“与地图单击事件相关的”处理程序中作用的对象。您没有显示任何代码,因此很难确切说明如何修复它 - 但处理此问题的通用方法如下。

// listen for mousedown on the window 
google.earth.addEventListener(ge.getWindow(), 'mousedown', function(e) {
  var type = e.getTarget().getType();
  if (type == 'KmlPlacemark') {
    // prevent the default event for placemarks, stop Propagation
    e.preventDefault();
    e.stopPropagation();
  } else if(type == 'GEGlobe') {
    // do something with the globe...
  }
  // etc...
});
于 2011-12-18T01:08:54.157 回答