【问题标题】:google maps : want to add/remove GEvent Listener to map谷歌地图:想要添加/删除 GEvent 监听器到地图
【发布时间】:2009-06-02 13:36:08
【问题描述】:

我想为 Google 地图添加和删除相同的事件。

因为我在地图上的“moveend”事件上附加了一个监听器,所以事件会打开一个大的 infoWindow,然后也会发生“moveend”事件,我不想为这件事运行。 知道如何打开和关闭“moveend”事件监听器吗?

【问题讨论】:

  • 为了将来参考,可以通过包含显示您当前拥有的特定源代码来改进这个问题。

标签: google-maps


【解决方案1】:

您可以删除事件侦听器,但您必须传递添加时返回的确切侦听器。

例如

//add moveend listener
var moveendListener = GEvent.addListener(source, "moveend", yourfunction);

//remove moveend listener
GEvent.removeListener(moveendListener);

//remove all listeners associated with an event
GEvent.clearListeners(source, "moveend") ;

编辑:另一种选择是让监听器调用的函数在不同条件下表现不同。

例如

function moveendHandler() {
    if (isWhateverActive()) return;

    //code to run if whatever is not active
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    相关资源
    最近更新 更多