From 2d286b7cccf2fa823079953f48f899e465174e29 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Thu, 28 Aug 2008 18:41:00 +0000 Subject: [PATCH] Clear bounds of geometries when reprojecting. Patch wwork by myself, tschaub, ahocevar. r=ahocevar. (Closes #1658) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7885 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Geometry/Collection.js | 3 ++- lib/OpenLayers/Geometry/LinearRing.js | 1 + lib/OpenLayers/Geometry/Point.js | 1 + tests/Geometry/Collection.html | 25 +++++++++++++++++++++++++ tests/Geometry/Point.html | 14 ++++++++++++++ tests/Geometry/Polygon.html | 14 ++++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Geometry/Collection.js b/lib/OpenLayers/Geometry/Collection.js index 7af305edc1..7b98240885 100644 --- a/lib/OpenLayers/Geometry/Collection.js +++ b/lib/OpenLayers/Geometry/Collection.js @@ -325,7 +325,8 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { var component = this.components[i]; component.transform(source, dest); } - } + this.bounds = null; + } return this; }, diff --git a/lib/OpenLayers/Geometry/LinearRing.js b/lib/OpenLayers/Geometry/LinearRing.js index 844f40656b..f82a27faaf 100644 --- a/lib/OpenLayers/Geometry/LinearRing.js +++ b/lib/OpenLayers/Geometry/LinearRing.js @@ -172,6 +172,7 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class( var component = this.components[i]; component.transform(source, dest); } + this.bounds = null; } return this; }, diff --git a/lib/OpenLayers/Geometry/Point.js b/lib/OpenLayers/Geometry/Point.js index ad181c4d86..5039b66cf9 100644 --- a/lib/OpenLayers/Geometry/Point.js +++ b/lib/OpenLayers/Geometry/Point.js @@ -206,6 +206,7 @@ OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { if ((source && dest)) { OpenLayers.Projection.transform( this, source, dest); + this.bounds = null; } return this; }, diff --git a/tests/Geometry/Collection.html b/tests/Geometry/Collection.html index 8499e71259..4518295fa0 100644 --- a/tests/Geometry/Collection.html +++ b/tests/Geometry/Collection.html @@ -226,6 +226,31 @@ t.eq( coll.getArea(), 65, "coll with valid components correctly sums getArea"); } + function test_transform(t) { + t.plan(5); + var p1 = new OpenLayers.Geometry.Point(0,0); + p1.bounds = "foo"; + var p2 = new OpenLayers.Geometry.Point(1,1); + p2.bounds = "foo"; + var line = new OpenLayers.Geometry.LineString([p1, p2]); + var multipoint = new OpenLayers.Geometry.MultiPoint([p1, p2]); + var coll = new OpenLayers.Geometry.Collection([ + p1, p2, line, multipoint + ]); + coll.bounds = "foo"; + + var wgs84 = new OpenLayers.Projection("EPSG:4326"); + var sm = new OpenLayers.Projection("EPSG:900913"); + coll.transform(wgs84, sm); + + t.eq(coll.bounds, null, "coll bounds cleared"); + t.eq(p1.bounds, null, "p1 component bounds cleared"); + t.eq(p2.bounds, null, "p2 component bounds cleared"); + t.eq(line.bounds, null, "line component bounds cleared"); + t.eq(multipoint.bounds, null, "multipoint component bounds cleared"); + + } + function test_Collection_destroy(t) { t.plan( 1 ); coll = new OpenLayers.Geometry.Collection(); diff --git a/tests/Geometry/Point.html b/tests/Geometry/Point.html index 7f122e48e4..2630b9f342 100644 --- a/tests/Geometry/Point.html +++ b/tests/Geometry/Point.html @@ -37,6 +37,20 @@ t.eq( point.bounds.bottom, y, "bounds.bottom is 20" ); } + + function test_Point_transform_getBounds (t) { + t.plan(2); + + var x = 10; + var y = 20; + point = new OpenLayers.Geometry.Point(x, y); + point.calculateBounds(); + t.ok( point.bounds != null, "bounds calculated by calcBounds" ); + point.transform(new OpenLayers.Projection("EPSG:4326"), + new OpenLayers.Projection("EPSG:900913")); + t.eq(point.bounds, null, "Point bounds cleared after transform"); + } + function test_Point_distanceTo(t) { t.plan(2); diff --git a/tests/Geometry/Polygon.html b/tests/Geometry/Polygon.html index 379a88cace..50d19b3660 100644 --- a/tests/Geometry/Polygon.html +++ b/tests/Geometry/Polygon.html @@ -32,6 +32,20 @@ t.eq( polygon.components.length, 2, "polygon.components.length is set correctly"); } + function test_Polygon_transform_getBounds (t) { + t.plan(3); + + var components = [new OpenLayers.Geometry.Point(10,14), new OpenLayers.Geometry.Point(5,3)]; + var linearRing = new OpenLayers.Geometry.LinearRing(components); + polygon = new OpenLayers.Geometry.Polygon([linearRing.clone()]); + polygon.calculateBounds(); + t.ok( polygon.bounds != null, "bounds calculated by calcBounds" ); + polygon.transform(new OpenLayers.Projection("EPSG:4326"), + new OpenLayers.Projection("EPSG:900913")); + t.eq(polygon.bounds, null, "Point bounds cleared after transform"); + t.eq(polygon.getBounds().toBBOX(), "556597.453889,334111.171355,1113194.907778,1574216.547942", "Bounds are correct") + } + function test_Polygon_getArea(t) { t.plan( 5 );