OpenLayers – Set Layer Ordering
We just need to use the following in order to set the layer ordering.
var layer = map.getLayer(id);
Please take note, the following are the base z-index of each components in OpenLayers:
BaseLayer : 100,
Overlay : 325,
Feature : 725,
Popup : 750,
Control : 1000
Most of the layer overlays start it’s z-index from 725 + zIdx * 5(see OpenLayers.Map.setLayerZIndex() method. So if you pass a zIdx of 5, then the ordering of the overylay is 725 + (5 * 5) = 750.
You maybe have two or more layers need to be set their ordering (probably you have the mechanism of drag and drop interface for setting up layer ordering, or some sort of it), this little tips should work, as long you be able to grab the target layers – and do the swap method to change it’s ordering(use OpenLayers.Layer.getZIndex() to get the Z-Index of the particular layer).
Hope you got the idea. Please let me know if my explanation is confusing. I’ll further explain, if needed. 🙂