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
This commit is contained in:
crschmidt
2008-08-28 18:41:00 +00:00
parent 1b71180f14
commit 2d286b7ccc
6 changed files with 57 additions and 1 deletions

View File

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

View File

@@ -172,6 +172,7 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
var component = this.components[i];
component.transform(source, dest);
}
this.bounds = null;
}
return this;
},

View File

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

View File

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

View File

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

View File

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