One direction pinch zoom
This commit is contained in:
@@ -33,9 +33,12 @@ ol.array.binaryFindNearest = function(arr, target) {
|
||||
/**
|
||||
* @param {Array.<number>} arr Array.
|
||||
* @param {number} target Target.
|
||||
* @param {number} direction 0 means return the nearest, > 0
|
||||
* means return the largest nearest, < 0 means return the
|
||||
* smallest nearest.
|
||||
* @return {number} Index.
|
||||
*/
|
||||
ol.array.linearFindNearest = function(arr, target) {
|
||||
ol.array.linearFindNearest = function(arr, target, direction) {
|
||||
var n = arr.length;
|
||||
if (arr[0] <= target) {
|
||||
return 0;
|
||||
@@ -43,6 +46,19 @@ ol.array.linearFindNearest = function(arr, target) {
|
||||
return n - 1;
|
||||
} else {
|
||||
var i;
|
||||
if (direction > 0) {
|
||||
for (i = 1; i < n; ++i) {
|
||||
if (arr[i] < target) {
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
} else if (direction < 0) {
|
||||
for (i = 1; i < n; ++i) {
|
||||
if (arr[i] <= target) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 1; i < n; ++i) {
|
||||
if (arr[i] == target) {
|
||||
return i;
|
||||
@@ -54,6 +70,10 @@ ol.array.linearFindNearest = function(arr, target) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// We should never get here, but the compiler complains
|
||||
// if it finds a path for which no number is returned.
|
||||
goog.asserts.assert(false);
|
||||
return n - 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,6 +29,12 @@ ol.interaction.TouchZoom = function() {
|
||||
*/
|
||||
this.lastDistance_;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.lastScaleDelta_ = 1;
|
||||
|
||||
};
|
||||
goog.inherits(ol.interaction.TouchZoom, ol.interaction.Touch);
|
||||
|
||||
@@ -53,6 +59,9 @@ ol.interaction.TouchZoom.prototype.handleTouchMove =
|
||||
scaleDelta = this.lastDistance_ / distance;
|
||||
}
|
||||
this.lastDistance_ = distance;
|
||||
if (scaleDelta != 1.0) {
|
||||
this.lastScaleDelta_ = scaleDelta;
|
||||
}
|
||||
|
||||
var map = mapBrowserEvent.map;
|
||||
var view = map.getView();
|
||||
@@ -78,9 +87,12 @@ ol.interaction.TouchZoom.prototype.handleTouchEnd =
|
||||
if (this.targetTouches.length < 2) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var view = map.getView();
|
||||
// take the resolution constraint into account
|
||||
// Zoom to final resolution, with an animation, and provide a
|
||||
// direction not to zoom out/in if user was pinching in/out.
|
||||
// Direction is > 0 if pinching out, and < 0 if pinching in.
|
||||
var direction = this.lastScaleDelta_ - 1;
|
||||
view.zoom(map, view.getResolution(), undefined,
|
||||
ol.interaction.TOUCHZOOM_ANIMATION_DURATION);
|
||||
ol.interaction.TOUCHZOOM_ANIMATION_DURATION, direction);
|
||||
view.setHint(ol.ViewHint.INTERACTING, -1);
|
||||
return false;
|
||||
} else {
|
||||
@@ -97,6 +109,7 @@ ol.interaction.TouchZoom.prototype.handleTouchStart =
|
||||
if (this.targetTouches.length >= 2) {
|
||||
var view = mapBrowserEvent.map.getView();
|
||||
this.lastDistance_ = undefined;
|
||||
this.lastScaleDelta_ = 1;
|
||||
view.setHint(ol.ViewHint.INTERACTING, 1);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,7 @@ goog.require('ol.array');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
* @typedef {function((number|undefined), number, number): (number|undefined)}
|
||||
*/
|
||||
ol.ResolutionConstraintType;
|
||||
|
||||
@@ -20,7 +20,7 @@ ol.ResolutionConstraintType;
|
||||
ol.ResolutionConstraint.createContinuous =
|
||||
function(power, maxResolution, opt_minResolution) {
|
||||
var minResolution = opt_minResolution || 0;
|
||||
return function(resolution, delta) {
|
||||
return function(resolution, delta, direction) {
|
||||
if (goog.isDef(resolution)) {
|
||||
resolution /= Math.pow(power, delta);
|
||||
return goog.math.clamp(resolution, minResolution, maxResolution);
|
||||
@@ -37,9 +37,9 @@ ol.ResolutionConstraint.createContinuous =
|
||||
*/
|
||||
ol.ResolutionConstraint.createSnapToResolutions =
|
||||
function(resolutions) {
|
||||
return function(resolution, delta) {
|
||||
return function(resolution, delta, direction) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var z = ol.array.linearFindNearest(resolutions, resolution);
|
||||
var z = ol.array.linearFindNearest(resolutions, resolution, direction);
|
||||
z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
|
||||
return resolutions[z];
|
||||
} else {
|
||||
@@ -57,10 +57,18 @@ ol.ResolutionConstraint.createSnapToResolutions =
|
||||
*/
|
||||
ol.ResolutionConstraint.createSnapToPower =
|
||||
function(power, maxResolution, opt_maxLevel) {
|
||||
return function(resolution, delta) {
|
||||
return function(resolution, delta, direction) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var offset;
|
||||
if (direction > 0) {
|
||||
offset = 0;
|
||||
} else if (direction < 0) {
|
||||
offset = 1;
|
||||
} else {
|
||||
offset = 0.5;
|
||||
}
|
||||
var oldLevel = Math.floor(
|
||||
Math.log(maxResolution / resolution) / Math.log(power) + 0.5);
|
||||
Math.log(maxResolution / resolution) / Math.log(power) + offset);
|
||||
var newLevel = Math.max(oldLevel + delta, 0);
|
||||
if (goog.isDef(opt_maxLevel)) {
|
||||
newLevel = Math.min(newLevel, opt_maxLevel);
|
||||
|
||||
@@ -100,7 +100,7 @@ ol.source.ImageSource.prototype.createImage =
|
||||
ol.source.ImageSource.prototype.findNearestResolution =
|
||||
function(resolution) {
|
||||
if (!goog.isNull(this.resolutions_)) {
|
||||
var idx = ol.array.linearFindNearest(this.resolutions_, resolution);
|
||||
var idx = ol.array.linearFindNearest(this.resolutions_, resolution, 0);
|
||||
resolution = this.resolutions_[idx];
|
||||
}
|
||||
return resolution;
|
||||
|
||||
@@ -329,7 +329,7 @@ ol.tilegrid.TileGrid.prototype.getTileSize = function(z) {
|
||||
* @return {number} Z.
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.getZForResolution = function(resolution) {
|
||||
return ol.array.linearFindNearest(this.resolutions_, resolution);
|
||||
return ol.array.linearFindNearest(this.resolutions_, resolution, 0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ ol.View2D.prototype.getView3D = function() {
|
||||
ol.View2D.prototype.fitExtent = function(extent, size) {
|
||||
this.setCenter(extent.getCenter());
|
||||
var resolution = this.getResolutionForExtent(extent, size);
|
||||
resolution = this.constraints_.resolution(resolution, 0);
|
||||
resolution = this.constraints_.resolution(resolution, 0, 0);
|
||||
this.setResolution(resolution);
|
||||
};
|
||||
|
||||
@@ -342,10 +342,19 @@ ol.View2D.prototype.rotateWithoutConstraints =
|
||||
* @param {number|undefined} resolution Resolution to go to.
|
||||
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
||||
* @param {number=} opt_duration Duration.
|
||||
* @param {number=} opt_direction Zooming direction; > 0 indicates
|
||||
* zooming out, in which case the constraints system will select
|
||||
* the largest nearest resolution; < 0 indicates zooming in, in
|
||||
* which case the constraints system will select the smallest
|
||||
* nearest resolution; == 0 indicates that the zooming direction
|
||||
* is unknown/not relevant, in which case the constraints system
|
||||
* will select the nearest resolution. If not defined 0 is
|
||||
* assumed.
|
||||
*/
|
||||
ol.View2D.prototype.zoom =
|
||||
function(map, resolution, opt_anchor, opt_duration) {
|
||||
resolution = this.constraints_.resolution(resolution, 0);
|
||||
function(map, resolution, opt_anchor, opt_duration, opt_direction) {
|
||||
var direction = opt_direction || 0;
|
||||
resolution = this.constraints_.resolution(resolution, 0, direction);
|
||||
this.zoomWithoutConstraints(map, resolution, opt_anchor, opt_duration);
|
||||
};
|
||||
|
||||
@@ -359,7 +368,7 @@ ol.View2D.prototype.zoom =
|
||||
ol.View2D.prototype.zoomByDelta =
|
||||
function(map, delta, opt_anchor, opt_duration) {
|
||||
var currentResolution = this.getResolution();
|
||||
var resolution = this.constraints_.resolution(currentResolution, delta);
|
||||
var resolution = this.constraints_.resolution(currentResolution, delta, 0);
|
||||
this.zoomWithoutConstraints(map, resolution, opt_anchor, opt_duration);
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user