Google 地图:如何更改标记的 z 索引?
谷歌地图上大约有 100 个标记,另外还有一个特殊标记需要可见。目前,当地图缩小时,它周围的标记会完全或部分隐藏它。我需要该标记完全可见,并且我认为将其放在所有其他标记之上应该可以解决问题。但我找不到修改其堆叠顺序(z-index)的方法。
There are about 100 markers on a google map plus there is one special marker that needs to be visible. Currently, the markers around it hide it totally or partially when the map is zoomed out. I need that marker to be fully visible and I think keeping it on top of all other markers should do the trick. But I cannot find a way to modify its stacking order (z-index).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这适用于 Google Maps API 2。
对于 Google Maps API 3,请使用标记的 setZIndex(zIndex:number)。
看:
http://code.google.com/apis/maps/documentation /javascript/reference.html#标记
This is for Google Maps API 2.
For Google Maps API 3 use the setZIndex(zIndex:number) of the marker.
See:
http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker
当您创建标记您想要在顶部的标记。例如:
我相信默认值是有一个 z 索引,它是标记点的纬度,所以这应该相当安全地将单个标记放在前面。此外,这只是一个简单的例子;您可以按照您想要的任何简单或复杂的方式设置所有标记的 z 索引。另一个例子是有两个函数:一个用于特殊标记,一个用于其余标记。
Use the zIndexProcess option in GMarkerOptions when you create the marker that you want on top. For example:
I believe the default is to have a z-index that is the latitude of the point of the marker, so this should be fairly safe at bringing a single marker to the front. Further, this was just a simple example; you can set the z-index of all your markers in whatever simple or complex way you want. Another example is to have two functions: one for special markers and one for the rest.
添加到 jhanifen 的答案中,如果您想让一个特殊标记位于所有其他标记之上,请将其 zIndex 设置为 google.maps.Marker.MAX_ZINDEX + 1。这将确保它位于任何标记之上在地图上。
Adding on to jhanifen's answer, if you want to get your one special marker to be on top of all the rest, set it's zIndex to google.maps.Marker.MAX_ZINDEX + 1. This will make sure that it is on top of any marker on the map.