Constraint objects moved to ol namespace from ol.interaction namespace
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
goog.provide('ol.interaction.CenterConstraint');
|
||||
goog.provide('ol.interaction.CenterConstraintType');
|
||||
|
||||
goog.require('ol.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((ol.Coordinate|undefined),
|
||||
* (number|undefined),
|
||||
* ol.Coordinate): (ol.Coordinate|undefined)}
|
||||
*/
|
||||
ol.interaction.CenterConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {ol.Coordinate} delta Delta.
|
||||
* @return {ol.Coordinate|undefined} Center.
|
||||
*/
|
||||
ol.interaction.CenterConstraint.none = function(center, resolution, delta) {
|
||||
if (goog.isDefAndNotNull(center) && goog.isDef(resolution)) {
|
||||
var x = center.x + delta.x;
|
||||
var y = center.y + delta.y;
|
||||
return new ol.Coordinate(x, y);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {ol.Coordinate} delta Delta.
|
||||
* @return {ol.Coordinate|undefined} Center.
|
||||
*/
|
||||
ol.interaction.CenterConstraint.snapToPixel =
|
||||
function(center, resolution, delta) {
|
||||
if (goog.isDefAndNotNull(center) && goog.isDef(resolution)) {
|
||||
var x = Math.floor((center.x + delta.x) / resolution + 0.5) * resolution;
|
||||
var y = Math.floor((center.y + delta.y) / resolution + 0.5) * resolution;
|
||||
return new ol.Coordinate(x, y);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
goog.provide('ol.interaction.Constraints');
|
||||
|
||||
goog.require('ol.interaction.CenterConstraintType');
|
||||
goog.require('ol.interaction.ResolutionConstraintType');
|
||||
goog.require('ol.interaction.RotationConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.interaction.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
* @param {ol.interaction.RotationConstraintType} rotationConstraint
|
||||
* Rotation constraint.
|
||||
*/
|
||||
ol.interaction.Constraints =
|
||||
function(resolutionConstraint, rotationConstraint) {
|
||||
|
||||
/**
|
||||
* @type {ol.interaction.ResolutionConstraintType}
|
||||
*/
|
||||
this.resolution = resolutionConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol.interaction.RotationConstraintType}
|
||||
*/
|
||||
this.rotation = rotationConstraint;
|
||||
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
goog.provide('ol.interaction.ResolutionConstraint');
|
||||
goog.provide('ol.interaction.ResolutionConstraintType');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.array');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol.interaction.ResolutionConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
* @param {number=} opt_minResolution Minimum resolution.
|
||||
* @return {ol.interaction.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.interaction.ResolutionConstraint.createContinuous =
|
||||
function(power, maxResolution, opt_minResolution) {
|
||||
var minResolution = opt_minResolution || 0;
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
resolution /= Math.pow(power, delta);
|
||||
return goog.math.clamp(resolution, minResolution, maxResolution);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} resolutions Resolutions.
|
||||
* @return {ol.interaction.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.interaction.ResolutionConstraint.createSnapToResolutions =
|
||||
function(resolutions) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var z = ol.array.linearFindNearest(resolutions, resolution);
|
||||
z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
|
||||
return resolutions[z];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
* @param {number=} opt_maxLevel Maximum level.
|
||||
* @return {ol.interaction.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.interaction.ResolutionConstraint.createSnapToPower =
|
||||
function(power, maxResolution, opt_maxLevel) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var oldLevel = Math.floor(
|
||||
Math.log(maxResolution / resolution) / Math.log(power) + 0.5);
|
||||
var newLevel = Math.max(oldLevel + delta, 0);
|
||||
if (goog.isDef(opt_maxLevel)) {
|
||||
newLevel = Math.min(newLevel, opt_maxLevel);
|
||||
}
|
||||
return maxResolution / Math.pow(power, newLevel);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
goog.provide('ol.interaction.RotationConstraint');
|
||||
goog.provide('ol.interaction.RotationConstraintType');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol.interaction.RotationConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} rotation Rotation.
|
||||
* @param {number} delta Delta.
|
||||
* @return {number|undefined} Rotation.
|
||||
*/
|
||||
ol.interaction.RotationConstraint.none = function(rotation, delta) {
|
||||
if (goog.isDef(rotation)) {
|
||||
return rotation + delta;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} n N.
|
||||
* @return {ol.interaction.RotationConstraintType} Rotation constraint.
|
||||
*/
|
||||
ol.interaction.RotationConstraint.createSnapToN = function(n) {
|
||||
var theta = 2 * Math.PI / n;
|
||||
return function(rotation, delta) {
|
||||
if (goog.isDef(rotation)) {
|
||||
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
|
||||
return rotation;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user