One direction pinch zoom

This commit is contained in:
Éric Lemoine
2013-03-25 18:15:00 +01:00
parent 588e0c1cdc
commit de1575e457
9 changed files with 269 additions and 137 deletions

View File

@@ -28,21 +28,49 @@ describe('ol.array', function() {
it('returns expected value', function() {
var arr = [1000, 500, 100];
expect(ol.array.linearFindNearest(arr, 10000)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 1000)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 900)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 10000, 0)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 10000, 1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 10000, -1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 750)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 1000, 0)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 1000, 1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 1000, -1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 550)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 500)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 450)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 900, 0)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 900, 1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 900, -1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 300)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 750, 0)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 750, 1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 750, -1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 200)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 100)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 50)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 550, 0)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 550, 1)).to.eql(0);
expect(ol.array.linearFindNearest(arr, 550, -1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 500, 0)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 500, 1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 500, -1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 450, 0)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 450, 1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 450, -1)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 300, 0)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 300, 1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 300, -1)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 200, 0)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 200, 1)).to.eql(1);
expect(ol.array.linearFindNearest(arr, 200, -1)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 100, 0)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 100, 1)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 100, -1)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 50, 0)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 50, 1)).to.eql(2);
expect(ol.array.linearFindNearest(arr, 50, -1)).to.eql(2);
});
});
});

View File

@@ -13,28 +13,28 @@ describe('ol.ResolutionConstraint', function() {
describe('delta 0', function() {
it('returns expected resolution value', function() {
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);
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);
});
});
describe('zoom in', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1000, 1)).to.eql(500);
expect(resolutionConstraint(500, 1)).to.eql(250);
expect(resolutionConstraint(250, 1)).to.eql(100);
expect(resolutionConstraint(100, 1)).to.eql(100);
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);
});
});
describe('zoom out', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1000, -1)).to.eql(1000);
expect(resolutionConstraint(500, -1)).to.eql(1000);
expect(resolutionConstraint(250, -1)).to.eql(500);
expect(resolutionConstraint(100, -1)).to.eql(250);
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);
});
});
});
@@ -51,40 +51,40 @@ describe('ol.ResolutionConstraint', function() {
describe('delta 0', function() {
it('returns expected resolution value', function() {
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);
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);
});
});
describe('zoom in', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1050, 1)).to.eql(500);
expect(resolutionConstraint(950, 1)).to.eql(500);
expect(resolutionConstraint(550, 1)).to.eql(250);
expect(resolutionConstraint(450, 1)).to.eql(250);
expect(resolutionConstraint(300, 1)).to.eql(100);
expect(resolutionConstraint(200, 1)).to.eql(100);
expect(resolutionConstraint(150, 1)).to.eql(100);
expect(resolutionConstraint(50, 1)).to.eql(100);
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);
});
});
describe('zoom out', function() {
it('returns expected resolution value', function() {
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(1000);
expect(resolutionConstraint(300, -1)).to.eql(500);
expect(resolutionConstraint(200, -1)).to.eql(500);
expect(resolutionConstraint(150, -1)).to.eql(250);
expect(resolutionConstraint(50, -1)).to.eql(250);
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);
});
});
});
@@ -100,49 +100,49 @@ describe('ol.ResolutionConstraint', function() {
describe('delta 0', function() {
it('returns expected resolution value', function() {
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);
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);
});
});
describe('zoom in', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1024, 1)).to.eql(512);
expect(resolutionConstraint(512, 1)).to.eql(256);
expect(resolutionConstraint(256, 1)).to.eql(128);
expect(resolutionConstraint(128, 1)).to.eql(64);
expect(resolutionConstraint(64, 1)).to.eql(32);
expect(resolutionConstraint(32, 1)).to.eql(16);
expect(resolutionConstraint(16, 1)).to.eql(8);
expect(resolutionConstraint(8, 1)).to.eql(4);
expect(resolutionConstraint(4, 1)).to.eql(2);
expect(resolutionConstraint(2, 1)).to.eql(1);
expect(resolutionConstraint(1, 1)).to.eql(1);
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);
});
});
describe('zoom out', function() {
it('returns expected resolution value', function() {
expect(resolutionConstraint(1024, -1)).to.eql(1024);
expect(resolutionConstraint(512, -1)).to.eql(1024);
expect(resolutionConstraint(256, -1)).to.eql(512);
expect(resolutionConstraint(128, -1)).to.eql(256);
expect(resolutionConstraint(64, -1)).to.eql(128);
expect(resolutionConstraint(32, -1)).to.eql(64);
expect(resolutionConstraint(16, -1)).to.eql(32);
expect(resolutionConstraint(8, -1)).to.eql(16);
expect(resolutionConstraint(4, -1)).to.eql(8);
expect(resolutionConstraint(2, -1)).to.eql(4);
expect(resolutionConstraint(1, -1)).to.eql(2);
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);
});
});
});
@@ -156,30 +156,84 @@ describe('ol.ResolutionConstraint', function() {
ol.ResolutionConstraint.createSnapToPower(2, 1024, 10);
});
describe('delta 0', function() {
describe('delta 0, direction 0', function() {
it('returns expected resolution value', function() {
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);
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);
});
});
describe('delta 0, direction > 0', 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);
});
});
describe('delta 0, direction < 0', 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);
});
});
});

View File

@@ -9,9 +9,9 @@ describe('ol.View2D', function() {
it('gives a correct resolution constraint function', function() {
var options = {};
var fn = ol.View2D.createConstraints_(options).resolution;
expect(fn(156543.03392804097, 0))
expect(fn(156543.03392804097, 0, 0))
.to.roughlyEqual(156543.03392804097, 1e-9);
expect(fn(78271.51696402048, 0))
expect(fn(78271.51696402048, 0, 0))
.to.roughlyEqual(78271.51696402048, 1e-10);
});
});
@@ -25,12 +25,12 @@ describe('ol.View2D', function() {
zoomFactor: 3
};
var fn = ol.View2D.createConstraints_(options).resolution;
expect(fn(82, 0)).to.eql(81);
expect(fn(81, 0)).to.eql(81);
expect(fn(27, 0)).to.eql(27);
expect(fn(9, 0)).to.eql(9);
expect(fn(3, 0)).to.eql(3);
expect(fn(2, 0)).to.eql(3);
expect(fn(82, 0, 0)).to.eql(81);
expect(fn(81, 0, 0)).to.eql(81);
expect(fn(27, 0, 0)).to.eql(27);
expect(fn(9, 0, 0)).to.eql(9);
expect(fn(3, 0, 0)).to.eql(3);
expect(fn(2, 0, 0)).to.eql(3);
});
});
@@ -40,11 +40,11 @@ describe('ol.View2D', function() {
resolutions: [97, 76, 65, 54, 0.45]
};
var fn = ol.View2D.createConstraints_(options).resolution;
expect(fn(97, 0)).to.eql(97);
expect(fn(76, 0)).to.eql(76);
expect(fn(65, 0)).to.eql(65);
expect(fn(54, 0)).to.eql(54);
expect(fn(0.45, 0)).to.eql(0.45);
expect(fn(97, 0, 0)).to.eql(97);
expect(fn(76, 0, 0)).to.eql(76);
expect(fn(65, 0, 0)).to.eql(65);
expect(fn(54, 0, 0)).to.eql(54);
expect(fn(0.45, 0, 0)).to.eql(0.45);
});
});