【问题标题】:Mousing over Infobox fires hover event on markers that are behind it将鼠标悬停在 Infobox 上会在其后面的标记上触发悬停事件
【发布时间】:2013-06-07 08:19:23
【问题描述】:

我目前正在为 Google 地图使用 InfoBox 插件。不幸的是,我遇到了一个烦人的问题。

我的应用程序上的用户可以通过将鼠标悬停在相应的标记上来打开信息框。这很好用。当信息框打开并且用户将鼠标悬停在它上面时,就会出现问题。出于某种原因,信息框下方的标记正在触发它们的鼠标悬停事件。这是一个大问题,因为它在打开属于刚刚触发其鼠标悬停事件的标记的框之前关闭当前框。我做了一些搜索,发现将每个标记设置为:

optimized: false

防止了这个错误。但是,此选项会减慢地图的速度并使其使用起来很麻烦。

我的信息框:

infoWindows[obj.VehicleName] = new InfoBox({
    content: contentString,
    disableAutoPan: false,
    maxWidth: 500,
    pixelOffset: new google.maps.Size(-250, -490),
    boxStyle: {
         width: "500px"
    },
    enableEventPropagation: false,
    infoBoxClearance: new google.maps.Size(45, 1)
});

我的听众:

google.maps.event.addListener(marker, 'mouseover', function() {

【问题讨论】:

标签: javascript google-maps google-maps-api-3


【解决方案1】:

丑陋的修复,因为所有广告选项 (enableEventPropagation) 似乎都不适合我(而且我当然不想在 300 多个标记上使用“optimized:false”)

在每个标记的 mouseover 侦听器中,我检查当前打开的 InfoWindow 是否被悬停:

google.maps.event.addListener(marker, 'mouseover', function() {

    //If an InfoBox is currently open
    if(openInfoBox !== null){

        var id = $(openInfoBox.getContent()).attr('id');
        //If the main div inside that InfoBox is currently being hovered over
        if ($('#' + id + ':hover').length) {
            return false; //go no further. i.e. ignore mouseover event for marker
        }

    }

    //Open InfoBox etc etc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多