diff --git a/Makefile b/Makefile index e791429b1e..0880a60ece 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,6 @@ GSLINT_EXCLUDES= \ src/api/popup.js \ src/api/projection.js \ src/ol/base.js \ - src/ol/Bounds.js \ src/ol/control/Attribution.js \ src/ol/control/Control.js \ src/ol/control/Navigation.js \ @@ -52,7 +51,6 @@ GSLINT_EXCLUDES= \ src/ol/Tile.js \ src/ol/TileCache.js \ src/ol/TileSet.js \ - src/ol/UnreferencedBounds.js \ src/ol.export.js \ src/ol.js diff --git a/src/all.js b/src/all.js index 62e738a54e..87ba3bbb9e 100644 --- a/src/all.js +++ b/src/all.js @@ -1,5 +1,6 @@ goog.provide('ol'); +goog.require('ol.Bounds'); goog.require('ol.MVCArray'); goog.require('ol.MVCObject'); goog.require('ol.TileBounds'); diff --git a/src/ol/Bounds.js b/src/ol/Bounds.js deleted file mode 100644 index d0676d7c65..0000000000 --- a/src/ol/Bounds.js +++ /dev/null @@ -1,105 +0,0 @@ -goog.provide('ol.Bounds'); - -goog.require('ol.UnreferencedBounds'); -goog.require('ol.Loc'); -goog.require('ol.Projection'); - -goog.require('goog.string.format'); - -/** - * @export - * @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. - * @extends {ol.UnreferencedBounds} - */ -ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) { - - goog.base(this, minX, minY, maxX, maxY); - - /** - * @protected - * @type {ol.Projection} - */ - this.projection_ = goog.isDef(opt_projection) ? opt_projection : null; - -}; -goog.inherits(ol.Bounds, ol.UnreferencedBounds); - -/** - * @return {ol.Projection} Projection. - */ -ol.Bounds.prototype.getProjection = function() { - return this.projection_; -}; - -/** - * @param {ol.Projection} projection Projection. - */ -ol.Bounds.prototype.setProjection = function(projection) { - this.projection_ = projection; -}; - -/** - * Determine if this bounds intersects the target bounds (bounds that only - * touch are considered intersecting). - * - * @param {ol.Bounds} bounds Target bounds. - * @return {boolean} The provided bounds intersects this bounds. - */ -ol.Bounds.prototype.intersects = function(bounds) { - var otherProj = bounds.getProjection(); - if (!goog.isNull(otherProj) && !goog.isNull(this.projection_)) { - bounds = bounds.doTransform(this.projection_); - } - return goog.base(this, "intersects", bounds.toUnreferencedBounds()); -}; - -/** - * Transform this node into another coordinate reference system. Returns a new - * bounds instead of modifying this bounds. - * - * @param {ol.Projection} proj Target projection. - * @return {ol.Bounds} A new bounds in the target projection. - */ -ol.Bounds.prototype.doTransform = function(proj) { - if (goog.isNull(this.projection_)) { - throw new Error("Bounds must have a projection before transforming."); - } - var tl = new ol.Loc( - this.minX_, this.maxY_, undefined, this.projection_).doTransform(proj); - var tr = new ol.Loc( - this.maxX_, this.maxY_, undefined, this.projection_).doTransform(proj); - var bl = new ol.Loc( - this.minX_, this.minY_, undefined, this.projection_).doTransform(proj); - var br = new ol.Loc( - this.maxX_, this.minY_, undefined, this.projection_).doTransform(proj); - - var x = [tl.getX(), tr.getX(), bl.getX(), br.getX()].sort(); - var y = [tl.getY(), tr.getY(), bl.getY(), br.getY()].sort(); - - return new ol.Bounds(x[0], y[0], x[3], y[3], proj); -}; - -/** - * Return a bbox string for this bounds. - * - * @return {string} The "minx,miny,maxx,maxy" representation of this bounds. - */ -ol.Bounds.prototype.toBBOX = function() { - return goog.string.format( - '%f,%f,%f,%f', this.minX_, this.minY_, this.maxX_, this.maxY_); -}; - -/** - * Cast this bounds into an unreferenced bounds. - * - * @returns {ol.UnreferencedBounds} - */ -ol.Bounds.prototype.toUnreferencedBounds = function() { - return new ol.UnreferencedBounds( - this.getMinX(), this.getMinY(), this.getMaxX(), this.getMaxY()); -}; diff --git a/src/ol/UnreferencedBounds.js b/src/ol/UnreferencedBounds.js deleted file mode 100644 index f07a775254..0000000000 --- a/src/ol/UnreferencedBounds.js +++ /dev/null @@ -1,130 +0,0 @@ -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) { - - /** - * @protected - * @type {number} - */ - this.minX_ = minX; - - /** - * @protected - * @type {number} - */ - this.minY_ = minY; - - /** - * @protected - * @type {number} - */ - this.maxX_ = maxX; - - /** - * @protected - * @type {number} - */ - this.maxY_ = maxY; - -}; - - -/** - * @return {number} Minimun X. - */ -ol.UnreferencedBounds.prototype.getMinX = function() { - return this.minX_; -}; - -/** - * @param {number} minX Minimum X. - */ -ol.UnreferencedBounds.prototype.setMinX = function(minX) { - this.minX_ = minX; -}; - -/** - * @return {number} Minimun Y. - */ -ol.UnreferencedBounds.prototype.getMinY = function() { - return this.minY_; -}; - -/** - * @param {number} minY Minimum Y. - */ -ol.UnreferencedBounds.prototype.setMinY = function(minY) { - this.minY_ = minY; -}; - -/** - * @return {number} Maximun X. - */ -ol.UnreferencedBounds.prototype.getMaxX = function() { - return this.maxX_; -}; - -/** - * @param {number} maxX Maximum X. - */ -ol.UnreferencedBounds.prototype.setMaxX = function(maxX) { - this.maxX_ = maxX; -}; - -/** - * @return {number} Maximun Y. - */ -ol.UnreferencedBounds.prototype.getMaxY = function() { - return this.maxY_; -}; - -/** - * @param {number} maxY Maximum Y. - */ -ol.UnreferencedBounds.prototype.setMaxY = function(maxY) { - this.maxY_ = maxY; -}; - -/** - * @return {number} Bounds width. - */ -ol.UnreferencedBounds.prototype.getWidth = function() { - return this.maxX_ - this.minX_; -}; - -/** - * @return {number} Bounds height. - */ -ol.UnreferencedBounds.prototype.getHeight = function() { - return this.maxY_ - this.minY_; -}; - -/** - * Determine if this bounds intersects the target bounds (bounds that only - * touch are considered intersecting). - * - * @param {ol.UnreferencedBounds} bounds Target bounds. - * @return {boolean} The provided bounds intersects this bounds. - */ -ol.UnreferencedBounds.prototype.intersects = function(bounds) { - return !( - // this is left - (this.minX_ > bounds.getMaxX()) || - - // this is right - (this.maxX_ < bounds.getMinX()) || - - // this is above - (this.minY_ > bounds.getMaxY()) || - - // this is below - (this.maxY_ < bounds.getMinY()) - ); -}; diff --git a/src/ol/bounds.js b/src/ol/bounds.js new file mode 100644 index 0000000000..2c820ce32e --- /dev/null +++ b/src/ol/bounds.js @@ -0,0 +1,20 @@ +goog.provide('ol.Bounds'); + +goog.require('goog.math.Box'); + + + +/** + * @constructor + * @extends {goog.math.Box} + * @param {number} top Top. + * @param {number} right Right. + * @param {number} bottom Bottom. + * @param {number} left Left. + */ +ol.Bounds = function(top, right, bottom, left) { + + goog.base(this, top, right, bottom, left); + +}; +goog.inherits(ol.Bounds, goog.math.Box);