Constrain the center in zoomByDelta

This commit is contained in:
Thomas Chandelle
2017-01-05 14:43:54 +01:00
parent 23960d086d
commit 395d833dd6
2 changed files with 80 additions and 0 deletions

View File

@@ -58,4 +58,67 @@ describe('ol.interaction.Interaction', function() {
});
describe('zoomByDelta()', function() {
it('changes view resolution', function() {
var view = new ol.View({
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
ol.interaction.Interaction.zoomByDelta(view, 1);
expect(view.getResolution()).to.be(0.5);
ol.interaction.Interaction.zoomByDelta(view, -1);
expect(view.getResolution()).to.be(1);
ol.interaction.Interaction.zoomByDelta(view, 2);
expect(view.getResolution()).to.be(0.25);
ol.interaction.Interaction.zoomByDelta(view, -2);
expect(view.getResolution()).to.be(1);
});
it('changes view resolution and center relative to the anchor', function() {
var view = new ol.View({
center: [0, 0],
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
ol.interaction.Interaction.zoomByDelta(view, 1, [10, 10]);
expect(view.getCenter()).to.eql([5, 5]);
ol.interaction.Interaction.zoomByDelta(view, -1, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]);
ol.interaction.Interaction.zoomByDelta(view, 2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
ol.interaction.Interaction.zoomByDelta(view, -2, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]);
});
it('changes view resolution and center relative to the anchor, while respecting the extent', function() {
var view = new ol.View({
center: [0, 0],
extent: [-2.5, -2.5, 2.5, 2.5],
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
ol.interaction.Interaction.zoomByDelta(view, 1, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
ol.interaction.Interaction.zoomByDelta(view, -1, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
ol.interaction.Interaction.zoomByDelta(view, 2, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
ol.interaction.Interaction.zoomByDelta(view, -2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
});
});
});