0

I am trying to set the Index of a wms layer called "landsat1". It draws on top by default, and I want to move it down the order. I have tried

landsat1.setZIndex(1)

But I get an error "function not found". Im using ol 3.11.0. According to the api documentation, the function is experimental....but it doesn't seem to work for any version that has this function....other functions like landsat1.getProperties() works fine....why does this function not work? Or is there a better way to set the zindex om the wms layer?

  • Do you have a jsFiddle? It works fine for me in here: openlayers.org/en/v3.11.2/examples/arcgis-tiled.html typing this in the console changes the layer sequence: map.getLayers().item(0).setZIndex(1) – bartvde Dec 1 '15 at 8:03
  • This function works fine for me too. We could help you with some code I think. – Alexis_A Dec 7 '15 at 23:39
1

To be honest I dint know about this function, maybe it is a progress I am not aware. But I ll tell what I am using so far to achive what your want.

//get the layers collection of your map
var layersColl = map.getLayers();
//you know your layer is at index 0 and you want to move it a index 1
var idxFrom = 0;
var idxTo = 1;
//this should return your landsat1 layer
var lyrToChangeIndex = layersColl.removeAt(idxFrom);
//once removed can be placed in the index you want to place it
layersColl.insertAt(idxTo,lyrToChangeIndex);
  • Thanks pavlos, those functions are a good way around...but for some strange reason my raster tilewms "landsat1" layer always stays on top. – Haydlew Dec 2 '15 at 0:40
  • when you call var lyrToChangeIndex = layersColl.removeAt(idxFrom); does this returns the layer landsat1????? You must provide some code to find out what is wrong. It propably has to do with the way you declare your layer. – pavlos Dec 2 '15 at 11:05
  • Yeah ...your right. I was using an api example that had the layer embeded inside a angularjs module. I should have provided a link to the example api code. My appoligies. Thanks Pavlos, bartvde & Alexis for taking the time to help. – Haydlew Dec 9 '15 at 2:10

Your Answer

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

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