Merge pull request #12284 from MoonE/layer-group-inherit-zindex

Layers should inherit group z-index
This commit is contained in:
MoonE
2021-06-17 00:01:09 +02:00
committed by GitHub
4 changed files with 182 additions and 100 deletions

View File

@@ -111,8 +111,7 @@ class BaseLayer extends BaseObject {
state.sourceState = this.getSourceState();
state.visible = this.getVisible();
state.extent = this.getExtent();
state.zIndex =
zIndex !== undefined ? zIndex : state.managed === false ? Infinity : 0;
state.zIndex = zIndex === undefined && !state.managed ? Infinity : zIndex;
state.maxResolution = this.getMaxResolution();
state.minResolution = Math.max(this.getMinResolution(), 0);
state.minZoom = this.getMinZoom();

View File

@@ -205,12 +205,16 @@ class LayerGroup extends BaseLayer {
}
/**
* @param {Array<import("./Layer.js").State>} [opt_states] Optional list of layer states (to be modified in place).
* Get the layer states list and use this groups z-index as the default
* for all layers in this and nested groups, if it is unset at this point.
* If opt_states is not provided and this group's z-index is undefined
* 0 is used a the default z-index.
* @param {Array<import("./Layer.js").State>} [opt_states] Optional list
* of layer states (to be modified in place).
* @return {Array<import("./Layer.js").State>} List of layer states.
*/
getLayerStatesArray(opt_states) {
const states = opt_states !== undefined ? opt_states : [];
const pos = states.length;
this.getLayers().forEach(function (layer) {
@@ -218,6 +222,10 @@ class LayerGroup extends BaseLayer {
});
const ownLayerState = this.getLayerState();
let defaultZIndex = ownLayerState.zIndex;
if (!opt_states && ownLayerState.zIndex === undefined) {
defaultZIndex = 0;
}
for (let i = pos, ii = states.length; i < ii; i++) {
const layerState = states[i];
layerState.opacity *= ownLayerState.opacity;
@@ -242,6 +250,9 @@ class LayerGroup extends BaseLayer {
layerState.extent = ownLayerState.extent;
}
}
if (layerState.zIndex === undefined) {
layerState.zIndex = defaultZIndex;
}
}
return states;