Merge pull request #9137 from jahow/add-view-constrain-extent-2

Refactor the way view constraints are handled & add a view extent constraint
This commit is contained in:
Andreas Hocevar
2019-03-11 10:38:31 +01:00
committed by GitHub
32 changed files with 1304 additions and 839 deletions

View File

@@ -62,13 +62,18 @@ describe('ol.interaction.DragRotateAndZoom', function() {
true);
interaction.lastAngle_ = Math.PI;
let view = map.getView();
let spy = sinon.spy(view, 'rotate');
interaction.handleDragEvent(event);
expect(spy.callCount).to.be(1);
expect(interaction.lastAngle_).to.be(-0.8308214428190254);
view.rotate.restore();
let callCount = 0;
let view = map.getView();
view.on('change:rotation', function() {
callCount++;
});
interaction.handleDragEvent(event);
expect(callCount).to.be(1);
expect(interaction.lastAngle_).to.be(-0.8308214428190254);
callCount = 0;
view = new View({
projection: 'EPSG:4326',
center: [0, 0],
@@ -76,15 +81,16 @@ describe('ol.interaction.DragRotateAndZoom', function() {
enableRotation: false
});
map.setView(view);
view.on('change:rotation', function() {
callCount++;
});
event = new MapBrowserPointerEvent('pointermove', map,
new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}),
true);
spy = sinon.spy(view, 'rotate');
interaction.handleDragEvent(event);
expect(spy.callCount).to.be(0);
view.rotate.restore();
expect(callCount).to.be(0);
});
});

View File

@@ -103,7 +103,7 @@ describe('ol.interaction.DragZoom', function() {
setTimeout(function() {
const view = map.getView();
const resolution = view.getResolution();
expect(resolution).to.eql(view.constrainResolution(0.5));
expect(resolution).to.eql(view.getConstrainedResolution(0.5));
done();
}, 50);
}, 50);

View File

@@ -1,7 +1,6 @@
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import EventTarget from '../../../../src/ol/events/Target.js';
import Interaction, {zoomByDelta} from '../../../../src/ol/interaction/Interaction.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
import {FALSE} from '../../../../src/ol/functions.js';
describe('ol.interaction.Interaction', function() {
@@ -87,67 +86,4 @@ describe('ol.interaction.Interaction', function() {
});
describe('zoomByDelta()', function() {
it('changes view resolution', function() {
const view = new View({
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
zoomByDelta(view, 1);
expect(view.getResolution()).to.be(0.5);
zoomByDelta(view, -1);
expect(view.getResolution()).to.be(1);
zoomByDelta(view, 2);
expect(view.getResolution()).to.be(0.25);
zoomByDelta(view, -2);
expect(view.getResolution()).to.be(1);
});
it('changes view resolution and center relative to the anchor', function() {
const view = new View({
center: [0, 0],
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
zoomByDelta(view, 1, [10, 10]);
expect(view.getCenter()).to.eql([5, 5]);
zoomByDelta(view, -1, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]);
zoomByDelta(view, 2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
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() {
const view = new View({
center: [0, 0],
extent: [-2.5, -2.5, 2.5, 2.5],
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
zoomByDelta(view, 1, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
zoomByDelta(view, -1, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
zoomByDelta(view, 2, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
zoomByDelta(view, -2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
});
});
});

View File

@@ -565,7 +565,6 @@ describe('ol.Map', function() {
const interactions = defaultInteractions(options);
expect(interactions.getLength()).to.eql(1);
expect(interactions.item(0)).to.be.a(MouseWheelZoom);
expect(interactions.item(0).constrainResolution_).to.eql(false);
expect(interactions.item(0).useAnchor_).to.eql(true);
interactions.item(0).setMouseAnchor(false);
expect(interactions.item(0).useAnchor_).to.eql(false);
@@ -601,21 +600,6 @@ describe('ol.Map', function() {
const interactions = defaultInteractions(options);
expect(interactions.getLength()).to.eql(1);
expect(interactions.item(0)).to.be.a(PinchZoom);
expect(interactions.item(0).constrainResolution_).to.eql(false);
});
});
describe('set constrainResolution option', function() {
it('set constrainResolution option', function() {
options.pinchZoom = true;
options.mouseWheelZoom = true;
options.constrainResolution = true;
const interactions = defaultInteractions(options);
expect(interactions.getLength()).to.eql(2);
expect(interactions.item(0)).to.be.a(PinchZoom);
expect(interactions.item(0).constrainResolution_).to.eql(true);
expect(interactions.item(1)).to.be.a(MouseWheelZoom);
expect(interactions.item(1).constrainResolution_).to.eql(true);
});
});

View File

@@ -1,4 +1,5 @@
import {createSnapToResolutions, createSnapToPower} from '../../../src/ol/resolutionconstraint.js';
import {createMinMaxResolution} from '../../../src/ol/resolutionconstraint';
describe('ol.resolutionconstraint', function() {
@@ -12,30 +13,30 @@ describe('ol.resolutionconstraint', function() {
[1000, 500, 250, 100]);
});
describe('delta 0', function() {
describe('direction 0', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1000, 0, 0)).to.eql(1000);
expect(resolutionConstraint(500, 0, 0)).to.eql(500);
expect(resolutionConstraint(250, 0, 0)).to.eql(250);
expect(resolutionConstraint(100, 0, 0)).to.eql(100);
expect(resolutionConstraint(1000, 0)).to.eql(1000);
expect(resolutionConstraint(500, 0)).to.eql(500);
expect(resolutionConstraint(250, 0)).to.eql(250);
expect(resolutionConstraint(100, 0)).to.eql(100);
});
});
describe('zoom in', function() {
describe('direction 1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1000, 1, 0)).to.eql(500);
expect(resolutionConstraint(500, 1, 0)).to.eql(250);
expect(resolutionConstraint(250, 1, 0)).to.eql(100);
expect(resolutionConstraint(100, 1, 0)).to.eql(100);
expect(resolutionConstraint(1000, 1)).to.eql(1000);
expect(resolutionConstraint(500, 1)).to.eql(500);
expect(resolutionConstraint(250, 1)).to.eql(250);
expect(resolutionConstraint(100, 1)).to.eql(100);
});
});
describe('zoom out', function() {
describe('direction -1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1000, -1, 0)).to.eql(1000);
expect(resolutionConstraint(500, -1, 0)).to.eql(1000);
expect(resolutionConstraint(250, -1, 0)).to.eql(500);
expect(resolutionConstraint(100, -1, 0)).to.eql(250);
expect(resolutionConstraint(1000, -1)).to.eql(1000);
expect(resolutionConstraint(500, -1)).to.eql(500);
expect(resolutionConstraint(250, -1)).to.eql(250);
expect(resolutionConstraint(100, -1)).to.eql(100);
});
});
});
@@ -50,42 +51,42 @@ describe('ol.resolutionconstraint', function() {
[1000, 500, 250, 100]);
});
describe('delta 0', function() {
describe('direction 0', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, 0, 0)).to.eql(1000);
expect(resolutionConstraint(950, 0, 0)).to.eql(1000);
expect(resolutionConstraint(550, 0, 0)).to.eql(500);
expect(resolutionConstraint(400, 0, 0)).to.eql(500);
expect(resolutionConstraint(300, 0, 0)).to.eql(250);
expect(resolutionConstraint(200, 0, 0)).to.eql(250);
expect(resolutionConstraint(150, 0, 0)).to.eql(100);
expect(resolutionConstraint(50, 0, 0)).to.eql(100);
expect(resolutionConstraint(1050, 0)).to.eql(1000);
expect(resolutionConstraint(950, 0)).to.eql(1000);
expect(resolutionConstraint(550, 0)).to.eql(500);
expect(resolutionConstraint(400, 0)).to.eql(500);
expect(resolutionConstraint(300, 0)).to.eql(250);
expect(resolutionConstraint(200, 0)).to.eql(250);
expect(resolutionConstraint(150, 0)).to.eql(100);
expect(resolutionConstraint(50, 0)).to.eql(100);
});
});
describe('zoom in', function() {
describe('direction 1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, 1, 0)).to.eql(500);
expect(resolutionConstraint(950, 1, 0)).to.eql(500);
expect(resolutionConstraint(550, 1, 0)).to.eql(250);
expect(resolutionConstraint(450, 1, 0)).to.eql(250);
expect(resolutionConstraint(300, 1, 0)).to.eql(100);
expect(resolutionConstraint(200, 1, 0)).to.eql(100);
expect(resolutionConstraint(150, 1, 0)).to.eql(100);
expect(resolutionConstraint(50, 1, 0)).to.eql(100);
expect(resolutionConstraint(1050, 1)).to.eql(1000);
expect(resolutionConstraint(950, 1)).to.eql(1000);
expect(resolutionConstraint(550, 1)).to.eql(1000);
expect(resolutionConstraint(450, 1)).to.eql(500);
expect(resolutionConstraint(300, 1)).to.eql(500);
expect(resolutionConstraint(200, 1)).to.eql(250);
expect(resolutionConstraint(150, 1)).to.eql(250);
expect(resolutionConstraint(50, 1)).to.eql(100);
});
});
describe('zoom out', function() {
describe('direction -1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, -1, 0)).to.eql(1000);
expect(resolutionConstraint(950, -1, 0)).to.eql(1000);
expect(resolutionConstraint(550, -1, 0)).to.eql(1000);
expect(resolutionConstraint(450, -1, 0)).to.eql(1000);
expect(resolutionConstraint(300, -1, 0)).to.eql(500);
expect(resolutionConstraint(200, -1, 0)).to.eql(500);
expect(resolutionConstraint(150, -1, 0)).to.eql(250);
expect(resolutionConstraint(50, -1, 0)).to.eql(250);
expect(resolutionConstraint(1050, -1)).to.eql(1000);
expect(resolutionConstraint(950, -1)).to.eql(500);
expect(resolutionConstraint(550, -1)).to.eql(500);
expect(resolutionConstraint(450, -1)).to.eql(250);
expect(resolutionConstraint(300, -1)).to.eql(250);
expect(resolutionConstraint(200, -1)).to.eql(100);
expect(resolutionConstraint(150, -1)).to.eql(100);
expect(resolutionConstraint(50, -1)).to.eql(100);
});
});
});
@@ -96,54 +97,54 @@ describe('ol.resolutionconstraint', function() {
beforeEach(function() {
resolutionConstraint =
createSnapToPower(2, 1024, 10);
createSnapToPower(2, 1024, 1);
});
describe('delta 0', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1024, 0, 0)).to.eql(1024);
expect(resolutionConstraint(512, 0, 0)).to.eql(512);
expect(resolutionConstraint(256, 0, 0)).to.eql(256);
expect(resolutionConstraint(128, 0, 0)).to.eql(128);
expect(resolutionConstraint(64, 0, 0)).to.eql(64);
expect(resolutionConstraint(32, 0, 0)).to.eql(32);
expect(resolutionConstraint(16, 0, 0)).to.eql(16);
expect(resolutionConstraint(8, 0, 0)).to.eql(8);
expect(resolutionConstraint(4, 0, 0)).to.eql(4);
expect(resolutionConstraint(2, 0, 0)).to.eql(2);
expect(resolutionConstraint(1, 0, 0)).to.eql(1);
expect(resolutionConstraint(1024, 0)).to.eql(1024);
expect(resolutionConstraint(512, 0)).to.eql(512);
expect(resolutionConstraint(256, 0)).to.eql(256);
expect(resolutionConstraint(128, 0)).to.eql(128);
expect(resolutionConstraint(64, 0)).to.eql(64);
expect(resolutionConstraint(32, 0)).to.eql(32);
expect(resolutionConstraint(16, 0)).to.eql(16);
expect(resolutionConstraint(8, 0)).to.eql(8);
expect(resolutionConstraint(4, 0)).to.eql(4);
expect(resolutionConstraint(2, 0)).to.eql(2);
expect(resolutionConstraint(1, 0)).to.eql(1);
});
});
describe('zoom in', function() {
describe('direction 1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1024, 1, 0)).to.eql(512);
expect(resolutionConstraint(512, 1, 0)).to.eql(256);
expect(resolutionConstraint(256, 1, 0)).to.eql(128);
expect(resolutionConstraint(128, 1, 0)).to.eql(64);
expect(resolutionConstraint(64, 1, 0)).to.eql(32);
expect(resolutionConstraint(32, 1, 0)).to.eql(16);
expect(resolutionConstraint(16, 1, 0)).to.eql(8);
expect(resolutionConstraint(8, 1, 0)).to.eql(4);
expect(resolutionConstraint(4, 1, 0)).to.eql(2);
expect(resolutionConstraint(2, 1, 0)).to.eql(1);
expect(resolutionConstraint(1, 1, 0)).to.eql(1);
expect(resolutionConstraint(1024, 1)).to.eql(1024);
expect(resolutionConstraint(512, 1)).to.eql(512);
expect(resolutionConstraint(256, 1)).to.eql(256);
expect(resolutionConstraint(128, 1)).to.eql(128);
expect(resolutionConstraint(64, 1)).to.eql(64);
expect(resolutionConstraint(32, 1)).to.eql(32);
expect(resolutionConstraint(16, 1)).to.eql(16);
expect(resolutionConstraint(8, 1)).to.eql(8);
expect(resolutionConstraint(4, 1)).to.eql(4);
expect(resolutionConstraint(2, 1)).to.eql(2);
expect(resolutionConstraint(1, 1)).to.eql(1);
});
});
describe('zoom out', function() {
describe('direction -1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1024, -1, 0)).to.eql(1024);
expect(resolutionConstraint(512, -1, 0)).to.eql(1024);
expect(resolutionConstraint(256, -1, 0)).to.eql(512);
expect(resolutionConstraint(128, -1, 0)).to.eql(256);
expect(resolutionConstraint(64, -1, 0)).to.eql(128);
expect(resolutionConstraint(32, -1, 0)).to.eql(64);
expect(resolutionConstraint(16, -1, 0)).to.eql(32);
expect(resolutionConstraint(8, -1, 0)).to.eql(16);
expect(resolutionConstraint(4, -1, 0)).to.eql(8);
expect(resolutionConstraint(2, -1, 0)).to.eql(4);
expect(resolutionConstraint(1, -1, 0)).to.eql(2);
expect(resolutionConstraint(1024, -1)).to.eql(1024);
expect(resolutionConstraint(512, -1)).to.eql(512);
expect(resolutionConstraint(256, -1)).to.eql(256);
expect(resolutionConstraint(128, -1)).to.eql(128);
expect(resolutionConstraint(64, -1)).to.eql(64);
expect(resolutionConstraint(32, -1)).to.eql(32);
expect(resolutionConstraint(16, -1)).to.eql(16);
expect(resolutionConstraint(8, -1)).to.eql(8);
expect(resolutionConstraint(4, -1)).to.eql(4);
expect(resolutionConstraint(2, -1)).to.eql(2);
expect(resolutionConstraint(1, -1)).to.eql(1);
});
});
});
@@ -154,88 +155,182 @@ describe('ol.resolutionconstraint', function() {
beforeEach(function() {
resolutionConstraint =
createSnapToPower(2, 1024, 10);
createSnapToPower(2, 1024, 1);
});
describe('delta 0, direction 0', function() {
describe('direction 0', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, 0, 0)).to.eql(1024);
expect(resolutionConstraint(9050, 0, 0)).to.eql(1024);
expect(resolutionConstraint(550, 0, 0)).to.eql(512);
expect(resolutionConstraint(450, 0, 0)).to.eql(512);
expect(resolutionConstraint(300, 0, 0)).to.eql(256);
expect(resolutionConstraint(250, 0, 0)).to.eql(256);
expect(resolutionConstraint(150, 0, 0)).to.eql(128);
expect(resolutionConstraint(100, 0, 0)).to.eql(128);
expect(resolutionConstraint(75, 0, 0)).to.eql(64);
expect(resolutionConstraint(50, 0, 0)).to.eql(64);
expect(resolutionConstraint(40, 0, 0)).to.eql(32);
expect(resolutionConstraint(30, 0, 0)).to.eql(32);
expect(resolutionConstraint(20, 0, 0)).to.eql(16);
expect(resolutionConstraint(12, 0, 0)).to.eql(16);
expect(resolutionConstraint(9, 0, 0)).to.eql(8);
expect(resolutionConstraint(7, 0, 0)).to.eql(8);
expect(resolutionConstraint(5, 0, 0)).to.eql(4);
expect(resolutionConstraint(3.5, 0, 0)).to.eql(4);
expect(resolutionConstraint(2.1, 0, 0)).to.eql(2);
expect(resolutionConstraint(1.9, 0, 0)).to.eql(2);
expect(resolutionConstraint(1.1, 0, 0)).to.eql(1);
expect(resolutionConstraint(0.9, 0, 0)).to.eql(1);
expect(resolutionConstraint(1050, 0)).to.eql(1024);
expect(resolutionConstraint(9050, 0)).to.eql(1024);
expect(resolutionConstraint(550, 0)).to.eql(512);
expect(resolutionConstraint(450, 0)).to.eql(512);
expect(resolutionConstraint(300, 0)).to.eql(256);
expect(resolutionConstraint(250, 0)).to.eql(256);
expect(resolutionConstraint(150, 0)).to.eql(128);
expect(resolutionConstraint(100, 0)).to.eql(128);
expect(resolutionConstraint(75, 0)).to.eql(64);
expect(resolutionConstraint(50, 0)).to.eql(64);
expect(resolutionConstraint(40, 0)).to.eql(32);
expect(resolutionConstraint(30, 0)).to.eql(32);
expect(resolutionConstraint(20, 0)).to.eql(16);
expect(resolutionConstraint(12, 0)).to.eql(16);
expect(resolutionConstraint(9, 0)).to.eql(8);
expect(resolutionConstraint(7, 0)).to.eql(8);
expect(resolutionConstraint(5, 0)).to.eql(4);
expect(resolutionConstraint(3.5, 0)).to.eql(4);
expect(resolutionConstraint(2.1, 0)).to.eql(2);
expect(resolutionConstraint(1.9, 0)).to.eql(2);
expect(resolutionConstraint(1.1, 0)).to.eql(1);
expect(resolutionConstraint(0.9, 0)).to.eql(1);
});
});
describe('delta 0, direction > 0', function() {
describe('direction 1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, 0, 1)).to.eql(1024);
expect(resolutionConstraint(9050, 0, 1)).to.eql(1024);
expect(resolutionConstraint(550, 0, 1)).to.eql(1024);
expect(resolutionConstraint(450, 0, 1)).to.eql(512);
expect(resolutionConstraint(300, 0, 1)).to.eql(512);
expect(resolutionConstraint(250, 0, 1)).to.eql(256);
expect(resolutionConstraint(150, 0, 1)).to.eql(256);
expect(resolutionConstraint(100, 0, 1)).to.eql(128);
expect(resolutionConstraint(75, 0, 1)).to.eql(128);
expect(resolutionConstraint(50, 0, 1)).to.eql(64);
expect(resolutionConstraint(40, 0, 1)).to.eql(64);
expect(resolutionConstraint(30, 0, 1)).to.eql(32);
expect(resolutionConstraint(20, 0, 1)).to.eql(32);
expect(resolutionConstraint(12, 0, 1)).to.eql(16);
expect(resolutionConstraint(9, 0, 1)).to.eql(16);
expect(resolutionConstraint(7, 0, 1)).to.eql(8);
expect(resolutionConstraint(5, 0, 1)).to.eql(8);
expect(resolutionConstraint(3.5, 0, 1)).to.eql(4);
expect(resolutionConstraint(2.1, 0, 1)).to.eql(4);
expect(resolutionConstraint(1.9, 0, 1)).to.eql(2);
expect(resolutionConstraint(1.1, 0, 1)).to.eql(2);
expect(resolutionConstraint(0.9, 0, 1)).to.eql(1);
expect(resolutionConstraint(1050, 1)).to.eql(1024);
expect(resolutionConstraint(9050, 1)).to.eql(1024);
expect(resolutionConstraint(550, 1)).to.eql(1024);
expect(resolutionConstraint(450, 1)).to.eql(512);
expect(resolutionConstraint(300, 1)).to.eql(512);
expect(resolutionConstraint(250, 1)).to.eql(256);
expect(resolutionConstraint(150, 1)).to.eql(256);
expect(resolutionConstraint(100, 1)).to.eql(128);
expect(resolutionConstraint(75, 1)).to.eql(128);
expect(resolutionConstraint(50, 1)).to.eql(64);
expect(resolutionConstraint(40, 1)).to.eql(64);
expect(resolutionConstraint(30, 1)).to.eql(32);
expect(resolutionConstraint(20, 1)).to.eql(32);
expect(resolutionConstraint(12, 1)).to.eql(16);
expect(resolutionConstraint(9, 1)).to.eql(16);
expect(resolutionConstraint(7, 1)).to.eql(8);
expect(resolutionConstraint(5, 1)).to.eql(8);
expect(resolutionConstraint(3.5, 1)).to.eql(4);
expect(resolutionConstraint(2.1, 1)).to.eql(4);
expect(resolutionConstraint(1.9, 1)).to.eql(2);
expect(resolutionConstraint(1.1, 1)).to.eql(2);
expect(resolutionConstraint(0.9, 1)).to.eql(1);
});
});
describe('delta 0, direction < 0', function() {
describe('direction -1', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, 0, -1)).to.eql(1024);
expect(resolutionConstraint(9050, 0, -1)).to.eql(1024);
expect(resolutionConstraint(550, 0, -1)).to.eql(512);
expect(resolutionConstraint(450, 0, -1)).to.eql(256);
expect(resolutionConstraint(300, 0, -1)).to.eql(256);
expect(resolutionConstraint(250, 0, -1)).to.eql(128);
expect(resolutionConstraint(150, 0, -1)).to.eql(128);
expect(resolutionConstraint(100, 0, -1)).to.eql(64);
expect(resolutionConstraint(75, 0, -1)).to.eql(64);
expect(resolutionConstraint(50, 0, -1)).to.eql(32);
expect(resolutionConstraint(40, 0, -1)).to.eql(32);
expect(resolutionConstraint(30, 0, -1)).to.eql(16);
expect(resolutionConstraint(20, 0, -1)).to.eql(16);
expect(resolutionConstraint(12, 0, -1)).to.eql(8);
expect(resolutionConstraint(9, 0, -1)).to.eql(8);
expect(resolutionConstraint(7, 0, -1)).to.eql(4);
expect(resolutionConstraint(5, 0, -1)).to.eql(4);
expect(resolutionConstraint(3.5, 0, -1)).to.eql(2);
expect(resolutionConstraint(2.1, 0, -1)).to.eql(2);
expect(resolutionConstraint(1.9, 0, -1)).to.eql(1);
expect(resolutionConstraint(1.1, 0, -1)).to.eql(1);
expect(resolutionConstraint(0.9, 0, -1)).to.eql(1);
expect(resolutionConstraint(1050, -1)).to.eql(1024);
expect(resolutionConstraint(9050, -1)).to.eql(1024);
expect(resolutionConstraint(550, -1)).to.eql(512);
expect(resolutionConstraint(450, -1)).to.eql(256);
expect(resolutionConstraint(300, -1)).to.eql(256);
expect(resolutionConstraint(250, -1)).to.eql(128);
expect(resolutionConstraint(150, -1)).to.eql(128);
expect(resolutionConstraint(100, -1)).to.eql(64);
expect(resolutionConstraint(75, -1)).to.eql(64);
expect(resolutionConstraint(50, -1)).to.eql(32);
expect(resolutionConstraint(40, -1)).to.eql(32);
expect(resolutionConstraint(30, -1)).to.eql(16);
expect(resolutionConstraint(20, -1)).to.eql(16);
expect(resolutionConstraint(12, -1)).to.eql(8);
expect(resolutionConstraint(9, -1)).to.eql(8);
expect(resolutionConstraint(7, -1)).to.eql(4);
expect(resolutionConstraint(5, -1)).to.eql(4);
expect(resolutionConstraint(3.5, -1)).to.eql(2);
expect(resolutionConstraint(2.1, -1)).to.eql(2);
expect(resolutionConstraint(1.9, -1)).to.eql(1);
expect(resolutionConstraint(1.1, -1)).to.eql(1);
expect(resolutionConstraint(0.9, -1)).to.eql(1);
});
});
});
describe('SnapToPower smooth constraint', function() {
describe('snap to power, smooth constraint on', function() {
it('returns expected resolution value', function() {
const resolutionConstraint = createSnapToPower(2, 128, 16, true);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.be.lessThan(130);
expect(resolutionConstraint(128, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(16, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.be.greaterThan(15);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.be.lessThan(16);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.be.greaterThan(10);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.be.lessThan(16);
});
});
describe('snap to power, smooth constraint off', function() {
it('returns expected resolution value', function() {
const resolutionConstraint = createSnapToPower(2, 128, 16, false);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(128, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(16, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.eql(16);
});
});
describe('snap to resolutions, smooth constraint on', function() {
it('returns expected resolution value', function() {
const resolutionConstraint = createSnapToResolutions([128, 64, 32, 16], true);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.be.lessThan(130);
expect(resolutionConstraint(128, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(16, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.be.greaterThan(15);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.be.lessThan(16);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.be.greaterThan(10);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.be.lessThan(16);
});
});
describe('snap to resolutions, smooth constraint off', function() {
it('returns expected resolution value', function() {
const resolutionConstraint = createSnapToResolutions([128, 64, 32, 16], false);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(128, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(16, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.eql(16);
});
});
describe('min/max, smooth constraint on', function() {
it('returns expected resolution value', function() {
const resolutionConstraint = createMinMaxResolution(128, 16, true);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.be.lessThan(130);
expect(resolutionConstraint(128, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(16, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.be.greaterThan(15);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.be.lessThan(16);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.be.greaterThan(10);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.be.lessThan(16);
});
});
describe('min/max, smooth constraint off', function() {
it('returns expected resolution value', function() {
const resolutionConstraint = createMinMaxResolution(128, 16, false);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(128, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(16, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(15, 0, [100, 100], true)).to.eql(16);
expect(resolutionConstraint(10, 0, [100, 100], true)).to.eql(16);
});
});
});
});

View File

@@ -8,27 +8,15 @@ describe('ol.rotationconstraint', function() {
it('returns expected rotation value', function() {
const rotationConstraint = createSnapToZero(0.3);
expect(rotationConstraint(0.1, 0)).to.eql(0);
expect(rotationConstraint(0.2, 0)).to.eql(0);
expect(rotationConstraint(0.3, 0)).to.eql(0);
expect(rotationConstraint(0.4, 0)).to.eql(0.4);
expect(rotationConstraint(0.1)).to.eql(0);
expect(rotationConstraint(0.2)).to.eql(0);
expect(rotationConstraint(0.3)).to.eql(0);
expect(rotationConstraint(0.4)).to.eql(0.4);
expect(rotationConstraint(-0.1, 0)).to.eql(0);
expect(rotationConstraint(-0.2, 0)).to.eql(0);
expect(rotationConstraint(-0.3, 0)).to.eql(0);
expect(rotationConstraint(-0.4, 0)).to.eql(-0.4);
expect(rotationConstraint(1, -0.9)).to.eql(0);
expect(rotationConstraint(1, -0.8)).to.eql(0);
// floating-point arithmetic
expect(rotationConstraint(1, -0.7)).not.to.eql(0);
expect(rotationConstraint(1, -0.6)).to.eql(0.4);
expect(rotationConstraint(-1, 0.9)).to.eql(0);
expect(rotationConstraint(-1, 0.8)).to.eql(0);
// floating-point arithmetic
expect(rotationConstraint(-1, 0.7)).not.to.eql(0);
expect(rotationConstraint(-1, 0.6)).to.eql(-0.4);
expect(rotationConstraint(-0.1)).to.eql(0);
expect(rotationConstraint(-0.2)).to.eql(0);
expect(rotationConstraint(-0.3)).to.eql(0);
expect(rotationConstraint(-0.4)).to.eql(-0.4);
});
});

View File

@@ -42,15 +42,36 @@ describe('ol.View', function() {
});
});
describe('with extent option and center only', function() {
it('gives a correct center constraint function', function() {
const options = {
extent: [0, 0, 1, 1],
constrainOnlyCenter: true
};
const fn = createCenterConstraint(options);
expect(fn([0, 0])).to.eql([0, 0]);
expect(fn([-10, 0])).to.eql([0, 0]);
expect(fn([100, 100])).to.eql([1, 1]);
});
});
describe('with extent option', function() {
it('gives a correct center constraint function', function() {
const options = {
extent: [0, 0, 1, 1]
};
const fn = createCenterConstraint(options);
expect(fn([0, 0])).to.eql([0, 0]);
expect(fn([-10, 0])).to.eql([0, 0]);
expect(fn([100, 100])).to.eql([1, 1]);
const res = 1;
const size = [0.15, 0.1];
expect(fn([0, 0], res, size)).to.eql([0.075, 0.05]);
expect(fn([0.5, 0.5], res, size)).to.eql([0.5, 0.5]);
expect(fn([10, 10], res, size)).to.eql([0.925, 0.95]);
const overshootCenter = fn([10, 10], res, size, true);
expect(overshootCenter[0] > 0.925).to.eql(true);
expect(overshootCenter[1] > 0.95).to.eql(true);
expect(overshootCenter[0] < 9).to.eql(true);
expect(overshootCenter[1] < 9).to.eql(true);
});
});
@@ -218,7 +239,8 @@ describe('ol.View', function() {
it('works with minResolution and maxResolution', function() {
const constraint = getConstraint({
maxResolution: 500,
minResolution: 100
minResolution: 100,
constrainResolution: true
});
expect(constraint(600, 0, 0)).to.be(500);
@@ -234,7 +256,8 @@ describe('ol.View', function() {
const constraint = getConstraint({
maxResolution: 500,
minResolution: 1,
zoomFactor: 10
zoomFactor: 10,
constrainResolution: true
});
expect(constraint(1000, 0, 0)).to.be(500);
@@ -365,6 +388,7 @@ describe('ol.View', function() {
it('applies the current resolution if resolution was originally supplied', function() {
const view = new View({
center: [0, 0],
maxResolution: 2000,
resolution: 1000
});
view.setResolution(500);
@@ -964,7 +988,8 @@ describe('ol.View', function() {
let view;
beforeEach(function() {
view = new View({
resolutions: [512, 256, 128, 64, 32, 16]
resolutions: [1024, 512, 256, 128, 64, 32, 16, 8],
smoothResolutionConstraint: false
});
});
@@ -973,30 +998,31 @@ describe('ol.View', function() {
expect(view.getZoom()).to.be(undefined);
view.setResolution(513);
expect(view.getZoom()).to.roughlyEqual(Math.log(512 / 513) / Math.LN2, 1e-9);
expect(view.getZoom()).to.roughlyEqual(Math.log(1024 / 513) / Math.LN2, 1e-9);
view.setResolution(512);
expect(view.getZoom()).to.be(0);
expect(view.getZoom()).to.be(1);
view.setResolution(100);
expect(view.getZoom()).to.roughlyEqual(2.35614, 1e-5);
expect(view.getZoom()).to.roughlyEqual(3.35614, 1e-5);
view.setResolution(65);
expect(view.getZoom()).to.roughlyEqual(2.97763, 1e-5);
expect(view.getZoom()).to.roughlyEqual(3.97763, 1e-5);
view.setResolution(64);
expect(view.getZoom()).to.be(3);
expect(view.getZoom()).to.be(4);
view.setResolution(16);
expect(view.getZoom()).to.be(5);
expect(view.getZoom()).to.be(6);
view.setResolution(15);
expect(view.getZoom()).to.roughlyEqual(Math.log(512 / 15) / Math.LN2, 1e-9);
expect(view.getZoom()).to.roughlyEqual(Math.log(1024 / 15) / Math.LN2, 1e-9);
});
it('works for resolution arrays with variable zoom factors', function() {
const view = new View({
resolutions: [10, 5, 2, 1]
resolutions: [10, 5, 2, 1],
smoothResolutionConstraint: false
});
view.setZoom(1);
@@ -1021,7 +1047,8 @@ describe('ol.View', function() {
it('returns correct zoom levels', function() {
const view = new View({
minZoom: 10,
maxZoom: 20
maxZoom: 20,
smoothResolutionConstraint: false
});
view.setZoom(5);
@@ -1097,12 +1124,16 @@ describe('ol.View', function() {
describe('#getResolutionForZoom', function() {
it('returns correct zoom resolution', function() {
const view = new View();
const view = new View({
smoothResolutionConstraint: false
});
const max = view.getMaxZoom();
const min = view.getMinZoom();
expect(view.getResolutionForZoom(max)).to.be(view.getMinResolution());
expect(view.getResolutionForZoom(max + 1)).to.be(view.getMinResolution() / 2);
expect(view.getResolutionForZoom(min)).to.be(view.getMaxResolution());
expect(view.getResolutionForZoom(min - 1)).to.be(view.getMaxResolution() * 2);
});
it('returns correct zoom levels for specifically configured resolutions', function() {
@@ -1110,11 +1141,30 @@ describe('ol.View', function() {
resolutions: [10, 8, 6, 4, 2]
});
expect(view.getResolutionForZoom(-1)).to.be(10);
expect(view.getResolutionForZoom(0)).to.be(10);
expect(view.getResolutionForZoom(1)).to.be(8);
expect(view.getResolutionForZoom(2)).to.be(6);
expect(view.getResolutionForZoom(3)).to.be(4);
expect(view.getResolutionForZoom(4)).to.be(2);
expect(view.getResolutionForZoom(5)).to.be(2);
});
it('returns correct zoom levels for resolutions with variable zoom levels', function() {
const view = new View({
resolutions: [50, 10, 5, 2.5, 1.25, 0.625]
});
expect(view.getResolutionForZoom(-1)).to.be(50);
expect(view.getResolutionForZoom(0)).to.be(50);
expect(view.getResolutionForZoom(0.5)).to.be(50 / Math.pow(5, 0.5));
expect(view.getResolutionForZoom(1)).to.be(10);
expect(view.getResolutionForZoom(2)).to.be(5);
expect(view.getResolutionForZoom(2.75)).to.be(5 / Math.pow(2, 0.75));
expect(view.getResolutionForZoom(3)).to.be(2.5);
expect(view.getResolutionForZoom(4)).to.be(1.25);
expect(view.getResolutionForZoom(5)).to.be(0.625);
expect(view.getResolutionForZoom(6)).to.be(0.625);
});
});
@@ -1246,8 +1296,14 @@ describe('ol.View', function() {
document.body.removeChild(target);
});
it('calculates the size correctly', function() {
const size = map.getView().getSizeFromViewport_();
let size = map.getView().getSizeFromViewport_();
expect(size).to.eql([200, 150]);
size = map.getView().getSizeFromViewport_(Math.PI / 2);
expect(size[0]).to.roughlyEqual(150, 1e-9);
expect(size[1]).to.roughlyEqual(200, 1e-9);
size = map.getView().getSizeFromViewport_(Math.PI);
expect(size[0]).to.roughlyEqual(200, 1e-9);
expect(size[1]).to.roughlyEqual(150, 1e-9);
});
});
@@ -1278,14 +1334,40 @@ describe('ol.View', function() {
zoom: 5
});
});
it('fits correctly to the geometry', function() {
it('fits correctly to the geometry (with unconstrained resolution)', function() {
view.fit(
new LineString([[6000, 46000], [6000, 47100], [7000, 46000]]),
{size: [200, 200], padding: [100, 0, 0, 100], constrainResolution: false});
{size: [200, 200], padding: [100, 0, 0, 100]});
expect(view.getResolution()).to.be(11);
expect(view.getCenter()[0]).to.be(5950);
expect(view.getCenter()[1]).to.be(47100);
view.fit(
new Circle([6000, 46000], 1000),
{size: [200, 200]});
expect(view.getResolution()).to.be(10);
expect(view.getCenter()[0]).to.be(6000);
expect(view.getCenter()[1]).to.be(46000);
view.setRotation(Math.PI / 8);
view.fit(
new Circle([6000, 46000], 1000),
{size: [200, 200]});
expect(view.getResolution()).to.roughlyEqual(10, 1e-9);
expect(view.getCenter()[0]).to.roughlyEqual(6000, 1e-9);
expect(view.getCenter()[1]).to.roughlyEqual(46000, 1e-9);
view.setRotation(Math.PI / 4);
view.fit(
new LineString([[6000, 46000], [6000, 47100], [7000, 46000]]),
{size: [200, 200], padding: [100, 0, 0, 100]});
expect(view.getResolution()).to.roughlyEqual(14.849242404917458, 1e-9);
expect(view.getCenter()[0]).to.roughlyEqual(5200, 1e-9);
expect(view.getCenter()[1]).to.roughlyEqual(46300, 1e-9);
});
it('fits correctly to the geometry', function() {
view.setConstrainResolution(true);
view.fit(
new LineString([[6000, 46000], [6000, 47100], [7000, 46000]]),
{size: [200, 200], padding: [100, 0, 0, 100]});
@@ -1314,30 +1396,8 @@ describe('ol.View', function() {
expect(view.getZoom()).to.be(6);
expect(view.getCenter()[0]).to.be(5900);
expect(view.getCenter()[1]).to.be(46100);
view.fit(
new Circle([6000, 46000], 1000),
{size: [200, 200], constrainResolution: false});
expect(view.getResolution()).to.be(10);
expect(view.getCenter()[0]).to.be(6000);
expect(view.getCenter()[1]).to.be(46000);
view.setRotation(Math.PI / 8);
view.fit(
new Circle([6000, 46000], 1000),
{size: [200, 200], constrainResolution: false});
expect(view.getResolution()).to.roughlyEqual(10, 1e-9);
expect(view.getCenter()[0]).to.roughlyEqual(6000, 1e-9);
expect(view.getCenter()[1]).to.roughlyEqual(46000, 1e-9);
view.setRotation(Math.PI / 4);
view.fit(
new LineString([[6000, 46000], [6000, 47100], [7000, 46000]]),
{size: [200, 200], padding: [100, 0, 0, 100], constrainResolution: false});
expect(view.getResolution()).to.roughlyEqual(14.849242404917458, 1e-9);
expect(view.getCenter()[0]).to.roughlyEqual(5200, 1e-9);
expect(view.getCenter()[1]).to.roughlyEqual(46300, 1e-9);
});
it('fits correctly to the extent', function() {
view.fit([1000, 1000, 2000, 2000], {size: [200, 200]});
expect(view.getResolution()).to.be(5);
@@ -1360,7 +1420,6 @@ describe('ol.View', function() {
{
size: [200, 200],
padding: [100, 0, 0, 100],
constrainResolution: false,
duration: 25
});
@@ -1422,6 +1481,235 @@ describe('ol.View', function() {
expect(view.getCenter()[1]).to.roughlyEqual(46000, 1e-9);
});
});
describe('#beginInteraction() and endInteraction()', function() {
let view;
beforeEach(function() {
view = new View();
});
it('correctly changes the view hint', function() {
view.beginInteraction();
expect(view.getHints()[1]).to.be(1);
view.beginInteraction();
expect(view.getHints()[1]).to.be(2);
view.endInteraction();
view.endInteraction();
expect(view.getHints()[1]).to.be(0);
});
});
describe('#getConstrainedZoom()', function() {
let view;
it('works correctly without constraint', function() {
view = new View({
zoom: 0
});
expect(view.getConstrainedZoom(3)).to.be(3);
});
it('works correctly with resolution constraints', function() {
view = new View({
zoom: 4,
minZoom: 4,
maxZoom: 8
});
expect(view.getConstrainedZoom(3)).to.be(4);
expect(view.getConstrainedZoom(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.getConstrainedZoom(0)).to.be(0);
expect(view.getConstrainedZoom(4)).to.be(4);
expect(view.getConstrainedZoom(8)).to.be(6);
});
});
describe('#getConstrainedResolution()', function() {
let view;
const defaultMaxRes = 156543.03392804097;
it('works correctly by snapping to power of 2', function() {
view = new View();
expect(view.getConstrainedResolution(1000000)).to.be(defaultMaxRes);
expect(view.getConstrainedResolution(defaultMaxRes / 8)).to.be(defaultMaxRes / 8);
});
it('works correctly by snapping to a custom zoom factor', function() {
view = new View({
maxResolution: 2500,
zoomFactor: 5,
maxZoom: 4,
constrainResolution: true
});
expect(view.getConstrainedResolution(90, 1)).to.be(100);
expect(view.getConstrainedResolution(90, -1)).to.be(20);
expect(view.getConstrainedResolution(20)).to.be(20);
expect(view.getConstrainedResolution(5)).to.be(4);
expect(view.getConstrainedResolution(1)).to.be(4);
});
it('works correctly with a specific resolution set', function() {
view = new View({
zoom: 0,
resolutions: [512, 256, 128, 64, 32, 16, 8],
constrainResolution: true
});
expect(view.getConstrainedResolution(1000, 1)).to.be(512);
expect(view.getConstrainedResolution(260, 1)).to.be(512);
expect(view.getConstrainedResolution(260)).to.be(256);
expect(view.getConstrainedResolution(30)).to.be(32);
expect(view.getConstrainedResolution(30, -1)).to.be(16);
expect(view.getConstrainedResolution(4, -1)).to.be(8);
});
});
describe('#adjustRotation()', function() {
it('changes view rotation with anchor', function() {
const view = new View({
resolution: 1,
center: [0, 0]
});
view.adjustRotation(Math.PI / 2);
expect(view.getRotation()).to.be(Math.PI / 2);
expect(view.getCenter()).to.eql([0, 0]);
view.adjustRotation(-Math.PI);
expect(view.getRotation()).to.be(-Math.PI / 2);
expect(view.getCenter()).to.eql([0, 0]);
view.adjustRotation(Math.PI / 3, [50, 0]);
expect(view.getRotation()).to.roughlyEqual(-Math.PI / 6, 1e-9);
expect(view.getCenter()[0]).to.roughlyEqual(50 * (1 - Math.cos(Math.PI / 3)), 1e-9);
expect(view.getCenter()[1]).to.roughlyEqual(-50 * Math.sin(Math.PI / 3), 1e-9);
});
it('does not change view parameters if rotation is disabled', function() {
const view = new View({
resolution: 1,
enableRotation: false,
center: [0, 0]
});
view.adjustRotation(Math.PI / 2);
expect(view.getRotation()).to.be(0);
expect(view.getCenter()).to.eql([0, 0]);
view.adjustRotation(-Math.PI * 3, [-50, 0]);
expect(view.getRotation()).to.be(0);
expect(view.getCenter()).to.eql([0, 0]);
});
});
describe('#adjustZoom()', function() {
it('changes view resolution', function() {
const view = new View({
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
view.adjustZoom(1);
expect(view.getResolution()).to.be(0.5);
view.adjustZoom(-1);
expect(view.getResolution()).to.be(1);
view.adjustZoom(2);
expect(view.getResolution()).to.be(0.25);
view.adjustZoom(-2);
expect(view.getResolution()).to.be(1);
});
it('changes view resolution and center relative to the anchor', function() {
const view = new View({
center: [0, 0],
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
view.adjustZoom(1, [10, 10]);
expect(view.getCenter()).to.eql([5, 5]);
view.adjustZoom(-1, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]);
view.adjustZoom(2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
view.adjustZoom(-2, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]);
});
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],
constrainOnlyCenter: true,
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
view.adjustZoom(1, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
view.adjustZoom(-1, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
view.adjustZoom(2, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]);
view.adjustZoom(-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);
view.adjustZoom(1, [100, 100]);
expect(view.getCenter()).to.eql([75, 75]);
view.adjustZoom(-1, [75, 75]);
expect(view.getCenter()).to.eql([50, 50]);
view.adjustZoom(2, [100, 100]);
expect(view.getCenter()).to.eql([87.5, 87.5]);
view.adjustZoom(-3, [0, 0]);
expect(view.getCenter()).to.eql([50, 50]);
expect(view.getResolution()).to.eql(1);
});
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;
view.adjustZoom(1, [100, 100]);
expect(view.getCenter()).to.eql([100 - halfSize / 2, 100 - halfSize / 2]);
view.setCenter([0, 50]);
view.adjustZoom(-1, [0, 0]);
expect(view.getCenter()).to.eql([0, 100 - halfSize]);
});
});
});
describe('ol.View.isNoopAnimation()', function() {