简体   繁体   English

如何使用Google Maps API设置图层顺序?

[英]How to set up the layer order with Google Maps API?

I'm developing a web mapping site (using google maps api 3.0 and javascript) that combines wms layers and ground overlays (uploaded rasters) that are displayed on top of google maps. 我正在开发一个网络地图网站(使用Google Maps api 3.0和javascript),该网站结合了wms图层和显示在Google地图顶部的地面叠加层(上载的栅格)。 The software is working well except that I'm having problems controlling the draw order of the layers. 该软件运行良好,但无法控制图层的绘制顺序。 I would like to have the wms layer (the NRCS soils layer) displayed on top of the custom raster images, with the google maps as the base layer. 我想在自定义栅格图像的顶部显示wms层(NRCS土层),并以google地图作为基础层。 Currently, the wms layer displays as expected on top of the google maps layer, but is covered by the raster layer. 当前,wms图层按预期显示在google maps图层的顶部,但是被raster图层覆盖。 The question is: does the google maps api allow control of the order that layers are displayed (in my case the vector layer on top of raster layer on top of google maps)? 问题是:google maps api是否允许控制图层的显示顺序(在我的情况下,矢量层位于google地图的栅格图层之上)? I have tried setting the zindex of the display order, but that has not worked (but I could easily be missing something). 我尝试设置显示顺序的zindex,但是没有用(但是我很容易丢失某些东西)。

WMS layers are also rasters, not vectors -- I assume you are using an ImageMapType along with your GroundOverlay? WMS图层也是栅格,而不是矢量-我假设您正在将ImageMapType和GroundOverlay一起使用?

Leaving that aside, there is currently no way to control the layer ordering once they have been added to the map. 抛开这些,将图层添加到地图后,目前无法控制图层的顺序。

As a hack (untested) you may wish to add the layers in the order you wish them to be drawn, with some timeout between... I think this may work (again, untested). 作为hack(未经测试),您可能希望按希望绘制的顺序添加图层,并且之间存在一些超时...我认为这可能会起作用(再次,未经测试)。

(optional). (可选的)。 how i order it. 我如何订购。

first i create layer in object like this. 首先,我在这样的对象中创建图层。

        layer = {};
        layer.nrcs_soils= new google.maps.ImageMapType({
            getTileUrl: function (coord, zoom) {
                return getTileWmsUrl(coord, zoom, "nrcs_soils");
            },
            tileSize: new google.maps.Size(256, 256),
            opacity: 1,
            name:'nrcs_soils',
            alt:{
                layer_name:'nrcs_soils'
                ,order   : 0
            },
            isPng: true
        });

after that i create simple function add layer to map. 之后,我创建简单的功能添加图层来映射。

add_layer = function(layer_name){
   //-- get order from object layer
   var order_layer =layer[layer_name].alt.order;
   map.overlayMapTypes.insertAt(order_layer ,layer[layer_name]);

} }

just call this function for add and order layer from your setting on your object layer. 只需通过对象层上的设置调用此函数即可添加和订购层。

add_layer("nrcs_soils");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM