From 1c003b5ab11e3c213776d62a2137961ce329dbf2 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 17 Jun 2013 16:45:40 +0200 Subject: [PATCH] Add ol.CenterConstraint --- src/ol/centerconstraint.js | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/ol/centerconstraint.js diff --git a/src/ol/centerconstraint.js b/src/ol/centerconstraint.js new file mode 100644 index 0000000000..2cc4db9592 --- /dev/null +++ b/src/ol/centerconstraint.js @@ -0,0 +1,42 @@ +goog.provide('ol.CenterConstraint'); +goog.provide('ol.CenterConstraintType'); + +goog.require('goog.math'); + + +/** + * @typedef {function((ol.Coordinate|undefined)): (ol.Coordinate|undefined)} + */ +ol.CenterConstraintType; + + +/** + * @param {ol.Extent} extent Extent. + * @return {ol.CenterConstraintType} + */ +ol.CenterConstraint.createExtent = function(extent) { + return ( + /** + * @param {ol.Coordinate|undefined} center Center. + * @return {ol.Coordinate|undefined} Center. + */ + function(center) { + if (goog.isDef(center)) { + return [ + goog.math.clamp(center[0], extent[0], extent[2]), + goog.math.clamp(center[1], extent[1], extent[3]) + ]; + } else { + return undefined; + } + }); +}; + + +/** + * @param {ol.Coordinate|undefined} center Center. + * @return {ol.Coordinate|undefined} Center. + */ +ol.CenterConstraint.none = function(center) { + return center; +};