[OpenLayers-Commits] r12187 - in trunk/openlayers:
lib/OpenLayers/Layer tests/Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Jul 25 09:13:48 EDT 2011
Author: bartvde
Date: 2011-07-25 06:13:46 -0700 (Mon, 25 Jul 2011)
New Revision: 12187
Modified:
trunk/openlayers/lib/OpenLayers/Layer/Vector.js
trunk/openlayers/tests/Layer/Vector.html
Log:
getDataExtent should return null when there are no features with a geometry, r=ahocevar (closes #3435)
Modified: trunk/openlayers/lib/OpenLayers/Layer/Vector.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Vector.js 2011-07-25 12:22:54 UTC (rev 12186)
+++ trunk/openlayers/lib/OpenLayers/Layer/Vector.js 2011-07-25 13:13:46 UTC (rev 12187)
@@ -597,7 +597,7 @@
if(this.events.triggerEvent("beforefeatureadded",
{feature: feature}) === false) {
continue;
- };
+ }
this.preFeatureInsert(feature);
}
@@ -816,7 +816,7 @@
this.unrenderedFeatures[feature.id] = feature;
} else {
delete this.unrenderedFeatures[feature.id];
- };
+ }
},
/**
@@ -988,17 +988,20 @@
* Calculates the max extent which includes all of the features.
*
* Returns:
- * {<OpenLayers.Bounds>}
+ * {<OpenLayers.Bounds>} or null if the layer has no features with
+ * geometries.
*/
getDataExtent: function () {
var maxExtent = null;
var features = this.features;
if(features && (features.length > 0)) {
- maxExtent = new OpenLayers.Bounds();
var geometry = null;
for(var i=0, len=features.length; i<len; i++) {
geometry = features[i].geometry;
if (geometry) {
+ if (maxExtent === null) {
+ maxExtent = new OpenLayers.Bounds();
+ }
maxExtent.extend(geometry.getBounds());
}
}
Modified: trunk/openlayers/tests/Layer/Vector.html
===================================================================
--- trunk/openlayers/tests/Layer/Vector.html 2011-07-25 12:22:54 UTC (rev 12186)
+++ trunk/openlayers/tests/Layer/Vector.html 2011-07-25 13:13:46 UTC (rev 12187)
@@ -286,6 +286,14 @@
t.ok(extent.toBBOX() != layer.features[0].geometry.getBounds().toBBOX(), "extent from getDataExtent doesn't clobber first feature");
}
+ function test_Layer_Vector_getDataExtentEmpty(t) {
+ t.plan(1);
+ var layer = new OpenLayers.Layer.Vector(name);
+ layer.addFeatures([new OpenLayers.Feature.Vector(null), new OpenLayers.Feature.Vector(null)]);
+ var extent = layer.getDataExtent();
+ t.eq(extent, null, "We expect null to be returned if there are no features with a geometry");
+ }
+
function test_Layer_Vector_removeFeatures(t) {
t.plan(17);
More information about the Commits
mailing list