【发布时间】:2014-07-29 14:24:38
【问题描述】:
这看起来很简单,但我找不到解决方案。我有一个带有 KML 和多边形的谷歌地图。将鼠标悬停在多边形上会弹出一个信息框。如果用户将鼠标悬停在信息框上,它需要保持打开状态,但如果用户将鼠标悬停在信息框之外,或者如果用户鼠标悬停在多边形上,那么信息框应该关闭。所以听起来很简单,但目前我只能做其中之一。
更新:
以下内容现在可以正常工作,但是有点“错误”。这是由于当用户实际上在多边形的中心(信息框弹出的位置)周围悬停时发生“mouseout”功能,脚本认为他们已将光标移出多边形,因为信息框图层加载在顶部。
代码:
// User moves the cursor outside of the active polygon
google.maps.event.addListener(poly,"mouseout",function() {
$poly = this;
$infowindow_hover = false;
$("#geoxml3_infowindow").mouseenter(function(){
clearTimeout($(this).data('timeoutId'));
$infowindow_hover = true;
}).mouseleave(function(){
var someElement = $(this),
timeoutId = setTimeout(function(){
$poly.infoWindow.close();
}, 500);
//set the timeoutId, allowing us to clear this trigger if the mouse comes back over
someElement.data('timeoutId', timeoutId);
});
function closeInfoWindow()
{
if ($infowindow_hover == false) $poly.infoWindow.close();
}
setTimeout(closeInfoWindow, 1000)
});
【问题讨论】:
-
我已经尝试过了,但还有很多需要考虑的地方。我在其他库和自定义 KML 文件等中使用 geoxml3,并且得到一个简单的简化测试用例工作被证明是一场噩梦。
标签: javascript jquery google-maps google-maps-api-3