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

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

问题描述

当我使用不同的图标类型为Google Map添加更多标记时:

  ... 
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不起作用,Symbol符号出现在



我的代码出错了,或者我该如何让zIndex工作?

解决方案

您必须同时指定 zIndex 并添加

 优化:假

改为每个标记构造函数,例如

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

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

p>

这真的解决了这个问题。
但要注意的一点是,每个标记必须具有优化:假属性。只要一个标记没有它,它将无法工作。



从LeJared的小提琴中删除任何optimized:false属性,您将遇到该错误。



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

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
         });
...

and

...
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
         });
...

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

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

解决方案

You have to both specify a zIndex and add

optimized: false

to every marker constructor, eg.

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.

Edit:

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.

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天全站免登陆