Support zoom limits for layers
This commit is contained in:
@@ -44,7 +44,9 @@ describe('ol.layer.Group', function() {
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: Infinity,
|
||||
minResolution: 0
|
||||
minResolution: 0,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
});
|
||||
|
||||
@@ -147,13 +149,17 @@ describe('ol.layer.Group', function() {
|
||||
visible: false,
|
||||
zIndex: 10,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: 1,
|
||||
maxZoom: 10
|
||||
});
|
||||
|
||||
expect(layerGroup.getOpacity()).to.be(0.5);
|
||||
expect(layerGroup.getVisible()).to.be(false);
|
||||
expect(layerGroup.getMaxResolution()).to.be(500);
|
||||
expect(layerGroup.getMinResolution()).to.be(0.25);
|
||||
expect(layerGroup.getMinZoom()).to.be(1);
|
||||
expect(layerGroup.getMaxZoom()).to.be(10);
|
||||
expect(layerGroup.getLayerState()).to.eql({
|
||||
layer: layerGroup,
|
||||
opacity: 0.5,
|
||||
@@ -164,7 +170,9 @@ describe('ol.layer.Group', function() {
|
||||
extent: undefined,
|
||||
zIndex: 10,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: 1,
|
||||
maxZoom: 10
|
||||
});
|
||||
expect(layerGroup.getLayers()).to.be.a(Collection);
|
||||
expect(layerGroup.getLayers().getLength()).to.be(1);
|
||||
@@ -206,7 +214,9 @@ describe('ol.layer.Group', function() {
|
||||
extent: groupExtent,
|
||||
zIndex: 0,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
expect(layerGroup.getLayers()).to.be.a(Collection);
|
||||
expect(layerGroup.getLayers().getLength()).to.be(1);
|
||||
@@ -237,6 +247,8 @@ describe('ol.layer.Group', function() {
|
||||
layerGroup.setExtent(groupExtent);
|
||||
layerGroup.setMaxResolution(500);
|
||||
layerGroup.setMinResolution(0.25);
|
||||
layerGroup.setMinZoom(5);
|
||||
layerGroup.setMaxZoom(10);
|
||||
expect(layerGroup.getLayerState()).to.eql({
|
||||
layer: layerGroup,
|
||||
opacity: 0.3,
|
||||
@@ -247,7 +259,9 @@ describe('ol.layer.Group', function() {
|
||||
extent: groupExtent,
|
||||
zIndex: 10,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: 5,
|
||||
maxZoom: 10
|
||||
});
|
||||
});
|
||||
|
||||
@@ -264,7 +278,9 @@ describe('ol.layer.Group', function() {
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: Infinity,
|
||||
minResolution: 0
|
||||
minResolution: 0,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
|
||||
layerGroup.setOpacity(3);
|
||||
@@ -279,7 +295,9 @@ describe('ol.layer.Group', function() {
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: Infinity,
|
||||
minResolution: 0
|
||||
minResolution: 0,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
});
|
||||
|
||||
@@ -452,12 +470,58 @@ describe('ol.layer.Group', function() {
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: 150,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
|
||||
layerGroup.dispose();
|
||||
});
|
||||
|
||||
it('returns max minZoom', function() {
|
||||
const group = new LayerGroup({
|
||||
minZoom: 5,
|
||||
layers: [
|
||||
new Layer({
|
||||
source: new Source({
|
||||
projection: 'EPSG:4326'
|
||||
})
|
||||
}),
|
||||
new Layer({
|
||||
source: new Source({
|
||||
projection: 'EPSG:4326'
|
||||
}),
|
||||
minZoom: 10
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
expect(group.getLayerStatesArray()[0].minZoom).to.be(5);
|
||||
expect(group.getLayerStatesArray()[1].minZoom).to.be(10);
|
||||
});
|
||||
|
||||
it('returns min maxZoom of layers', function() {
|
||||
const group = new LayerGroup({
|
||||
maxZoom: 5,
|
||||
layers: [
|
||||
new Layer({
|
||||
source: new Source({
|
||||
projection: 'EPSG:4326'
|
||||
})
|
||||
}),
|
||||
new Layer({
|
||||
source: new Source({
|
||||
projection: 'EPSG:4326'
|
||||
}),
|
||||
maxZoom: 2
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
expect(group.getLayerStatesArray()[0].maxZoom).to.be(5);
|
||||
expect(group.getLayerStatesArray()[1].maxZoom).to.be(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import Layer, {visibleAtResolution} from '../../../../src/ol/layer/Layer.js';
|
||||
import Layer, {inView} from '../../../../src/ol/layer/Layer.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import RenderEvent from '../../../../src/ol/render/Event.js';
|
||||
import Source from '../../../../src/ol/source/Source.js';
|
||||
@@ -43,6 +43,14 @@ describe('ol.layer.Layer', function() {
|
||||
expect(layer.getMinResolution()).to.be(0);
|
||||
});
|
||||
|
||||
it('provides default min zoom', function() {
|
||||
expect(layer.getMinZoom()).to.be(-Infinity);
|
||||
});
|
||||
|
||||
it('provides default max zoom', function() {
|
||||
expect(layer.getMaxZoom()).to.be(Infinity);
|
||||
});
|
||||
|
||||
it('provides default layerState', function() {
|
||||
expect(layer.getLayerState()).to.eql({
|
||||
layer: layer,
|
||||
@@ -54,7 +62,9 @@ describe('ol.layer.Layer', function() {
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: Infinity,
|
||||
minResolution: 0
|
||||
minResolution: 0,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,6 +82,8 @@ describe('ol.layer.Layer', function() {
|
||||
zIndex: 10,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25,
|
||||
minZoom: 1,
|
||||
maxZoom: 10,
|
||||
foo: 42
|
||||
});
|
||||
|
||||
@@ -79,6 +91,8 @@ describe('ol.layer.Layer', function() {
|
||||
expect(layer.getVisible()).to.be(false);
|
||||
expect(layer.getMaxResolution()).to.be(500);
|
||||
expect(layer.getMinResolution()).to.be(0.25);
|
||||
expect(layer.getMinZoom()).to.be(1);
|
||||
expect(layer.getMaxZoom()).to.be(10);
|
||||
expect(layer.get('foo')).to.be(42);
|
||||
expect(layer.getLayerState()).to.eql({
|
||||
layer: layer,
|
||||
@@ -90,7 +104,9 @@ describe('ol.layer.Layer', function() {
|
||||
extent: undefined,
|
||||
zIndex: 10,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: 1,
|
||||
maxZoom: 10
|
||||
});
|
||||
|
||||
layer.dispose();
|
||||
@@ -108,7 +124,7 @@ describe('ol.layer.Layer', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('visibleAtResolution', function() {
|
||||
describe('inView', function() {
|
||||
let layer;
|
||||
|
||||
beforeEach(function() {
|
||||
@@ -123,36 +139,196 @@ describe('ol.layer.Layer', function() {
|
||||
layer.dispose();
|
||||
});
|
||||
|
||||
it('returns false if layer is not visible', function() {
|
||||
layer.setVisible(false);
|
||||
layer.setMinResolution(3);
|
||||
layer.setMaxResolution(5);
|
||||
const layerState = layer.getLayerState();
|
||||
expect(visibleAtResolution(layerState, 4)).to.be(false);
|
||||
});
|
||||
const cases = [{
|
||||
when: 'layer is not visible',
|
||||
visible: false,
|
||||
view: {
|
||||
resolution: 4, zoom: 4
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'layer is not visible (with min/max zoom and resolution)',
|
||||
visible: false,
|
||||
minZoom: 2,
|
||||
maxZoom: 6,
|
||||
minResolution: 2,
|
||||
maxResolution: 6,
|
||||
view: {
|
||||
resolution: 4, zoom: 4
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view zoom is less than minZoom',
|
||||
minZoom: 2,
|
||||
view: {
|
||||
resolution: 1, zoom: 1
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view zoom is less than minZoom (with maxZoom)',
|
||||
minZoom: 2,
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 1, zoom: 1
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view zoom is equal to minZoom',
|
||||
minZoom: 2,
|
||||
view: {
|
||||
resolution: 2, zoom: 2
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view zoom is equal to minZoom (with maxZoom)',
|
||||
minZoom: 2,
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 2, zoom: 2
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view zoom is greater than minZoom',
|
||||
minZoom: 2,
|
||||
view: {
|
||||
resolution: 3, zoom: 3
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view zoom is greater than minZoom (with maxZoom)',
|
||||
minZoom: 2,
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 3, zoom: 3
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view zoom is equal to maxZoom',
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 4, zoom: 4
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view zoom is equal to maxZoom (with minZoom)',
|
||||
minZoom: 2,
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 4, zoom: 4
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view zoom is greater than maxZoom',
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 5, zoom: 5
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view zoom is greater than maxZoom (with minZoom)',
|
||||
minZoom: 2,
|
||||
maxZoom: 4,
|
||||
view: {
|
||||
resolution: 5, zoom: 5
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view resolution is less than minResolution',
|
||||
minResolution: 2,
|
||||
view: {
|
||||
resolution: 1, zoom: 1
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view resolution is less than minResolution (with maxResolution)',
|
||||
minResolution: 2,
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 1, zoom: 1
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view resolution is equal to minResolution',
|
||||
minResolution: 2,
|
||||
view: {
|
||||
resolution: 2, zoom: 2
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view resolution is equal to minResolution (with maxResolution)',
|
||||
minResolution: 2,
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 2, zoom: 2
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view resolution is greater than minResolution',
|
||||
minResolution: 2,
|
||||
view: {
|
||||
resolution: 3, zoom: 3
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view resolution is greater than minResolution (with maxResolution)',
|
||||
minResolution: 2,
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 3, zoom: 3
|
||||
},
|
||||
inView: true
|
||||
}, {
|
||||
when: 'view resolution is equal to maxResolution',
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 4, zoom: 4
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view resolution is equal to maxResolution (with minResolution)',
|
||||
minResolution: 2,
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 4, zoom: 4
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view resolution is greater than maxResolution',
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 5, zoom: 5
|
||||
},
|
||||
inView: false
|
||||
}, {
|
||||
when: 'view resolution is greater than maxResolution (with minResolution)',
|
||||
minResolution: 2,
|
||||
maxResolution: 4,
|
||||
view: {
|
||||
resolution: 5, zoom: 5
|
||||
},
|
||||
inView: false
|
||||
}];
|
||||
|
||||
it('returns false if resolution lower than minResolution', function() {
|
||||
layer.setVisible(true);
|
||||
layer.setMinResolution(3);
|
||||
layer.setMaxResolution(5);
|
||||
const layerState = layer.getLayerState();
|
||||
expect(visibleAtResolution(layerState, 2)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false if resolution greater than maxResolution', function() {
|
||||
layer.setVisible(true);
|
||||
layer.setMinResolution(3);
|
||||
layer.setMaxResolution(5);
|
||||
const layerState = layer.getLayerState();
|
||||
expect(visibleAtResolution(layerState, 6)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true otherwise', function() {
|
||||
layer.setVisible(true);
|
||||
layer.setMinResolution(3);
|
||||
layer.setMaxResolution(5);
|
||||
const layerState = layer.getLayerState();
|
||||
expect(visibleAtResolution(layerState, 4)).to.be(true);
|
||||
cases.forEach(function(c, i) {
|
||||
it('returns ' + c.inView + ' when ' + c.when, function() {
|
||||
if ('visible' in c) {
|
||||
layer.setVisible(c.visible);
|
||||
}
|
||||
if ('minZoom' in c) {
|
||||
layer.setMinZoom(c.minZoom);
|
||||
}
|
||||
if ('maxZoom' in c) {
|
||||
layer.setMaxZoom(c.maxZoom);
|
||||
}
|
||||
if ('minResolution' in c) {
|
||||
layer.setMinResolution(c.minResolution);
|
||||
}
|
||||
if ('maxResolution' in c) {
|
||||
layer.setMaxResolution(c.maxResolution);
|
||||
}
|
||||
const layerState = layer.getLayerState();
|
||||
expect(inView(layerState, c.view)).to.be(c.inView);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -189,40 +365,24 @@ describe('ol.layer.Layer', function() {
|
||||
extent: undefined,
|
||||
zIndex: 10,
|
||||
maxResolution: 500,
|
||||
minResolution: 0.25
|
||||
minResolution: 0.25,
|
||||
minZoom: -Infinity,
|
||||
maxZoom: Infinity
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a layerState with clamped values', function() {
|
||||
layer.setOpacity(-1.5);
|
||||
layer.setVisible(false);
|
||||
expect(layer.getLayerState()).to.eql({
|
||||
layer: layer,
|
||||
opacity: 0,
|
||||
visible: false,
|
||||
managed: true,
|
||||
hasOverlay: false,
|
||||
sourceState: 'ready',
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: Infinity,
|
||||
minResolution: 0
|
||||
});
|
||||
let state = layer.getLayerState();
|
||||
expect(state.opacity).to.be(0);
|
||||
expect(state.visible).to.be(false);
|
||||
|
||||
layer.setOpacity(3);
|
||||
layer.setVisible(true);
|
||||
expect(layer.getLayerState()).to.eql({
|
||||
layer: layer,
|
||||
opacity: 1,
|
||||
visible: true,
|
||||
managed: true,
|
||||
hasOverlay: false,
|
||||
sourceState: 'ready',
|
||||
extent: undefined,
|
||||
zIndex: 0,
|
||||
maxResolution: Infinity,
|
||||
minResolution: 0
|
||||
});
|
||||
state = layer.getLayerState();
|
||||
expect(state.opacity).to.be(1);
|
||||
expect(state.visible).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user