![](/img/trans.png)
[英]When a marker lies behind open infobox - Event mouseover with InfoBox plugin Google Maps API v3
[英]Google Maps infobox not working when clicking marker
我在位置上隱藏了信息框的地方設置了谷歌地圖。 要打開信息框,請單擊自定義標記(圖釘),然后將顯示infbox。 如果我第二次單擊標記,則信息框將關閉。
現在,因為最新的谷歌地圖。 信息框會在加載時自動打開,單擊標記不會執行任何操作。 不關閉,不打開。
這是信息框的代碼。
謝謝大家!
// infobox
var $infoboxText =
$('<div class="inner">').html(contentHtml);
var myOptions = {
boxClass:'gmap_infobox',
content:$infoboxText.get(0),
disableAutoPan:false,
maxWidth:0,
alignBottom:false,
pixelOffset:new google.maps.Size(0, 0),
zIndex:null,
closeBoxURL:"",
infoBoxClearance:new google.maps.Size(1, 1),
isHidden:false,
pane:"floatPane",
enableEventPropagation:false
};
var InfoBoxClose = function () {
myOptions.boxClass = 'gmap_infobox';
ib.setOptions(myOptions);
};
var InfoBoxOpen = function () {
var $content = $(myOptions.content);
if ($content.html().length > 0) {
myOptions.boxClass = $content.is(':visible') ? 'gmap_infobox' : 'gmap_infobox gmap_infobox--visible';
ib.setOptions(myOptions);
}
};
InfoBox.prototype.getCloseClickHandler_ = function () {
return handleInfoBoxClose;
};
var ib = new InfoBox(myOptions);
ib.open(map, marker);
if (config.marker === 'open-bubble') {
InfoBoxOpen();
}
// listeners
google.maps.event.addListener(marker, 'click', function() {
InfoBoxOpen();
});
}
首先,瀏覽以下內容: 參考api 。 特別是有關InfoWindow和InfoWindowOptions的部分。
然后試試看
var map, myInfoWindow;
function initialize() {
//Create the map
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(38.8282, -98.5795),
};
map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
//Create the infoWindow
var iwOptions = {content: "stuff"}; //put your infowindow options here
myInfoWindow = new google.maps.InfoWindow(iwOptions);
//coordinates for marker placement
var myLatLng = [
new google.maps.LatLng(32, -83),
new google.maps.LatLng(41, -90),
new google.maps.LatLng(38, -109)
];
//Create markers
for(var i=0; i<myLatLng.length; i++){
var marker = new google.maps.Marker({
position: myLatLng[i],
map: map
})
//This is the important part: add this to each of you markers
google.maps.event.addListener(marker, 'click', function(){
if( myInfoWindow.anchor === this ){
myInfoWindow.close();
} else {
myInfoWindow.open(map, this);
}
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.