将鼠标悬停在地图之外后,我想在 googlemap 之外显示信息框。在此代码中,mastercluster 和 infobox 工作正常,但仅在 div 外部显示时出现问题。
var pop = document.getElementById('example1');
var locations = <?php echo json_encode($jsArray); ?>;
var image = 'images/mapmarker.png';
var myLatlng = new google.maps.LatLng(locations[0][0], locations[0][1]);
var myOptions = {
zoom: 10,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDoubleClickZoom: false,
disableDefaultUI: true,
visibleInfoWindow: null,
zoomControlOptions: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
}
};
var mcOptions = {styles: [{
opt_textColor: 'white',
textColor: 'white',
height:34,
url: image,
width:34
}],
description: ' tracks: click to show'
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var markers = [];
for(var i=0;i<locations.length;i++)
{
var latlng=new google.maps.LatLng(locations[i][0], locations[i][1]);
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: image
});
boxText = document.createElement("div");
infoboxOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(18, -60),
zIndex: null,
boxStyle: {
opacity: 0.75,
width: "250px"
},
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
markers.push(marker);
boxText.style.cssText = "border: 1px solid black; margin-top:3px; background:#333; color:#FFF; font-family:Arial; font-size:12px; padding: 3px; border-radius:6px; -webkit-border-radius:6px; -moz-border-radius:6px;";
boxText.innerHTML = "<b>Hotel Name</b>: "+locations[i][2] + "<br/><br/>" + "<b>Rating</b>: "+locations[i][3]+"<br/><br/>"+"<b>Price:</b> € "+locations[i][4];
markers[i].infobox = new InfoBox(infoboxOptions);
pop.onmouseout = generateTriggerCallback(marker[i], 'mouseout');
pop.onmouseover = generateTriggerCallback(marker[i], 'mouseover');
$(".popup_slide").hover(function(){
$(this).addClass("resulthover");
},
function () {
$(this).removeClass("resulthover");
});
google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
return function() {
markers[i].infobox.open(map, this);
}
})(marker, i));
google.maps.event.addListener(marker, 'mouseout', (function(marker, i) {
return function() {
markers[i].infobox.close(map, this);
}
})(marker, i));
}
var markerCluster = new MarkerClusterer(map, markers, mcOptions);
function generateTriggerCallback(object, eventType) {
return function() {
google.maps.event.trigger(object, eventType);
};
}