Improve type checking in ol.ResolutionConstraint
This commit is contained in:
@@ -20,14 +20,21 @@ ol.ResolutionConstraintType;
|
||||
ol.ResolutionConstraint.createContinuous =
|
||||
function(power, maxResolution, opt_minResolution) {
|
||||
var minResolution = opt_minResolution || 0;
|
||||
return function(resolution, delta, direction) {
|
||||
return (
|
||||
/**
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {number} delta Delta.
|
||||
* @param {number} direction Direction.
|
||||
* @return {number|undefined} Resolution.
|
||||
*/
|
||||
function(resolution, delta, direction) {
|
||||
if (goog.isDef(resolution)) {
|
||||
resolution /= Math.pow(power, delta);
|
||||
return goog.math.clamp(resolution, minResolution, maxResolution);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -37,15 +44,23 @@ ol.ResolutionConstraint.createContinuous =
|
||||
*/
|
||||
ol.ResolutionConstraint.createSnapToResolutions =
|
||||
function(resolutions) {
|
||||
return function(resolution, delta, direction) {
|
||||
return (
|
||||
/**
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {number} delta Delta.
|
||||
* @param {number} direction Direction.
|
||||
* @return {number|undefined} Resolution.
|
||||
*/
|
||||
function(resolution, delta, direction) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var z = ol.array.linearFindNearest(resolutions, resolution, direction);
|
||||
var z =
|
||||
ol.array.linearFindNearest(resolutions, resolution, direction);
|
||||
z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
|
||||
return resolutions[z];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +72,14 @@ ol.ResolutionConstraint.createSnapToResolutions =
|
||||
*/
|
||||
ol.ResolutionConstraint.createSnapToPower =
|
||||
function(power, maxResolution, opt_maxLevel) {
|
||||
return function(resolution, delta, direction) {
|
||||
return (
|
||||
/**
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {number} delta Delta.
|
||||
* @param {number} direction Direction.
|
||||
* @return {number|undefined} Resolution.
|
||||
*/
|
||||
function(resolution, delta, direction) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var offset;
|
||||
if (direction > 0) {
|
||||
@@ -77,5 +99,5 @@ ol.ResolutionConstraint.createSnapToPower =
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user