出于某种原因,我的信息框出现在标记后面。我知道这应该是不可能的,但事实却并非如此。这是我的标记的代码:
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'es,但没有效果。我相信这与 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 .
最佳答案
您的代码来自制作“ map 标签”的示例,并且您将 infoBox 附加到 mapPane:
pane: "mapPane"
这会将其放在标记后面。如果您希望它成为信息窗口的替代品,请复制该示例中的代码:
pane: "floatPane"
关于google-maps - 谷歌地图 : infobox turns up behind markers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23962607/