Adding unreferenced bounds.

This commit is contained in:
Tim Schaub
2012-06-20 00:11:06 +02:00
parent 450f8f7b74
commit b06a52888f
5 changed files with 165 additions and 79 deletions

View File

@@ -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)) {

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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;
};

View File

@@ -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();