Add getDataExtent to Vector Layer. Patch from rupert, tests by me, r=me
(Closes #1369) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6947 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -534,5 +534,24 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
preFeatureInsert: function(feature) {
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getDataExtent
|
||||
* Calculates the max extent which includes all of the features.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Bounds>}
|
||||
*/
|
||||
getDataExtent: function () {
|
||||
var maxExtent = null;
|
||||
if( this.features && (this.features.length > 0)){
|
||||
var maxExtent = this.features[0].geometry.getBounds();
|
||||
for(var i=0; i < this.features.length; i++){
|
||||
maxExtent.extend(this.features[i].geometry.getBounds());
|
||||
}
|
||||
}
|
||||
|
||||
return maxExtent;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Layer.Vector"
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
}
|
||||
|
||||
function test_Layer_Vector_addFeatures(t) {
|
||||
t.plan(4);
|
||||
t.plan(5);
|
||||
|
||||
var layer = new OpenLayers.Layer.Vector(name);
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
}
|
||||
|
||||
layer.addFeatures([pointFeature], {silent: true});
|
||||
|
||||
var extent = layer.getDataExtent();
|
||||
t.eq(extent.toBBOX(), "-111.04,45.68,-111.04,45.68", "extent from getDataExtent is correct");
|
||||
}
|
||||
|
||||
function test_Layer_Vector_removeFeatures(t) {
|
||||
|
||||
Reference in New Issue
Block a user