[OpenLayers-Commits] r10953 - in trunk/openlayers:
lib/OpenLayers/Geometry tests/Geometry
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Dec 7 18:37:56 EST 2010
Author: tschaub
Date: 2010-12-07 15:37:56 -0800 (Tue, 07 Dec 2010)
New Revision: 10953
Modified:
trunk/openlayers/lib/OpenLayers/Geometry/Collection.js
trunk/openlayers/tests/Geometry/Collection.html
Log:
Avoiding infinite recursion when getting bounds of geometry collections. r=ahocevar (closes #2967)
Modified: trunk/openlayers/lib/OpenLayers/Geometry/Collection.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Geometry/Collection.js 2010-12-07 16:56:49 UTC (rev 10952)
+++ trunk/openlayers/lib/OpenLayers/Geometry/Collection.js 2010-12-07 23:37:56 UTC (rev 10953)
@@ -108,12 +108,19 @@
*/
calculateBounds: function() {
this.bounds = null;
- if ( this.components && this.components.length > 0) {
- this.setBounds(this.components[0].getBounds());
- for (var i=1, len=this.components.length; i<len; i++) {
- this.extendBounds(this.components[i].getBounds());
+ var bounds = new OpenLayers.Bounds();
+ var components = this.components;
+ if (components) {
+ for (var i=0, len=components.length; i<len; i++) {
+ bounds.extend(components[i].getBounds());
}
}
+ // to preserve old behavior, we only set bounds if non-null
+ // in the future, we could add bounds.isEmpty()
+ if (bounds.left != null && bounds.bottom != null &&
+ bounds.right != null && bounds.top != null) {
+ this.setBounds(bounds);
+ }
},
/**
Modified: trunk/openlayers/tests/Geometry/Collection.html
===================================================================
--- trunk/openlayers/tests/Geometry/Collection.html 2010-12-07 16:56:49 UTC (rev 10952)
+++ trunk/openlayers/tests/Geometry/Collection.html 2010-12-07 23:37:56 UTC (rev 10953)
@@ -392,6 +392,23 @@
coll.destroy();
}
+ function test_avoid_infinite_recursion(t) {
+ t.plan(1);
+
+ var g = new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing(),
+ new OpenLayers.Geometry.LinearRing()
+ ]);
+ var bounds;
+ try {
+ bounds = g.getBounds();
+ t.eq(bounds, null, "Polygon with empty linear ring has null bounds");
+ } catch (err) {
+ t.fail("Failed to get bounds of polygon with empty linear ring: " + err.message);
+ }
+
+ }
+
function test_Collection_destroy(t) {
t.plan( 3 );
More information about the Commits
mailing list