google.maps.Marker zIndex 不适用于两种图标类型 - 符号和字符串 [英] google.maps.Marker zIndex doesn't work for two icon types - Symbol and String

查看:14
本文介绍了google.maps.Marker zIndex 不适用于两种图标类型 - 符号和字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用不同的图标类型向 Google 地图添加更多标记时,例如:

When I add more Markers to Google Map with different icon types like:

...
var marker = new google.maps.Marker({
             position: markerLatLng,
             map: map,
             icon: "http://www.test.com/marker.png",
             zIndex: 10
         });
...

...
var resultIcon = {
            path: google.maps.SymbolPath.CIRCLE,
            fillColor: "black",
            strokeColor: "black",
            strokeWeight: 1,
         };

var marker = new google.maps.Marker({
             position: markerLatLng,
             map: map,
             icon: resultIcon,
             zIndex: 5
         });
...

比 zIndex 不起作用并且符号标记出现在顶部.

Than the zIndex doesn't work and the Symbol marker appears on the top.

我的代码有问题吗,或者我怎样才能让 zIndex 正常工作?

Am I wrong with my code or how can I make the zIndex working?

推荐答案

您必须同时指定 zIndex 和添加

You have to both specify a zIndex and add

optimized: false

每个标记构造函数,例如

var marker = new google.maps.Marker({
    position: markerLatLng,
    map: map,
    icon: resultIcon,
    optimized: false,
    zIndex: 5
})

这似乎是基于新画布的标记渲染的问题.

This seems to be an issue with the new canvas based rendering of the markers.

这确实解决了问题.不过要提到的一件事是每个标记都必须具有优化:假"属性.只要一个标记没有它,它就行不通.

This really solves the issue. One thing to mention though is that every marker has to have the "optimized: false" attribute. As long as one marker does not have it, it will not work.

从 LeJared 的小提琴中删除任何优化:假"属性,您将遇到错误.

Remove any of the "optimized: false" attributes from LeJared's fiddle and you will encounter the bug.

http://jsfiddle.net/BNWYq/1/

这篇关于google.maps.Marker zIndex 不适用于两种图标类型 - 符号和字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆