使用解决方法来设置zIndex KmlLayer

问题描述 投票:2回答:3

我一直在寻找一个直接的解决方案来解决我几天后遇到的问题。

例如,您需要在地图上按特定顺序添加多个kml图层,然后您需要zIndex。

但是使用谷歌地图API V3,你没有这样的东西。

任何的想法?

javascript google-maps google-maps-api-3 z-index settimeout
3个回答
1
投票

Google Maps Javascript API v3 KmlLayerOptions现在包含zIndex

来自the (latest) documentation

zIndex |类型:数字

层的z-index。

(或者你可以使用setZIndex方法)

请参阅此相关问题中的示例:KML ordering in Google Maps API

proof of concept fiddle


0
投票

保证Kml图层顺序的唯一方法是在添加下一图层之前等待先前的图层绘制。您可以听metadata_changed事件以了解图层何时绘制。

z-index选项是一个高度要求的功能:https://code.google.com/p/gmaps-api-issues/issues/detail?id=2804


0
投票

所以你可以做两件事。

第一种解决方法是添加侦听器:https://gist.github.com/jkeefe/1170104

第二种解决方法是在呼叫之间设置超时。

在地图上加载图层不会花费很长时间。

实际上,不需要超过10毫秒。

只需在setTimeout的回调函数中添加setTimeout即可。

例:

    layers.setMap(map);
    setTimeout(function(){
       layers2.setMap(map);
       setTimeout(function(){
          layers3.setMap(map);
          setTimeout(function(){
             layers4.setMap(map);
             setTimeout(function(){
                layers5.setMap(map);         
             },400);      
          },100);
       },100);
   },100);

我使用了第二种解决方法。

如果你认为这个帖子有用,请告诉我,Ciao!

© www.soinside.com 2019 - 2024. All rights reserved.