In my project I have the following situation:

layer A: zIndex = 1000;
layer B: zIndex = 2000;
layer C: zIndex = 3000;
layer D: zIndex = 4000;

I add the layers in this order:

layer A, layer C, layer D, layer B

I expect that correspondent to the zIndex the layers are in the following order:

layer A, layer B, layer C, layer D

But they are not! I get the order as they are added.

My questions:

  • Is the zIndex mechanism implemented - I'm using OL3.15.x and OL3.16.0?
  • How to set the zIndex to get the wanted result?
  • Are there any limitations on zIndex?
  • Should I add the layer before setting the zIndex?

Currently I'm porting a huge project from OpenLayers2 to Openlayers3. In OL2 this worked and with OL3 not.

This is a code snipped for one layer. The other layers are created in a similar way:

var sourceA = new ol.source.Vector({
 loader: fetchData,
 strategy: ol.loadingstrategy.bbox,
if (sourceA) {
 var layerA = new ol.layer.Vector({
  source: sourceA,
  visible: false
 if (layerA) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy