From 7440556585af3046b6d164587750811566b00b3f Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 19 Dec 2007 22:04:30 +0000 Subject: [PATCH] Add reprojection support on Geometry classes. Geometries can now be transformed in place by using .transform(source, dest). r=elemoine (Closes #1037) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5515 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Geometry/Collection.js | 21 +++++++++++++++++++++ lib/OpenLayers/Geometry/LinearRing.js | 21 +++++++++++++++++++++ lib/OpenLayers/Geometry/Point.js | 19 +++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/lib/OpenLayers/Geometry/Collection.js b/lib/OpenLayers/Geometry/Collection.js index 863ff5d83d..bd05bc796f 100644 --- a/lib/OpenLayers/Geometry/Collection.js +++ b/lib/OpenLayers/Geometry/Collection.js @@ -306,6 +306,27 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { return equivalent; }, + /** + * APIMethod: transform + * Reproject the components geometry from source to dest. + * + * Parameters: + * source - {} + * dest - {} + * + * Returns: + * {} + */ + transform: function(source, dest) { + if (source && dest) { + for (var i = 0; i < this.components.length; i++) { + var component = this.components[i]; + component.transform(source, dest); + } + } + return this; + }, + /** * APIMethod: intersects * Determine if the input geometry intersects this one. diff --git a/lib/OpenLayers/Geometry/LinearRing.js b/lib/OpenLayers/Geometry/LinearRing.js index 1e65856f6c..f862277c7f 100644 --- a/lib/OpenLayers/Geometry/LinearRing.js +++ b/lib/OpenLayers/Geometry/LinearRing.js @@ -152,6 +152,27 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class( this.components[i].resize(scale, origin, ratio); } }, + + /** + * APIMethod: transform + * Reproject the components geometry from source to dest. + * + * Parameters: + * source - {} + * dest - {} + * + * Returns: + * {} + */ + transform: function(source, dest) { + if (source && dest) { + for (var i = 0; i < this.components.length - 1; i++) { + var component = this.components[i]; + component.transform(source, dest); + } + } + return this; + }, /** * APIMethod: getArea diff --git a/lib/OpenLayers/Geometry/Point.js b/lib/OpenLayers/Geometry/Point.js index 7569bd82fa..af9a8916ef 100644 --- a/lib/OpenLayers/Geometry/Point.js +++ b/lib/OpenLayers/Geometry/Point.js @@ -188,6 +188,25 @@ OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { } return intersect; }, + + /** + * APIMethod: transform + * Translate the x,y properties of the point from source to dest. + * + * Parameters: + * source - {} + * dest - {} + * + * Returns: + * {} + */ + transform: function(source, dest) { + if ((source && dest)) { + OpenLayers.Projection.transform( + this, source, dest); + } + return this; + }, CLASS_NAME: "OpenLayers.Geometry.Point" });