简体   繁体   English

鼠标悬停在Infobox上会将悬停事件悬停在其背后的标记上

[英]Mousing over Infobox fires hover event on markers that are behind it

I'm currently using the InfoBox plugin for Google Maps. 我目前正在使用Google地图的InfoBox插件。 Unfortunately, I've run into an annoying problem. 不幸的是,我遇到了一个恼人的问题。

Users on my app can open an InfoBox by hovering over its corresponding marker. 我的应用程序上的用户可以通过将鼠标悬停在相应的标记上来打开InfoBox。 That works fine. 这很好。 The problem occurs when the InfoBox is open and the user is mousing over it. 当InfoBox打开并且用户将鼠标悬停在InfoBox上时,会出现此问题。 For some reason, the markers beneath the InfoBox are firing off their mouseover events. 出于某种原因,InfoBox 下方的标记会触发鼠标悬停事件。 This is a big issue because it closes the current box before opening the box belonging to the marker that has just fired off its mouseover event. 这是一个很大的问题,因为它会在打开属于刚刚触发其鼠标悬停事件的标记的框之前关闭当前框。 I've done some searching and I've found out that setting each marker to: 我做了一些搜索,我发现将每个标记设置为:

optimized: false

prevents this bug. 防止这个bug。 However, this option slows down the map and makes it feel cumbersome to use. 但是,此选项会降低地图的速度并使其使用起来变得很麻烦。

My InfoBox: 我的InfoBox:

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)
});

My listener: 我的听众:

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

Ugly fix because none of the advertised options (enableEventPropagation) seemed to be working for me (and I certainly didn't want to go down the route of using "optimized:false" on 300+ markers) 丑陋的修复,因为没有任何广告选项(enableEventPropagation)似乎对我有用(我当然不希望在300多个标记上使用“optimized:false”)

Inside the mouseover listener for each marker, I do a check to see if the currently-opened InfoWindow is being hovered over: 在每个标记的鼠标悬停监听器内部,我检查当前打开的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将鼠标悬停在顶部的对象上时,SVG悬停取消 - SVG hover cancelled when mousing over an object on top 模拟鼠标移开或页面点击重置 hover 事件 - Simulate mousing away or page click to reset hover event 单击或悬停在信息框上时,可响应地更改信息框的颜色 - Reactively changing colour of an infobox, upon a click or hover over 当标记位于打开的信息框后面时 - 使用InfoBox插件Google Maps API v3进行事件鼠标悬停 - When a marker lies behind open infobox - Event mouseover with InfoBox plugin Google Maps API v3 jQuery悬停/隐藏/显示-将鼠标悬停在多个图像上时,并非所有文本都会正确消失 - jQuery hover/hide/show - not all the text will disappear correctly when mousing over multiple images 将鼠标悬停在表格单元格分隔符HTML / CSS / JS上时的悬停效果 - Hover effect when mousing over table cell dividers HTML/CSS/JS Jquery动画鼠标悬停在容器上 - Jquery animate on mousing over the container 如果google.maps.Rectangle和InfoBox重叠,则地图上的Click事件会触发两次 - Click event on the map fires two times if google.maps.Rectangle and InfoBox are overlapped 在d3折线图中,如何在文本后面创建与鼠标悬停相同大小的边框? - In a d3 line chart, how do I create a bounding box behind my text that is the same size as what I'm mousing over? 将信息框添加到Google地方信息标记 - Add infobox to Google Places markers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM