出于某种原因,我的infoBox会出现在标记后面。我知道这应该是不可能的,但事实并非如此。这是我的标记的代码:
var yellowCircle={
path: google.maps.SymbolPath.CIRCLE,
scale: 5,
fillColor: '#faeadd',
strokeColor: 'black',
fillOpacity: 1.0,
strokeWeight: 0.5,
zIndex:-10
};
var yellowBlackCircle={
path: google.maps.SymbolPath.CIRCLE,
scale: 5,
fillColor: '#faeadd',
strokeColor: 'black',
fillOpacity: 1.0,
strokeWeight: 1.5,
zIndex:-10
};
var marker = new google.maps.Marker({
position: new google.maps.LatLng(Lat,Lng),
map: map,
title: name,
icon:yellowCircle,
url:url,
zIndex:-1,
});
google.maps.event.addListener(marker, 'mouseover', function() {
marker.setIcon(yellowBlackCircle);
});
google.maps.event.addListener(marker, 'mouseout', function() {
marker.setIcon(yellowCircle);
});
google.maps.event.addListener(marker, 'click', function() {
window.location.href = url;
});
我的信息框的代码:
var myOptions = {
content: name
,boxStyle: {
border: "1px solid black"
,textAlign: "center"
,fontSize: "12pt"
,fontType: "arial"
,backgroundColor: "#faeadd"
,fontWeight: "bold"
,zIndex:1
}
,disableAutoPan: true
,pixelOffset: new google.maps.Size(-getTextWidth(name, "bold 12pt arial")/2,-30)
,position: new google.maps.LatLng(49.47216, -123.76307)
,closeBoxURL: ""
,isHidden: false
,pane: "mapPane"
,enableEventPropagation: true
,zIndex:1
};
var infobox = new InfoBox(myOptions);
google.maps.event.addListener(marker, 'mouseover', function() {
infobox.open(map,marker);
});
google.maps.event.addListener(marker, 'mouseout', function() {
infobox.close();
});
您可以看到我甚至尝试过设置zIndex,但它没有任何效果。我认为这与google maps infobox above all other content z-index does not work中提出的问题相同。
我为没有附上jsfiddle而道歉 - 即使我将infobox_packed.js上传到存储库之后我似乎无法使其工作,所以我可以添加作为外部资源。相反,这是整个事情: http://www.kaarebmikkelsen.dk/wp-content/uploads/2014/05/test2.html
信息框代码主要是从https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/examples.html复制的。
答案 0 :(得分:4)
您的代码来自制作“地图标签”的示例,并且您将infoBox附加到mapPane:
pane: "mapPane"
这将把它放在标记之后。如果您希望它是infowindow替换,请复制该示例中的代码:
pane: "floatPane"