From 6198df9381f5dd7f87c99ed78c72b66a50a75446 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 21 Jun 2012 19:02:26 +0200 Subject: [PATCH] Location transform in api. --- src/api/loc.js | 17 +++++++++++++++++ src/ol/Loc.js | 24 +++--------------------- src/ol/Projection.js | 10 +++++++--- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/api/loc.js b/src/api/loc.js index 4c36d11535..69d2d87f4f 100644 --- a/src/api/loc.js +++ b/src/api/loc.js @@ -65,6 +65,23 @@ ol.loc = function(opt_arg){ }; +/** + * Transform this location to another coordinate reference system. This + * requires that this location has a projection set already (if not, an error + * will be thrown). Returns a new location object and does not modify this + * location. + * + * @export + * @param {string|ol.Projection} proj The destination projection. Can be + * supplied as a projection instance of a string identifier. + * @returns {ol.Loc} A new location. + */ +ol.Loc.prototype.transform = function(proj) { + if (goog.isString(proj)) { + proj = new ol.Projection(proj); + } + return this.doTransform(proj); +}; /** * @export diff --git a/src/ol/Loc.js b/src/ol/Loc.js index 68241c3ca6..bee33e636f 100644 --- a/src/ol/Loc.js +++ b/src/ol/Loc.js @@ -104,31 +104,13 @@ ol.Loc.prototype.setZ = function(z) { this.z_ = z; }; -/** - * Transform this location to another coordinate reference system. This - * requires that this location has a projection set already (if not, an error - * will be thrown). Returns a new location object and does not modify this - * location. - * - * @export - * @param {string|!ol.Projection} proj The destination projection. Can be - * supplied as a projection instance of a string identifier. - * @returns {!ol.Loc} A new location. - */ -ol.Loc.prototype.transform = function(proj) { - if (goog.isString(proj)) { - proj = new ol.Projection(proj); - } - return this._transform(proj); -}; - /** * Transform this location to a new location given a projection object. * - * @param {!ol.Projection} proj The destination projection. - * @returns {!ol.Loc} + * @param {ol.Projection} proj The destination projection. + * @returns {ol.Loc} */ -ol.Loc.prototype._transform = function(proj) { +ol.Loc.prototype.doTransform = function(proj) { var point = {'x': this.x_, 'y': this.y_}; var sourceProj = this.projection_; if (!goog.isDefAndNotNull(sourceProj)) { diff --git a/src/ol/Projection.js b/src/ol/Projection.js index 7d13bba417..78e38d7d09 100644 --- a/src/ol/Projection.js +++ b/src/ol/Projection.js @@ -164,12 +164,16 @@ 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 {!ol.Projection} source Source projection. - * @param {!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. */ ol.Projection.transform = function(point, source, dest) { + goog.asserts.assertObject(point); + goog.asserts.assertObject(source); + goog.asserts.assertObject(dest); if (source.proj_ && dest.proj_) { + // TODO: implement Proj4js handling // point = Proj4js.transform(source.proj_, dest.proj_, point); } else { var sourceCode = source.getCode();