我與谷歌地圖API的V3擺弄周圍,使用結合信息框插件(在http://google-maps-utility-library-v3.googlecode.com/套件的一部分),使一些很好的風格信息窗口,爲標誌的互動反應。谷歌地圖API V3鼠標懸停事件與信息框插件
對於這個特定的實驗,我試圖讓信息框窗口彈出時,標記已被懸停,但我一直在努力解決問題與事件系統有關mouseover/mouseout on InfoBox窗口。會發生什麼事是我能找到的DIV和使用google.maps.event.addDomListener
到鼠標懸停和鼠標移開事件附加到信息框,但它太繁瑣 - 當我將鼠標放置信息框內的子節點,則會將其視爲父節點上的鼠標移出,並引發事件。
是這個主題相關的傳播?我知道InfoBox在創建新的InfoBox時有一個enableEventPropagation
開關,但我不確定如何以及爲何使用它。
該實驗的目的是內部的上標記的鼠標懸停出現創建相關鏈接的信息窗口。然後,您可以在信息窗口中移動鼠標並進行交互,當您將鼠標移出時,它將關閉信息窗口。我已經嘗試了另一種方法,其中標記上的mouseover觸發外部函數,該函數創建一個定位的外部信息窗口元素並具有其自己的事件處理。這很好,但是在地圖頂部的自定義信息窗口的分層意味着當你將鼠標放在靠近另一個標記(在自定義信息窗口下)時,它不能爲該標記註冊鼠標懸停。
這是我在信息框方法嘗試:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
<!--
#map {
width: 800px;
height: 600px;
margin: 50px auto;
}
.map-popup {
overflow: visible;
display: block;
}
.map-popup .map-popup-window {
background: #fff;
width: 300px;
height: 140px;
position: absolute;
left: -150px;
bottom: 20px;
}
.map-popup .map-popup-content {
padding: 20px;
text-align: center;
color: #000;
font-family: 'Georgia', 'Times New Roman', serif;
}
-->
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js"></script>
<script type="text/javascript">
var gmap, gpoints = [];
function initialize() {
gmap = new google.maps.Map(document.getElementById('map'), {
zoom: 9,
streetViewControl: false,
scaleControl: false,
center: new google.maps.LatLng(-38.3000000,144.9629796),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
for (var i=0; i<5; i++) {
gpoints.push(new point(gmap));
}
}
function popup(_point) {
_point.popup = new InfoBox({
content: _point.content,
pane: 'floatPane',
closeBoxURL: '',
alignBottom: 1
});
_point.popup.open(_point.marker.map, _point.marker);
google.maps.event.addListener(_point.popup, 'domready', function() {
// Have to put this within the domready or else it can't find the div element (it's null until the InfoBox is opened)
google.maps.event.addDomListener(_point.popup.div_, 'mouseout', function() {
_point.popup.close();
});
});
}
function point(_map) {
this.marker = new google.maps.Marker({
position: new google.maps.LatLng(-37.8131869 - (1 * Math.random()),144.9629796 + (1 * Math.random())),
map: _map
});
this.content = '<div class="map-popup"><div class="map-popup-window"><div class="map-popup-content"><a href="http://www.google.com/">Just try to click me!</a><br/>Hovering over this text will result in a <code>mouseout</code> event firing on the <code>map-popup</code> element and this will disappear.</div></div>';
// Scope
var gpoint = this;
// Events
google.maps.event.addListener(gpoint.marker, 'mouseover', function() {
popup(gpoint);
});
}
</script>
</head>
<body onload="initialize()">
<div id="map"></div>
</body>
</html>
所以我想,如果有人知道如何使這項工作,並作出適當的反應(或提供相關的提示/技巧),那麼這將是偉大的!
你有沒有找到一個好的解決方案呢?下面的jQuery示例看起來像是針對彈出框本身而不是標記。我無法看到如何使用InfoBox以這種方式實現它。通過升級到InfoBox的最新開發版本並開啓事件傳播,我能夠讓彈出窗口不跳轉到彈出窗口下的任何底層標記。 – 2012-01-05 14:33:21