Add new tests for View & Interaction w/ fixes
This commit is contained in:
@@ -128,7 +128,7 @@ describe('ol.interaction.Interaction', function() {
|
||||
expect(view.getCenter()).to.eql([10, 10]);
|
||||
});
|
||||
|
||||
it('changes view resolution and center relative to the anchor, while respecting the extent', function() {
|
||||
it('changes view resolution and center relative to the anchor, while respecting the extent (center only)', function() {
|
||||
const view = new View({
|
||||
center: [0, 0],
|
||||
extent: [-2.5, -2.5, 2.5, 2.5],
|
||||
@@ -149,6 +149,50 @@ describe('ol.interaction.Interaction', function() {
|
||||
zoomByDelta(view, -2, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([2.5, 2.5]);
|
||||
});
|
||||
|
||||
it('changes view resolution and center relative to the anchor, while respecting the extent', function() {
|
||||
const map = new Map({});
|
||||
const view = new View({
|
||||
center: [50, 50],
|
||||
extent: [0, 0, 100, 100],
|
||||
resolution: 1,
|
||||
resolutions: [4, 2, 1, 0.5, 0.25, 0.125]
|
||||
});
|
||||
map.setView(view);
|
||||
|
||||
zoomByDelta(view, 1, [100, 100]);
|
||||
expect(view.getCenter()).to.eql([75, 75]);
|
||||
|
||||
zoomByDelta(view, -1, [75, 75]);
|
||||
expect(view.getCenter()).to.eql([50, 50]);
|
||||
|
||||
zoomByDelta(view, 2, [100, 100]);
|
||||
expect(view.getCenter()).to.eql([87.5, 87.5]);
|
||||
|
||||
zoomByDelta(view, -3, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([50, 50]);
|
||||
expect(view.getResolution()).to.eql(2);
|
||||
});
|
||||
|
||||
it('changes view resolution and center relative to the anchor, while respecting the extent (rotated)', function() {
|
||||
const map = new Map({});
|
||||
const view = new View({
|
||||
center: [50, 50],
|
||||
extent: [-100, -100, 100, 100],
|
||||
resolution: 1,
|
||||
resolutions: [2, 1, 0.5, 0.25, 0.125],
|
||||
rotation: Math.PI / 4
|
||||
});
|
||||
map.setView(view);
|
||||
const halfSize = 100 * Math.SQRT1_2;
|
||||
|
||||
zoomByDelta(view, 1, [100, 100]);
|
||||
expect(view.getCenter()).to.eql([100 - halfSize / 2, 100 - halfSize / 2]);
|
||||
|
||||
view.setCenter([0, 50]);
|
||||
zoomByDelta(view, -1, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([0, 100 - halfSize]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user