Merge pull request #10237 from fredj/zIndex_falsy_value

Fix layer zIndex test with falsy values
This commit is contained in:
Frédéric Junod
2019-11-01 08:25:56 +01:00
committed by GitHub
2 changed files with 10 additions and 9 deletions
+2 -1
View File
@@ -108,11 +108,12 @@ class BaseLayer extends BaseObject {
managed: opt_managed === undefined ? true : opt_managed, managed: opt_managed === undefined ? true : opt_managed,
hasOverlay: false hasOverlay: false
}); });
const zIndex = this.getZIndex();
state.opacity = clamp(Math.round(this.getOpacity() * 100) / 100, 0, 1); state.opacity = clamp(Math.round(this.getOpacity() * 100) / 100, 0, 1);
state.sourceState = this.getSourceState(); state.sourceState = this.getSourceState();
state.visible = this.getVisible(); state.visible = this.getVisible();
state.extent = this.getExtent(); state.extent = this.getExtent();
state.zIndex = this.getZIndex() || (state.managed === false ? Infinity : 0); state.zIndex = zIndex !== undefined ? zIndex : (state.managed === false ? Infinity : 0);
state.maxResolution = this.getMaxResolution(); state.maxResolution = this.getMaxResolution();
state.minResolution = Math.max(this.getMinResolution(), 0); state.minResolution = Math.max(this.getMinResolution(), 0);
state.minZoom = this.getMinZoom(); state.minZoom = this.getMinZoom();
+8 -8
View File
@@ -592,7 +592,7 @@ describe('ol.layer.Layer', function() {
const frameState = { const frameState = {
layerStatesArray: [] layerStatesArray: []
}; };
map.dispatchEvent(new RenderEvent('precompose', null, frameState, null, null)); map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
expect(frameState.layerStatesArray.length).to.be(1); expect(frameState.layerStatesArray.length).to.be(1);
const layerState = frameState.layerStatesArray[0]; const layerState = frameState.layerStatesArray[0];
expect(layerState.layer).to.equal(layer); expect(layerState.layer).to.equal(layer);
@@ -644,18 +644,18 @@ describe('ol.layer.Layer', function() {
}); });
it('has Infinity as zIndex when not configured otherwise', function() { it('has Infinity as zIndex when not configured otherwise', function() {
map.dispatchEvent(new RenderEvent('precompose', null, map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
frameState, null, null));
const layerState = frameState.layerStatesArray[0]; const layerState = frameState.layerStatesArray[0];
expect(layerState.zIndex).to.be(Infinity); expect(layerState.zIndex).to.be(Infinity);
}); });
it('respects the configured zIndex', function() { it('respects the configured zIndex', function() {
layer.setZIndex(42); [-5, 0, 42].forEach(index => {
map.dispatchEvent(new RenderEvent('precompose', null, layer.setZIndex(index);
frameState, null, null)); map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
const layerState = frameState.layerStatesArray[0]; const layerState = frameState.layerStatesArray[0];
expect(layerState.zIndex).to.be(42); expect(layerState.zIndex).to.be(index);
});
}); });
}); });