谷歌地图和活动

发布于 2024-11-09 14:53:43 字数 869 浏览 0 评论 0原文

我正在尝试提供一种功能,可以将鼠标悬停在标记上和鼠标移开,然后弹出信息窗口并自动关闭它。然后,当用户单击标记时,我会禁用该标记的鼠标移出以显示信息窗口,直到用户手动将其关闭。当用户单击信息窗口的关闭时,我想将鼠标移出添加回标记。

我有这样的代码:

google.maps.event.addListener(marker, 'mouseover', function() {
    infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'mouseout', function() {
    //setTimeout(function() { infowindow.close(); }, 3000);
    infowindow.close(map, marker);
});
google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map, marker);            
    google.maps.event.clearListeners(marker, 'mouseout');
});

我正在尝试使用“单击”事件来禁用“鼠标悬停”。以上有效。现在我想在使用下面的“closeclick”关闭信息窗口后添加回“mouseout”事件。

google.maps.event.addListener(infowindow, 'closeclick', function() {
    //google.maps.event.addListener(marker, 'mouseout', "");
});

我不知道该怎么做。有人能指出我正确的方向吗?

I'm trying to have the functionality to where I can mouseover and mouseout on markers and pop the infowindow up and auto close it. Then when a user clicks on a marker I disable the mouseout for that marker to display the infowindow until the user manually closes it. I want to add the mouseout back to the marker when the user clicks the close for the infowindow.

I have this code:

google.maps.event.addListener(marker, 'mouseover', function() {
    infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'mouseout', function() {
    //setTimeout(function() { infowindow.close(); }, 3000);
    infowindow.close(map, marker);
});
google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map, marker);            
    google.maps.event.clearListeners(marker, 'mouseout');
});

I'm trying to use the 'click' event to disable the 'mouseout'. The above works. Now I want to add back the 'mouseout' event after the infowindow is closed using the 'closeclick' below.

google.maps.event.addListener(infowindow, 'closeclick', function() {
    //google.maps.event.addListener(marker, 'mouseout', "");
});

I'm not sure how to do it. Can someone point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2024-11-16 14:53:43

我想通了这一点并认为我应该分享:

function attachData(marker, number) {
    //snipped code that adds the events that are removed in closeMarker
    google.maps.event.addListener(infowindow, 'closeclick', function() {
            closeMarker(marker, number);
    });
}

closeMarker 函数清除所有当前事件并通过调用 AttachData 函数将它们添加回来。

function closeMarker(marker, number) {
        google.maps.event.clearListeners(marker, 'mouseover');
        google.maps.event.clearListeners(marker, 'mouseout');
        google.maps.event.clearListeners(marker, 'click');
        google.maps.event.clearListeners(marker, 'closeclick');
        attachData(marker, number);
    }

I figured this out and thought I'd share:

function attachData(marker, number) {
    //snipped code that adds the events that are removed in closeMarker
    google.maps.event.addListener(infowindow, 'closeclick', function() {
            closeMarker(marker, number);
    });
}

The closeMarker function clears all current events and adds them back by calling the attachData function.

function closeMarker(marker, number) {
        google.maps.event.clearListeners(marker, 'mouseover');
        google.maps.event.clearListeners(marker, 'mouseout');
        google.maps.event.clearListeners(marker, 'click');
        google.maps.event.clearListeners(marker, 'closeclick');
        attachData(marker, number);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文