View / add a method to compute a valid zoom level
The `getValidZoomLevel` apply the current resolution constraint to return a value that is guaranteed valid. This is used for interactions & controls which need a target value to work: the +/- buttons, the zoom clider, the dragbox zoom and the mouse wheel zoom.
This commit is contained in:
@@ -1439,6 +1439,35 @@ describe('ol.View', function() {
|
||||
expect(view.getHints()[1]).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getValidZoomLevel()', function() {
|
||||
let view;
|
||||
|
||||
it('works correctly without constraint', function() {
|
||||
view = new View({
|
||||
zoom: 0
|
||||
});
|
||||
expect(view.getValidZoomLevel(3)).to.be(3);
|
||||
});
|
||||
it('works correctly with resolution constraints', function() {
|
||||
view = new View({
|
||||
zoom: 4,
|
||||
minZoom: 4,
|
||||
maxZoom: 8
|
||||
});
|
||||
expect(view.getValidZoomLevel(3)).to.be(4);
|
||||
expect(view.getValidZoomLevel(10)).to.be(8);
|
||||
});
|
||||
it('works correctly with a specific resolution set', function() {
|
||||
view = new View({
|
||||
zoom: 0,
|
||||
resolutions: [512, 256, 128, 64, 32, 16, 8]
|
||||
});
|
||||
expect(view.getValidZoomLevel(0)).to.be(0);
|
||||
expect(view.getValidZoomLevel(4)).to.be(4);
|
||||
expect(view.getValidZoomLevel(8)).to.be(6);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.View.isNoopAnimation()', function() {
|
||||
|
||||
Reference in New Issue
Block a user