From 408413ec924bcbc1570c157d1023e66f13fe5ac2 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 19 Jun 2012 17:41:17 +0200 Subject: [PATCH] Projection cannot be null. --- src/ol/Map.js | 4 +-- src/ol/Projection.js | 46 ++++++++++++++++----------------- test/spec/ol/Projection.test.js | 12 ++++----- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/ol/Map.js b/src/ol/Map.js index fe1114f71e..a321b00302 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -75,7 +75,7 @@ ol.Map.prototype.getCenter = function() { /** - * @return {ol.Projection} Projection. + * @return {!ol.Projection} Projection. */ ol.Map.prototype.getProjection = function() { if (goog.isNull(this.projection_)) { @@ -86,7 +86,7 @@ ol.Map.prototype.getProjection = function() { /** - * @return {ol.Projection} User projection. + * @return {!ol.Projection} User projection. */ ol.Map.prototype.getUserProjection = function() { if (goog.isNull(this.userProjection_)) { diff --git a/src/ol/Projection.js b/src/ol/Projection.js index 2490e49a7b..b40619ba54 100644 --- a/src/ol/Projection.js +++ b/src/ol/Projection.js @@ -65,7 +65,7 @@ ol.Projection.prototype.getUnits = function() { }; /** - * @param {string|undefined} units Units abbreviation. + * @param {string} units Units abbreviation. * @return {ol.Projection} This. */ ol.Projection.prototype.setUnits = function(units) { @@ -111,12 +111,13 @@ ol.Projection.prototype.units = function(opt_units){ ol.Projection.transforms = {}; /** - * APIProperty: defaults - * {Object} Defaults for the SRS codes known to OpenLayers (currently - * EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, - * EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units, - * maxExtent (the validity extent for the SRS) and yx (true if this SRS is - * known to have a reverse axis order). + * Defaults for the SRS codes known to OpenLayers (currently EPSG:4326, CRS:84, + * urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, EPSG:102113 and + * EPSG:102100). Keys are the SRS code, values are units, maxExtent (the + * validity extent for the SRS) and yx (true if this SRS is known to have a + * reverse axis order). + * + * @type {Object} */ ol.Projection.defaults = { "EPSG:4326": { @@ -135,17 +136,16 @@ ol.Projection.defaults = { }; /** - * APIMethod: addTransform * Set a custom transform method between two projections. Use this method in * cases where the proj4js lib is not available or where custom projections * need to be handled. * - * Parameters: - * from - {String} The code for the source projection - * to - {String} the code for the destination projection - * method - {Function} A function that takes a point as an argument and - * transforms that point from the source to the destination projection - * in place. The original point should be modified. + * @param {string} from The code for the source projection. + * @param {string} to The code for the destination projection. + * @param {function(Object)} method A function that takes an object with x and + * y properties as an argument and transforms that point from the source to + * the destination projection in place. The original point should be + * modified. */ ol.Projection.addTransform = function(from, to, method) { if (method === ol.Projection.nullTransform) { @@ -166,7 +166,7 @@ ol.Projection.addTransform = function(from, to, method) { * @param {Object} point Object with x and y properties. * @param {!string|!ol.Projection} source Source projection. * @param {!string|!ol.Projection} dest Destination projection. - * @returns {Object} Object with x and y properties. + * @private */ ol.Projection.transform = function(point, source, dest) { if (!(source instanceof ol.Projection)) { @@ -176,7 +176,7 @@ ol.Projection.transform = function(point, source, dest) { dest = new ol.Projection(dest); } if (source.proj_ && dest.proj_) { - // point = Proj4js.transform(source.proj, dest.proj, point); + // point = Proj4js.transform(source.proj_, dest.proj_, point); } else { var sourceCode = source.getCode(); var destCode = dest.getCode(); @@ -185,20 +185,18 @@ ol.Projection.transform = function(point, source, dest) { transforms[sourceCode][destCode](point); } } - return point; }; /** - * APIFunction: nullTransform * A null transformation - useful for defining projection aliases when * proj4js is not available: * - * (code) - * ol.Projection.addTransform("EPSG:3857", "EPSG:900913", - * ol.Projection.nullTransform); - * ol.Projection.addTransform("EPSG:900913", "EPSG:3857", - * ol.Projection.nullTransform); - * (end) + * ol.Projection.addTransform("EPSG:3857", "EPSG:900913", + * ol.Projection.nullTransform); + * ol.Projection.addTransform("EPSG:900913", "EPSG:3857", + * ol.Projection.nullTransform); + * + * @type {function(Object)} */ ol.Projection.nullTransform = function(point) { return point; diff --git a/test/spec/ol/Projection.test.js b/test/spec/ol/Projection.test.js index fa51cebaa9..950b90fe7b 100644 --- a/test/spec/ol/Projection.test.js +++ b/test/spec/ol/Projection.test.js @@ -27,19 +27,17 @@ describe("ol.Projection", function() { it("handles transforms", function() { - var orig = {x: 10, y: 20, z: 30}; + var point = {x: 10, y: 20, z: 30}; - var point = ol.Projection.transform(orig, "EPSG:4326", "EPSG:900913"); + var ret = ol.Projection.transform(point, "EPSG:4326", "EPSG:900913"); + expect(ret).toBeUndefined(); + + // original is modified expect(point.x.toFixed(3)).toBe("1113194.908"); expect(point.y.toFixed(3)).toBe("2273030.927"); expect(point.z).toBe(30); - // original remains unchanged - expect(orig.x).toBe(10); - expect(orig.y).toBe(20); - expect(orig.z).toBe(30); - }); });