[英]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.