Improve type checking in ol.ResolutionConstraint

This commit is contained in:
Tom Payne
2013-04-30 21:32:05 +02:00
parent 2690410cbe
commit bd9d723315
+29 -7
View File
@@ -20,14 +20,21 @@ ol.ResolutionConstraintType;
ol.ResolutionConstraint.createContinuous = ol.ResolutionConstraint.createContinuous =
function(power, maxResolution, opt_minResolution) { function(power, maxResolution, opt_minResolution) {
var minResolution = opt_minResolution || 0; 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)) { if (goog.isDef(resolution)) {
resolution /= Math.pow(power, delta); resolution /= Math.pow(power, delta);
return goog.math.clamp(resolution, minResolution, maxResolution); return goog.math.clamp(resolution, minResolution, maxResolution);
} else { } else {
return undefined; return undefined;
} }
}; });
}; };
@@ -37,15 +44,23 @@ ol.ResolutionConstraint.createContinuous =
*/ */
ol.ResolutionConstraint.createSnapToResolutions = ol.ResolutionConstraint.createSnapToResolutions =
function(resolutions) { 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)) { 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); z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
return resolutions[z]; return resolutions[z];
} else { } else {
return undefined; return undefined;
} }
}; });
}; };
@@ -57,7 +72,14 @@ ol.ResolutionConstraint.createSnapToResolutions =
*/ */
ol.ResolutionConstraint.createSnapToPower = ol.ResolutionConstraint.createSnapToPower =
function(power, maxResolution, opt_maxLevel) { 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)) { if (goog.isDef(resolution)) {
var offset; var offset;
if (direction > 0) { if (direction > 0) {
@@ -77,5 +99,5 @@ ol.ResolutionConstraint.createSnapToPower =
} else { } else {
return undefined; return undefined;
} }
}; });
}; };