Javascript 如何在 Google Maps API v3 中设置标记的 z-index
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9021159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set the z-index of a marker in Google Maps API v3
提问by Zabs
Can anyone explain the exact syntax used to set the z-index for a marker using the Google Maps API (Version 3)?
任何人都可以解释用于使用 Google Maps API(版本 3)为标记设置 z-index 的确切语法吗?
回答by ori
In the MarkerOptions:
var marker = new google.maps.Marker({
....
zIndex: 100
});
Or via the Markersetter:
或者通过标记设置器:
marker.setZIndex(100);
回答by super_user
zIndex is actually a relative term. For example, if you have two markers, marker1 and marker2, and the zIndex of marker1 is 100 and the zIndex of marker2 is 101: it means that marker2 is higher in the stack than marker1. As a result, marker2 will be on top or marker1, and in front of the user.
zIndex 实际上是一个相对术语。例如,如果您有两个标记,marker1 和marker2,并且marker1 的zIndex 为100,而marker2 的zIndex 为101:这意味着marker2 在堆栈中比marker1 高。因此,marker2 将在顶部或marker1 上,并在用户面前。
You can set the z-index using :
您可以使用以下方法设置 z-index:
var marker=new google.maps.Marker({
position: myCenter,
map: map,
zIndex: 100
});
If you have previously created a marker, then just use:
如果您之前已经创建了一个标记,那么只需使用:
marker.setZIndex(101);