From da7449454ee38c749529a21bfbaadc1264b8b369 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 19 Jun 2012 11:56:48 +0200 Subject: [PATCH] Pass bounds spec. --- src/api/bounds.js | 135 +++++++++++++++++++++++++++++++++++++++++++++ src/ol.js | 1 + src/ol/Bounds.js | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 273 insertions(+) create mode 100644 src/api/bounds.js create mode 100644 src/ol/Bounds.js diff --git a/src/api/bounds.js b/src/api/bounds.js new file mode 100644 index 0000000000..e5bb790280 --- /dev/null +++ b/src/api/bounds.js @@ -0,0 +1,135 @@ +goog.provide('ol.bounds'); + +goog.require('ol.Bounds'); +goog.require('ol.projection'); + + +/** + * @typedef {ol.Bounds|Array.|Object} bounds Location. + */ +ol.LocLike; + + + +/** + * @export + * @param {ol.LocLike} opt_arg Location. + * @return {ol.Bounds} Location. + */ +ol.bounds = function(opt_arg){ + + if (opt_arg instanceof ol.Bounds) { + return opt_arg; + } + + var minX = 0; + var minY = 0; + var maxX = 0; + var maxY = 0; + var projection; + + var x = 0; + var y = 0; + var z; + var projection; + + if (goog.isArray(opt_arg)) { + minX = opt_arg[0]; + minY = opt_arg[1]; + maxX = opt_arg[2]; + maxY = opt_arg[3]; + } else if (goog.isObject(opt_arg)) { + minX = opt_arg['minX']; + minY = opt_arg['minY']; + maxX = opt_arg['maxX']; + maxY = opt_arg['maxY']; + projection = ol.projection(opt_arg['projection']); + } + else { + throw new Error('ol.bounds'); + } + + var bounds = new ol.Bounds(); + bounds.setMinX(minX); + bounds.setMinY(minY); + bounds.setMaxX(maxX); + bounds.setMaxY(maxY); + bounds.setProjection(projection); + return bounds; + +}; + + +/** + * @export + * @param {ol.Projection=} opt_arg Projection. + * @return {ol.Bounds|ol.Projection|undefined} Result. + */ +ol.Bounds.prototype.projection = function(opt_arg){ + if (arguments.length == 1 && goog.isDef(opt_arg)) { + return this.setProjection(opt_arg); + } + else { + return this.getProjection(); + } +}; + + +/** + * @export + * @param {number=} opt_arg Minimum X. + * @return {ol.Bounds|number} Result. + */ +ol.Bounds.prototype.minX = function(opt_arg){ + if (arguments.length == 1 && goog.isDef(opt_arg)) { + return this.setMinX(opt_arg); + } + else { + return this.getMinX(); + } +}; + + +/** + * @export + * @param {number=} opt_arg Minimum Y. + * @return {ol.Bounds|number} Result. + */ +ol.Bounds.prototype.minY = function(opt_arg){ + if (arguments.length == 1 && goog.isDef(opt_arg)) { + return this.setMinY(opt_arg); + } + else { + return this.getMinY(); + } +}; + + +/** + * @export + * @param {number=} opt_arg Maximum X. + * @return {ol.Bounds|number} Result. + */ +ol.Bounds.prototype.maxX = function(opt_arg){ + if (arguments.length == 1 && goog.isDef(opt_arg)) { + return this.setMaxX(opt_arg); + } + else { + return this.getMaxX(); + } +}; + + +/** + * @export + * @param {number=} opt_arg Maximum Y. + * @return {ol.Bounds|number} Result. + */ +ol.Bounds.prototype.maxY = function(opt_arg){ + if (arguments.length == 1 && goog.isDef(opt_arg)) { + return this.setMaxY(opt_arg); + } + else { + return this.getMaxY(); + } +}; diff --git a/src/ol.js b/src/ol.js index db0827deb2..baa39356e7 100644 --- a/src/ol.js +++ b/src/ol.js @@ -1,4 +1,5 @@ goog.provide("ol"); +goog.require('ol.bounds'); goog.require("ol.map"); goog.require("ol.loc"); goog.require("ol.projection"); diff --git a/src/ol/Bounds.js b/src/ol/Bounds.js new file mode 100644 index 0000000000..0b8e99179e --- /dev/null +++ b/src/ol/Bounds.js @@ -0,0 +1,137 @@ +goog.provide('ol.Bounds'); + +goog.require('ol.Projection'); + + + +/** + * @constructor + * @param {number} minX Minimum X. + * @param {number} minY Minimum Y. + * @param {number} maxX Maximum X. + * @param {number} maxY Maximum Y. + * @param {ol.Projection=} opt_projection Projection. + */ +ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) { + + /** + * @private + * @type {number} + */ + this.minX_ = minX; + + /** + * @private + * @type {number} + */ + this.minY_ = minY; + + /** + * @private + * @type {number} + */ + this.minX_ = minX; + + /** + * @private + * @type {number} + */ + this.minY_ = minY; + + /** + * @private + * @type {ol.Projection|undefined} + */ + this.projection_ = opt_projection; + +}; + + +/** + * @return {number} Minimun X. + */ +ol.Bounds.prototype.getMinX = function() { + return this.minX_; +}; + + +/** + * @return {number} Minimun Y. + */ +ol.Bounds.prototype.getMinY = function() { + return this.minY_; +}; + + +/** + * @return {number} Maximun X. + */ +ol.Bounds.prototype.getMaxX = function() { + return this.maxX_; +}; + + +/** + * @return {number} Maximun Y. + */ +ol.Bounds.prototype.getMaxY = function() { + return this.maxY_; +}; + + +/** + * @return {ol.Projection|undefined} Projection. + */ +ol.Bounds.prototype.getProjection = function() { + return this.projection_; +}; + + +/** + * @param {number} minX Minimum X. + * @return {ol.Bounds} This. + */ +ol.Bounds.prototype.setMinX = function(minX) { + this.minX_ = minX; + return this; +}; + + +/** + * @param {number} minY Minimum Y. + * @return {ol.Bounds} This. + */ +ol.Bounds.prototype.setMinY = function(minY) { + this.minY_ = minY; + return this; +}; + + +/** + * @param {number} maxX Maximum X. + * @return {ol.Bounds} This. + */ +ol.Bounds.prototype.setMaxX = function(maxX) { + this.maxX_ = maxX; + return this; +}; + + +/** + * @param {number} maxY Maximum Y. + * @return {ol.Bounds} This. + */ +ol.Bounds.prototype.setMaxY = function(maxY) { + this.maxY_ = maxY; + return this; +}; + + +/** + * @param {ol.Projection|undefined} projection Projection. + * @return {ol.Bounds} This. + */ +ol.Bounds.prototype.setProjection = function(projection) { + this.projection_ = projection; + return this; +};