Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a marker layer, two vector layers and two raster layers. The marker layer gets covered by the two raster layers.

Is there a way to move the marker layer always on top?

Edited: The order of Z-indexes works well in the vector layer, but when I add another WMS raster layer on the map with a lower Z-index, the raster layer still covers the vector layer.

Edited: Could anyone point out the difference of the rendering order in terms of "LayerIndex" and "Z-Index" of a Layer? I think the layer index deal with the overlay order and the Zindex deals with the feature order in a vector layer, am I right?

share|improve this question
I think layerindex and z-index are interchangeable terms in OpenLayers. They are used in the same context in the documentation, ex:… – Casey Oct 4 '11 at 18:24
Hello @Casey I appreciate your example. However, I do not think the layerindex and z-index are interchangeable. For my own experience the setZindex does not work but the setIndex works. I notice that: 1. the Z-index example in openlayer works for a feature in a vector layer, and it is enabled by rendererOptions: {zIndexing: true}. 2.From your example for the raster image layer, you can see the layer render order is based on what you see on the map control, which depends on the layer index (as your answer code). 3. The layer index is set by the order I add on new layer (based layer as 0...) – Seen Oct 5 '11 at 1:52
1. I think you are right. 2 & 3. Right, but you can override the default behavior by calling the setLayerIndex method, which adjusts the z-index of a layer. This will effect the order of the layers in the map control and the drawing order of the layers. – Casey Oct 5 '11 at 2:38
Thanks for your clarification! – Seen Oct 5 '11 at 13:50
up vote 21 down vote accepted

Setting the z-index for each layer should help:


The example I originally linked to isn't too helpful. You want to set the layerindex/z-index of the layers, not the makers within the layers (as the ordering example showed). I put together an example (based off this example) showing custom layer indexing. Notice that when you turn on the Canada Raster, the Marker layer stays on top.

Here is the relevant code:

map.setLayerIndex(dm_wms, 0); //set the image overlay to the bottom
map.setLayerIndex(markers, 99); //set the marker layer to an arbitrarily high layer index

The documentation for the setLayerIndex code is here:

share|improve this answer

You can do it , if you want your vector layer always top with simply code...

var vecLyr = map.getLayersByName('VectorLayer')[0];
map.raiseLayer(vecLyr, map.layers.length);

May it be easy!

share|improve this answer

You can think of adding a layer to map as of laying a new sheet on top of existing ones. If the new sheet is not transparent it will hide all those below.

Unfortunately OpenLayers does not have an insertLayerAt method, so you have to reorder your layers after insertion. The solution is then to add the layer and then move it down the stack to the desired depth or move the one that you want on top back to the top.

You can do that as follows:

// add your wms as usual
var yourWMSLayer = new ....

// you can do it both ways:
// 1. now move the markers to the top of the stack
var yourMarkers = map.getLayersByName("the marker layer name")[0];
map.setLayerIndex(yourMarkers, map.layers.length-1);

// 2. OR you move the WMS down
// this is more succint
map.setLayerIndex(yourWMSLayer, map.layers.length-2);
share|improve this answer

none of the above worked for me, but simply doing this whenever I add a new layer worked a treat to keep my marker layer on top:

myMarkerLayer.setZIndex( 1001 );

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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