0

I have 6 different layers. Some are layers with markers and some other with raster data. In some point, when I zoom in the map, I create a vector layer. Upon adding the layer on the map I want a specific WMS layer to appear above the vector layer. That's why I do this:

map.setLayerIndex(wms_layer_network, map.layers.length+100);

Although the layer indeed change position and comes to the top, on my map I don't see this change. The vector layer keeps being on top of the WMS. This is how I check the layer array and their position (assuming the last value of the array is the one which will appear on top):

                    var mLayers = map.layers;

                for(var a = 0; a < mLayers.length; a++ ){
                    alert(mLayers[a].name)
                };

Does anyone know why this happens?

1 Answer 1

1

The map.layers.length only gives you the array size of the layers with the map but not the zindexes of those layers as specific ranges are used depending on what is being displayed. So, one possibility would be to add the vector layer, get its zindex, get the WMS zindex, and see if swapping the two would work for you, i.e.

var vectorindex = map.getLayerIndex(vector);
var WMSindex = map.getLayerIndex(WMS);
map.setLayerIndex(vector, WMSindex);
map.setLayerIndex(WMS, vectorindex);

where WMS and vector are the layers of course. You could also use the layer methods, getZIndex() and setZIndex(integer) to get/set the layer index as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.