s/ZoomFunction/ResolutionConstraint/
This commit is contained in:
@@ -12,9 +12,9 @@ goog.require('ol.control.DragPan');
|
||||
goog.require('ol.control.KeyboardPan');
|
||||
goog.require('ol.control.KeyboardZoom');
|
||||
goog.require('ol.control.MouseWheelZoom');
|
||||
goog.require('ol.control.ResolutionConstraint');
|
||||
goog.require('ol.control.ShiftDragRotateAndZoom');
|
||||
goog.require('ol.control.ShiftDragZoom');
|
||||
goog.require('ol.control.ZoomFunction');
|
||||
goog.require('ol.dom');
|
||||
goog.require('ol.dom.Map');
|
||||
goog.require('ol.webgl');
|
||||
@@ -80,18 +80,18 @@ ol.createMap = function(target, opt_values, opt_rendererHints) {
|
||||
var panFunction = ol.control.CenterConstraint.snapToPixel;
|
||||
|
||||
// FIXME this should be a configuration option
|
||||
var zoomFunction = ol.control.ZoomFunction.createSnapToPower(
|
||||
var resolutionConstraint = ol.control.ResolutionConstraint.createSnapToPower(
|
||||
2, ol.Projection.EPSG_3857_HALF_SIZE / 128);
|
||||
|
||||
if (!goog.object.containsKey(values, ol.MapProperty.CONTROLS)) {
|
||||
var controls = new ol.Collection();
|
||||
controls.push(new ol.control.DblClickZoom(zoomFunction));
|
||||
controls.push(new ol.control.DblClickZoom(resolutionConstraint));
|
||||
controls.push(new ol.control.DragPan(panFunction));
|
||||
controls.push(new ol.control.KeyboardPan(panFunction));
|
||||
controls.push(new ol.control.KeyboardZoom(zoomFunction));
|
||||
controls.push(new ol.control.MouseWheelZoom(zoomFunction));
|
||||
controls.push(new ol.control.ShiftDragRotateAndZoom(zoomFunction));
|
||||
controls.push(new ol.control.ShiftDragZoom(zoomFunction));
|
||||
controls.push(new ol.control.KeyboardZoom(resolutionConstraint));
|
||||
controls.push(new ol.control.MouseWheelZoom(resolutionConstraint));
|
||||
controls.push(new ol.control.ShiftDragRotateAndZoom(resolutionConstraint));
|
||||
controls.push(new ol.control.ShiftDragZoom(resolutionConstraint));
|
||||
values[ol.MapProperty.CONTROLS] = controls;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,25 @@ goog.provide('ol.control.DblClickZoom');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Control');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.ZoomFunctionType');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.ZoomFunctionType} zoomFunction Zoom function.
|
||||
* @param {ol.control.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
*/
|
||||
ol.control.DblClickZoom = function(zoomFunction) {
|
||||
ol.control.DblClickZoom = function(resolutionConstraint) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.control.ZoomFunctionType}
|
||||
* @type {ol.control.ResolutionConstraintType}
|
||||
*/
|
||||
this.zoomFunction_ = zoomFunction;
|
||||
this.resolutionConstraint_ = resolutionConstraint;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.DblClickZoom, ol.Control);
|
||||
@@ -38,7 +39,7 @@ ol.control.DblClickZoom.prototype.handleMapBrowserEvent =
|
||||
map.setCenter(mapBrowserEvent.getCoordinate());
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
var delta = browserEvent.shiftKey ? -1 : 1;
|
||||
var resolution = this.zoomFunction_(map.getResolution(), delta);
|
||||
var resolution = this.resolutionConstraint_(map.getResolution(), delta);
|
||||
map.setResolution(resolution);
|
||||
}, this);
|
||||
mapBrowserEvent.preventDefault();
|
||||
|
||||
@@ -3,24 +3,25 @@ goog.provide('ol.control.KeyboardZoom');
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.events.KeyHandler.EventType');
|
||||
goog.require('ol.Control');
|
||||
goog.require('ol.control.ZoomFunctionType');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.ZoomFunctionType} zoomFunction Zoom function.
|
||||
* @param {ol.control.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
*/
|
||||
ol.control.KeyboardZoom = function(zoomFunction) {
|
||||
ol.control.KeyboardZoom = function(resolutionConstraint) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.control.ZoomFunctionType}
|
||||
* @type {ol.control.ResolutionConstraintType}
|
||||
*/
|
||||
this.zoomFunction_ = zoomFunction;
|
||||
this.resolutionConstraint_ = resolutionConstraint;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.KeyboardZoom, ol.Control);
|
||||
@@ -38,7 +39,7 @@ ol.control.KeyboardZoom.prototype.handleMapBrowserEvent =
|
||||
if (charCode == '+'.charCodeAt(0) || charCode == '-'.charCodeAt(0)) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var delta = charCode == '+'.charCodeAt(0) ? 1 : -1;
|
||||
var resolution = this.zoomFunction_(map.getResolution(), delta);
|
||||
var resolution = this.resolutionConstraint_(map.getResolution(), delta);
|
||||
map.setResolution(resolution);
|
||||
keyEvent.preventDefault();
|
||||
mapBrowserEvent.preventDefault();
|
||||
|
||||
@@ -3,24 +3,25 @@ goog.provide('ol.control.MouseWheelZoom');
|
||||
goog.require('goog.events.MouseWheelEvent');
|
||||
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.ZoomFunctionType');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.ZoomFunctionType} zoomFunction Zoom function.
|
||||
* @param {ol.control.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
*/
|
||||
ol.control.MouseWheelZoom = function(zoomFunction) {
|
||||
ol.control.MouseWheelZoom = function(resolutionConstraint) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.control.ZoomFunctionType}
|
||||
* @type {ol.control.ResolutionConstraintType}
|
||||
*/
|
||||
this.zoomFunction_ = zoomFunction;
|
||||
this.resolutionConstraint_ = resolutionConstraint;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.MouseWheelZoom, ol.Control);
|
||||
@@ -42,7 +43,7 @@ ol.control.MouseWheelZoom.prototype.handleMapBrowserEvent =
|
||||
// FIXME compute correct center for zoom
|
||||
map.setCenter(mapBrowserEvent.getCoordinate());
|
||||
var delta = mouseWheelEvent.deltaY < 0 ? 1 : -1;
|
||||
var resolution = this.zoomFunction_(map.getResolution(), delta);
|
||||
var resolution = this.resolutionConstraint_(map.getResolution(), delta);
|
||||
map.setResolution(resolution);
|
||||
}, this);
|
||||
mapBrowserEvent.preventDefault();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
goog.provide('ol.control.ZoomFunction');
|
||||
goog.provide('ol.control.ZoomFunctionType');
|
||||
goog.provide('ol.control.ResolutionConstraint');
|
||||
goog.provide('ol.control.ResolutionConstraintType');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.array');
|
||||
@@ -8,14 +8,15 @@ goog.require('ol.array');
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol.control.ZoomFunctionType;
|
||||
ol.control.ResolutionConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} resolutions Resolutions.
|
||||
* @return {ol.control.ZoomFunctionType} Zoom function.
|
||||
* @return {ol.control.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.control.ZoomFunction.createSnapToResolutions = function(resolutions) {
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions =
|
||||
function(resolutions) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var oldLevel = ol.array.linearFindNearest(resolutions, resolution);
|
||||
@@ -33,9 +34,9 @@ ol.control.ZoomFunction.createSnapToResolutions = function(resolutions) {
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
* @param {number=} opt_maxLevel Maixmum level.
|
||||
* @return {ol.control.ZoomFunctionType} Zoom function.
|
||||
* @return {ol.control.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.control.ZoomFunction.createSnapToPower =
|
||||
ol.control.ResolutionConstraint.createSnapToPower =
|
||||
function(power, maxResolution, opt_maxLevel) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
159
src/ol/control/resolutionconstraint_test.js
Normal file
159
src/ol/control/resolutionconstraint_test.js
Normal file
@@ -0,0 +1,159 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.control.ResolutionConstraint');
|
||||
|
||||
|
||||
function testSnapToResolutionsZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1000, 0));
|
||||
assertEquals(500, resolutionConstraint(500, 0));
|
||||
assertEquals(250, resolutionConstraint(250, 0));
|
||||
assertEquals(100, resolutionConstraint(100, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsZoomIn() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(500, resolutionConstraint(1000, 1));
|
||||
assertEquals(250, resolutionConstraint(500, 1));
|
||||
assertEquals(100, resolutionConstraint(250, 1));
|
||||
assertEquals(100, resolutionConstraint(100, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsZoomOut() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1000, -1));
|
||||
assertEquals(1000, resolutionConstraint(500, -1));
|
||||
assertEquals(500, resolutionConstraint(250, -1));
|
||||
assertEquals(250, resolutionConstraint(100, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1050, 0));
|
||||
assertEquals(1000, resolutionConstraint(950, 0));
|
||||
assertEquals(500, resolutionConstraint(550, 0));
|
||||
assertEquals(500, resolutionConstraint(400, 0));
|
||||
assertEquals(250, resolutionConstraint(300, 0));
|
||||
assertEquals(250, resolutionConstraint(200, 0));
|
||||
assertEquals(100, resolutionConstraint(150, 0));
|
||||
assertEquals(100, resolutionConstraint(50, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZoomIn() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(500, resolutionConstraint(1050, 1));
|
||||
assertEquals(500, resolutionConstraint(950, 1));
|
||||
assertEquals(250, resolutionConstraint(550, 1));
|
||||
assertEquals(250, resolutionConstraint(450, 1));
|
||||
assertEquals(100, resolutionConstraint(300, 1));
|
||||
assertEquals(100, resolutionConstraint(200, 1));
|
||||
assertEquals(100, resolutionConstraint(150, 1));
|
||||
assertEquals(100, resolutionConstraint(50, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZoomOut() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1050, -1));
|
||||
assertEquals(1000, resolutionConstraint(950, -1));
|
||||
assertEquals(1000, resolutionConstraint(550, -1));
|
||||
assertEquals(1000, resolutionConstraint(450, -1));
|
||||
assertEquals(500, resolutionConstraint(300, -1));
|
||||
assertEquals(500, resolutionConstraint(200, -1));
|
||||
assertEquals(250, resolutionConstraint(150, -1));
|
||||
assertEquals(250, resolutionConstraint(50, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, resolutionConstraint(1024, 0));
|
||||
assertEquals(512, resolutionConstraint(512, 0));
|
||||
assertEquals(256, resolutionConstraint(256, 0));
|
||||
assertEquals(128, resolutionConstraint(128, 0));
|
||||
assertEquals(64, resolutionConstraint(64, 0));
|
||||
assertEquals(32, resolutionConstraint(32, 0));
|
||||
assertEquals(16, resolutionConstraint(16, 0));
|
||||
assertEquals(8, resolutionConstraint(8, 0));
|
||||
assertEquals(4, resolutionConstraint(4, 0));
|
||||
assertEquals(2, resolutionConstraint(2, 0));
|
||||
assertEquals(1, resolutionConstraint(1, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZoomIn() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(512, resolutionConstraint(1024, 1));
|
||||
assertEquals(256, resolutionConstraint(512, 1));
|
||||
assertEquals(128, resolutionConstraint(256, 1));
|
||||
assertEquals(64, resolutionConstraint(128, 1));
|
||||
assertEquals(32, resolutionConstraint(64, 1));
|
||||
assertEquals(16, resolutionConstraint(32, 1));
|
||||
assertEquals(8, resolutionConstraint(16, 1));
|
||||
assertEquals(4, resolutionConstraint(8, 1));
|
||||
assertEquals(2, resolutionConstraint(4, 1));
|
||||
assertEquals(1, resolutionConstraint(2, 1));
|
||||
assertEquals(1, resolutionConstraint(1, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZoomOut() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, resolutionConstraint(1024, -1));
|
||||
assertEquals(1024, resolutionConstraint(512, -1));
|
||||
assertEquals(512, resolutionConstraint(256, -1));
|
||||
assertEquals(256, resolutionConstraint(128, -1));
|
||||
assertEquals(128, resolutionConstraint(64, -1));
|
||||
assertEquals(64, resolutionConstraint(32, -1));
|
||||
assertEquals(32, resolutionConstraint(16, -1));
|
||||
assertEquals(16, resolutionConstraint(8, -1));
|
||||
assertEquals(8, resolutionConstraint(4, -1));
|
||||
assertEquals(4, resolutionConstraint(2, -1));
|
||||
assertEquals(2, resolutionConstraint(1, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerNearestZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, resolutionConstraint(1050, 0));
|
||||
assertEquals(1024, resolutionConstraint(9050, 0));
|
||||
assertEquals(512, resolutionConstraint(550, 0));
|
||||
assertEquals(512, resolutionConstraint(450, 0));
|
||||
assertEquals(256, resolutionConstraint(300, 0));
|
||||
assertEquals(256, resolutionConstraint(250, 0));
|
||||
assertEquals(128, resolutionConstraint(150, 0));
|
||||
assertEquals(128, resolutionConstraint(100, 0));
|
||||
assertEquals(64, resolutionConstraint(75, 0));
|
||||
assertEquals(64, resolutionConstraint(50, 0));
|
||||
assertEquals(32, resolutionConstraint(40, 0));
|
||||
assertEquals(32, resolutionConstraint(30, 0));
|
||||
assertEquals(16, resolutionConstraint(20, 0));
|
||||
assertEquals(16, resolutionConstraint(12, 0));
|
||||
assertEquals(8, resolutionConstraint(9, 0));
|
||||
assertEquals(8, resolutionConstraint(7, 0));
|
||||
assertEquals(4, resolutionConstraint(5, 0));
|
||||
assertEquals(4, resolutionConstraint(3.5, 0));
|
||||
assertEquals(2, resolutionConstraint(2.1, 0));
|
||||
assertEquals(2, resolutionConstraint(1.9, 0));
|
||||
assertEquals(1, resolutionConstraint(1.1, 0));
|
||||
assertEquals(1, resolutionConstraint(0.9, 0));
|
||||
}
|
||||
@@ -3,24 +3,25 @@ goog.provide('ol.control.ShiftDragRotateAndZoom');
|
||||
goog.require('goog.math.Vec2');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Drag');
|
||||
goog.require('ol.control.ZoomFunctionType');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Drag}
|
||||
* @param {ol.control.ZoomFunctionType=} opt_zoomFunction Zoom function.
|
||||
* @param {ol.control.ResolutionConstraintType=} opt_resolutionConstraint
|
||||
* Resolution constraint.
|
||||
*/
|
||||
ol.control.ShiftDragRotateAndZoom = function(opt_zoomFunction) {
|
||||
ol.control.ShiftDragRotateAndZoom = function(opt_resolutionConstraint) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.control.ZoomFunctionType|undefined}
|
||||
* @type {ol.control.ResolutionConstraintType|undefined}
|
||||
*/
|
||||
this.zoomFunction_ = opt_zoomFunction;
|
||||
this.resolutionConstraint_ = opt_resolutionConstraint;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.ShiftDragRotateAndZoom, ol.control.Drag);
|
||||
@@ -55,8 +56,8 @@ ol.control.ShiftDragRotateAndZoom.prototype.handleDrag =
|
||||
// FIXME this should use map.withFrozenRendering but an assertion fails :-(
|
||||
map.setRotation(this.startRotation_ - theta);
|
||||
var resolution = this.startRatio_ * delta.magnitude();
|
||||
if (goog.isDef(this.zoomFunction_)) {
|
||||
resolution = this.zoomFunction_(resolution, 0);
|
||||
if (goog.isDef(this.resolutionConstraint_)) {
|
||||
resolution = this.resolutionConstraint_(resolution, 0);
|
||||
}
|
||||
map.setResolution(resolution);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ goog.provide('ol.control.ShiftDragZoom');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Drag');
|
||||
goog.require('ol.control.ZoomFunctionType');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
|
||||
|
||||
/**
|
||||
@@ -25,17 +25,18 @@ ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS_SQUARED =
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Drag}
|
||||
* @param {ol.control.ZoomFunctionType=} opt_zoomFunction Zoom function.
|
||||
* @param {ol.control.ResolutionConstraintType=} opt_resolutionConstraint
|
||||
* Resolution constraint.
|
||||
*/
|
||||
ol.control.ShiftDragZoom = function(opt_zoomFunction) {
|
||||
ol.control.ShiftDragZoom = function(opt_resolutionConstraint) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.control.ZoomFunctionType|undefined}
|
||||
* @type {ol.control.ResolutionConstraintType|undefined}
|
||||
*/
|
||||
this.zoomFunction_ = opt_zoomFunction;
|
||||
this.resolutionConstraint_ = opt_resolutionConstraint;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.ShiftDragZoom, ol.control.Drag);
|
||||
@@ -52,8 +53,8 @@ ol.control.ShiftDragZoom.prototype.handleDragEnd = function(mapBrowserEvent) {
|
||||
this.startCoordinate,
|
||||
mapBrowserEvent.getCoordinate());
|
||||
var resolution = map.getResolutionForExtent(extent);
|
||||
if (goog.isDef(this.zoomFunction_)) {
|
||||
resolution = this.zoomFunction_(resolution, 0);
|
||||
if (goog.isDef(this.resolutionConstraint_)) {
|
||||
resolution = this.resolutionConstraint_(resolution, 0);
|
||||
}
|
||||
map.withFrozenRendering(function() {
|
||||
map.setCenter(extent.getCenter());
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.control.ZoomFunction');
|
||||
|
||||
|
||||
function testSnapToResolutionsZero() {
|
||||
var zoomFunction =
|
||||
ol.control.ZoomFunction.createSnapToResolutions([1000, 500, 250, 100]);
|
||||
assertEquals(1000, zoomFunction(1000, 0));
|
||||
assertEquals(500, zoomFunction(500, 0));
|
||||
assertEquals(250, zoomFunction(250, 0));
|
||||
assertEquals(100, zoomFunction(100, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsZoomIn() {
|
||||
var zoomFunction =
|
||||
ol.control.ZoomFunction.createSnapToResolutions([1000, 500, 250, 100]);
|
||||
assertEquals(500, zoomFunction(1000, 1));
|
||||
assertEquals(250, zoomFunction(500, 1));
|
||||
assertEquals(100, zoomFunction(250, 1));
|
||||
assertEquals(100, zoomFunction(100, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsZoomOut() {
|
||||
var zoomFunction =
|
||||
ol.control.ZoomFunction.createSnapToResolutions([1000, 500, 250, 100]);
|
||||
assertEquals(1000, zoomFunction(1000, -1));
|
||||
assertEquals(1000, zoomFunction(500, -1));
|
||||
assertEquals(500, zoomFunction(250, -1));
|
||||
assertEquals(250, zoomFunction(100, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZero() {
|
||||
var zoomFunction =
|
||||
ol.control.ZoomFunction.createSnapToResolutions([1000, 500, 250, 100]);
|
||||
assertEquals(1000, zoomFunction(1050, 0));
|
||||
assertEquals(1000, zoomFunction(950, 0));
|
||||
assertEquals(500, zoomFunction(550, 0));
|
||||
assertEquals(500, zoomFunction(400, 0));
|
||||
assertEquals(250, zoomFunction(300, 0));
|
||||
assertEquals(250, zoomFunction(200, 0));
|
||||
assertEquals(100, zoomFunction(150, 0));
|
||||
assertEquals(100, zoomFunction(50, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZoomIn() {
|
||||
var zoomFunction =
|
||||
ol.control.ZoomFunction.createSnapToResolutions([1000, 500, 250, 100]);
|
||||
assertEquals(500, zoomFunction(1050, 1));
|
||||
assertEquals(500, zoomFunction(950, 1));
|
||||
assertEquals(250, zoomFunction(550, 1));
|
||||
assertEquals(250, zoomFunction(450, 1));
|
||||
assertEquals(100, zoomFunction(300, 1));
|
||||
assertEquals(100, zoomFunction(200, 1));
|
||||
assertEquals(100, zoomFunction(150, 1));
|
||||
assertEquals(100, zoomFunction(50, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZoomOut() {
|
||||
var zoomFunction =
|
||||
ol.control.ZoomFunction.createSnapToResolutions([1000, 500, 250, 100]);
|
||||
assertEquals(1000, zoomFunction(1050, -1));
|
||||
assertEquals(1000, zoomFunction(950, -1));
|
||||
assertEquals(1000, zoomFunction(550, -1));
|
||||
assertEquals(1000, zoomFunction(450, -1));
|
||||
assertEquals(500, zoomFunction(300, -1));
|
||||
assertEquals(500, zoomFunction(200, -1));
|
||||
assertEquals(250, zoomFunction(150, -1));
|
||||
assertEquals(250, zoomFunction(50, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZero() {
|
||||
var zoomFunction = ol.control.ZoomFunction.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, zoomFunction(1024, 0));
|
||||
assertEquals(512, zoomFunction(512, 0));
|
||||
assertEquals(256, zoomFunction(256, 0));
|
||||
assertEquals(128, zoomFunction(128, 0));
|
||||
assertEquals(64, zoomFunction(64, 0));
|
||||
assertEquals(32, zoomFunction(32, 0));
|
||||
assertEquals(16, zoomFunction(16, 0));
|
||||
assertEquals(8, zoomFunction(8, 0));
|
||||
assertEquals(4, zoomFunction(4, 0));
|
||||
assertEquals(2, zoomFunction(2, 0));
|
||||
assertEquals(1, zoomFunction(1, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZoomIn() {
|
||||
var zoomFunction = ol.control.ZoomFunction.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(512, zoomFunction(1024, 1));
|
||||
assertEquals(256, zoomFunction(512, 1));
|
||||
assertEquals(128, zoomFunction(256, 1));
|
||||
assertEquals(64, zoomFunction(128, 1));
|
||||
assertEquals(32, zoomFunction(64, 1));
|
||||
assertEquals(16, zoomFunction(32, 1));
|
||||
assertEquals(8, zoomFunction(16, 1));
|
||||
assertEquals(4, zoomFunction(8, 1));
|
||||
assertEquals(2, zoomFunction(4, 1));
|
||||
assertEquals(1, zoomFunction(2, 1));
|
||||
assertEquals(1, zoomFunction(1, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZoomOut() {
|
||||
var zoomFunction = ol.control.ZoomFunction.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, zoomFunction(1024, -1));
|
||||
assertEquals(1024, zoomFunction(512, -1));
|
||||
assertEquals(512, zoomFunction(256, -1));
|
||||
assertEquals(256, zoomFunction(128, -1));
|
||||
assertEquals(128, zoomFunction(64, -1));
|
||||
assertEquals(64, zoomFunction(32, -1));
|
||||
assertEquals(32, zoomFunction(16, -1));
|
||||
assertEquals(16, zoomFunction(8, -1));
|
||||
assertEquals(8, zoomFunction(4, -1));
|
||||
assertEquals(4, zoomFunction(2, -1));
|
||||
assertEquals(2, zoomFunction(1, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerNearestZero() {
|
||||
var zoomFunction = ol.control.ZoomFunction.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, zoomFunction(1050, 0));
|
||||
assertEquals(1024, zoomFunction(9050, 0));
|
||||
assertEquals(512, zoomFunction(550, 0));
|
||||
assertEquals(512, zoomFunction(450, 0));
|
||||
assertEquals(256, zoomFunction(300, 0));
|
||||
assertEquals(256, zoomFunction(250, 0));
|
||||
assertEquals(128, zoomFunction(150, 0));
|
||||
assertEquals(128, zoomFunction(100, 0));
|
||||
assertEquals(64, zoomFunction(75, 0));
|
||||
assertEquals(64, zoomFunction(50, 0));
|
||||
assertEquals(32, zoomFunction(40, 0));
|
||||
assertEquals(32, zoomFunction(30, 0));
|
||||
assertEquals(16, zoomFunction(20, 0));
|
||||
assertEquals(16, zoomFunction(12, 0));
|
||||
assertEquals(8, zoomFunction(9, 0));
|
||||
assertEquals(8, zoomFunction(7, 0));
|
||||
assertEquals(4, zoomFunction(5, 0));
|
||||
assertEquals(4, zoomFunction(3.5, 0));
|
||||
assertEquals(2, zoomFunction(2.1, 0));
|
||||
assertEquals(2, zoomFunction(1.9, 0));
|
||||
assertEquals(1, zoomFunction(1.1, 0));
|
||||
assertEquals(1, zoomFunction(0.9, 0));
|
||||
}
|
||||
Reference in New Issue
Block a user