From b06a52888f8c06cca02bf9962ef1c60fd99b4f03 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 20 Jun 2012 00:11:06 +0200 Subject: [PATCH] Adding unreferenced bounds. --- src/api/bounds.js | 2 +- src/ol/Bounds.js | 84 +++++++------------------- src/ol/Projection.js | 52 +++++++++++----- src/ol/UnreferencedBounds.js | 102 ++++++++++++++++++++++++++++++++ test/spec/ol/Projection.test.js | 4 +- 5 files changed, 165 insertions(+), 79 deletions(-) create mode 100644 src/ol/UnreferencedBounds.js diff --git a/src/api/bounds.js b/src/api/bounds.js index 2eed88cf26..8031dd7ec9 100644 --- a/src/api/bounds.js +++ b/src/api/bounds.js @@ -72,7 +72,7 @@ ol.Bounds.prototype.projection = function(opt_arg){ /** * @export * @param {number=} opt_arg Minimum X. - * @return {ol.Bounds|number} Result. + * @return {!ol.Bounds|number} Result. */ ol.Bounds.prototype.minX = function(opt_arg){ if (arguments.length == 1 && goog.isDef(opt_arg)) { diff --git a/src/ol/Bounds.js b/src/ol/Bounds.js index 0b9d7ddf9d..dafc0f2b7c 100644 --- a/src/ol/Bounds.js +++ b/src/ol/Bounds.js @@ -1,9 +1,7 @@ goog.provide('ol.Bounds'); - +goog.require('ol.UnreferencedBounds'); goog.require('ol.Projection'); - - /** * @constructor * @param {number} minX Minimum X. @@ -11,6 +9,7 @@ goog.require('ol.Projection'); * @param {number} maxX Maximum X. * @param {number} maxY Maximum Y. * @param {ol.Projection=} opt_projection Projection. + * @extends {ol.UnreferencedBounds} */ ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) { @@ -45,40 +44,44 @@ ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) { this.projection_ = opt_projection; }; - +goog.inherits(ol.Bounds, ol.UnreferencedBounds); /** - * @return {number} Minimun X. + * @param {number} minX Minimum X. + * @return {!ol.Bounds} This. */ -ol.Bounds.prototype.getMinX = function() { - return this.minX_; +ol.Bounds.prototype.setMinX = function(minX) { + this.minX_ = minX; + return this; }; - /** - * @return {number} Minimun Y. + * @param {number} maxX Maximum X. + * @return {!ol.Bounds} This. */ -ol.Bounds.prototype.getMinY = function() { - return this.minY_; +ol.Bounds.prototype.setMaxX = function(maxX) { + this.maxX_ = maxX; + return this; }; - /** - * @return {number} Maximun X. + * @param {number} minY Minimum Y. + * @return {!ol.Bounds} This. */ -ol.Bounds.prototype.getMaxX = function() { - return this.maxX_; +ol.Bounds.prototype.setMinY = function(minY) { + this.minY_ = minY; + return this; }; - /** - * @return {number} Maximun Y. + * @param {number} maxY Maximum Y. + * @return {!ol.Bounds} This. */ -ol.Bounds.prototype.getMaxY = function() { - return this.maxY_; +ol.Bounds.prototype.setMaxY = function(maxY) { + this.maxY_ = maxY; + return this; }; - /** * @return {ol.Projection|undefined} Projection. */ @@ -86,47 +89,6 @@ 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. diff --git a/src/ol/Projection.js b/src/ol/Projection.js index b40619ba54..43d0e64a04 100644 --- a/src/ol/Projection.js +++ b/src/ol/Projection.js @@ -1,4 +1,5 @@ goog.provide('ol.Projection'); +goog.require('ol.UnreferencedBounds'); /** * @constructor @@ -20,10 +21,16 @@ ol.Projection = function(code) { /** * @private - * @type {Object|undefined} + * @type {!Object|undefined} */ this.proj_ = undefined; + /** + * @private + * @type {!ol.UnreferencedBounds|undefined} + */ + this.extent_ = undefined; + }; @@ -36,7 +43,7 @@ ol.Projection.prototype.getCode = function() { /** * @param {string} code Code. - * @return {ol.Projection} This. + * @return {!ol.Projection} This. */ ol.Projection.prototype.setCode = function(code) { this.code_ = code; @@ -46,10 +53,10 @@ ol.Projection.prototype.setCode = function(code) { /** * @export * @param {string=} opt_code Code. - * @return {ol.Projection|string} Result. + * @return {!ol.Projection|string} Result. */ ol.Projection.prototype.code = function(opt_code){ - if (goog.isDef(opt_code)) { + if (arguments.length == 1 && goog.isDef(opt_code)) { return this.setCode(opt_code); } else { @@ -58,7 +65,7 @@ ol.Projection.prototype.code = function(opt_code){ }; /** - * @return {string|undefined} Code. + * @return {string|undefined} Units abbreviation. */ ol.Projection.prototype.getUnits = function() { return this.units_; @@ -66,17 +73,36 @@ ol.Projection.prototype.getUnits = function() { /** * @param {string} units Units abbreviation. - * @return {ol.Projection} This. + * @return {!ol.Projection} This. */ ol.Projection.prototype.setUnits = function(units) { this.units_ = units; return this; }; +/** + * Get the validity extent of the coordinate reference system. + * + * @return {!ol.UnreferencedBounds|undefined} The valididty extent. + */ +ol.Projection.prototype.getExtent = function() { + return this.extent_; +}; + +/** + * @param {!ol.UnreferencedBounds} extent Validity extent. + * @return {ol.Projection} This. + */ +ol.Projection.prototype.setExtent = function(extent) { + this.extent_ = extent; + return this; +}; + /** * @export * @param {string=} opt_units Units abbreviation. - * @return {undefined|ol.Projection|string} Result. + * @return {undefined|!ol.Projection|string} Result. + * TODO: move to api folder */ ol.Projection.prototype.units = function(opt_units){ if (goog.isDef(opt_units)) { @@ -163,18 +189,12 @@ ol.Projection.addTransform = function(from, to, method) { /** * Transform a point coordinate from one projection to another. * - * @param {Object} point Object with x and y properties. - * @param {!string|!ol.Projection} source Source projection. - * @param {!string|!ol.Projection} dest Destination projection. + * @param {!Object} point Object with x and y properties. + * @param {!ol.Projection} source Source projection. + * @param {!ol.Projection} dest Destination projection. * @private */ ol.Projection.transform = function(point, source, dest) { - if (!(source instanceof ol.Projection)) { - source = new ol.Projection(source); - } - if (!(dest instanceof ol.Projection)) { - dest = new ol.Projection(dest); - } if (source.proj_ && dest.proj_) { // point = Proj4js.transform(source.proj_, dest.proj_, point); } else { diff --git a/src/ol/UnreferencedBounds.js b/src/ol/UnreferencedBounds.js new file mode 100644 index 0000000000..f4688d503d --- /dev/null +++ b/src/ol/UnreferencedBounds.js @@ -0,0 +1,102 @@ +goog.provide('ol.UnreferencedBounds'); + +/** + * @constructor + * @param {number} minX Minimum X. + * @param {number} minY Minimum Y. + * @param {number} maxX Maximum X. + * @param {number} maxY Maximum Y. + */ +ol.UnreferencedBounds = function(minX, minY, maxX, maxY) { + + /** + * @private + * @type {number} + */ + this.minX_ = minX; + + /** + * @private + * @type {number} + */ + this.minY_ = minY; + + /** + * @private + * @type {number} + */ + this.maxX_ = maxX; + + /** + * @private + * @type {number} + */ + this.maxY_ = maxY; + +}; + + +/** + * @return {number} Minimun X. + */ +ol.UnreferencedBounds.prototype.getMinX = function() { + return this.minX_; +}; + +/** + * @param {number} minX Minimum X. + * @return {ol.UnreferencedBounds} This. + */ +ol.UnreferencedBounds.prototype.setMinX = function(minX) { + this.minX_ = minX; + return this; +}; + +/** + * @return {number} Minimun Y. + */ +ol.UnreferencedBounds.prototype.getMinY = function() { + return this.minY_; +}; + +/** + * @param {number} minY Minimum Y. + * @return {ol.UnreferencedBounds} This. + */ +ol.UnreferencedBounds.prototype.setMinY = function(minY) { + this.minY_ = minY; + return this; +}; + +/** + * @return {number} Maximun X. + */ +ol.UnreferencedBounds.prototype.getMaxX = function() { + return this.maxX_; +}; + +/** + * @param {number} maxX Maximum X. + * @return {ol.UnreferencedBounds} This. + */ +ol.UnreferencedBounds.prototype.setMaxX = function(maxX) { + this.maxX_ = maxX; + return this; +}; + +/** + * @return {number} Maximun Y. + */ +ol.UnreferencedBounds.prototype.getMaxY = function() { + return this.maxY_; +}; + +/** + * @param {number} maxY Maximum Y. + * @return {ol.UnreferencedBounds} This. + */ +ol.UnreferencedBounds.prototype.setMaxY = function(maxY) { + this.maxY_ = maxY; + return this; +}; + diff --git a/test/spec/ol/Projection.test.js b/test/spec/ol/Projection.test.js index 950b90fe7b..7167933765 100644 --- a/test/spec/ol/Projection.test.js +++ b/test/spec/ol/Projection.test.js @@ -29,7 +29,9 @@ describe("ol.Projection", function() { var point = {x: 10, y: 20, z: 30}; - var ret = ol.Projection.transform(point, "EPSG:4326", "EPSG:900913"); + var to = new ol.Projection("EPSG:4326"); + var from = new ol.Projection("EPSG:900913"); + var ret = ol.Projection.transform(point, to, from); expect(ret).toBeUndefined();