Adding a removeAllFeatures method to the vector layer. This bypasses a few unnecessary steps when removing all features but retains the same behavior as the removeFeatures method otherwise. Optimizing the clear method on elements renderers a bit by avoiding length calculation of the live collection and looking up the first child once per node removal. r=ahocevar (closes #2774)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10597 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -616,10 +616,13 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
if(!features || features.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (features === this.features) {
|
||||
return this.removeAllFeatures(options);
|
||||
}
|
||||
if (!(features instanceof Array)) {
|
||||
features = [features];
|
||||
}
|
||||
if (features === this.features || features === this.selectedFeatures) {
|
||||
if (features === this.selectedFeatures) {
|
||||
features = features.slice();
|
||||
}
|
||||
|
||||
@@ -681,6 +684,49 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: removeAllFeatures
|
||||
* Remove all features from the layer.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Optional properties for changing behavior of the
|
||||
* removal.
|
||||
*
|
||||
* Valid options:
|
||||
* silent - {Boolean} Supress event triggering. Default is false.
|
||||
*/
|
||||
removeAllFeatures: function(options) {
|
||||
var notify = !options || !options.silent;
|
||||
var features = this.features;
|
||||
if (notify) {
|
||||
this.events.triggerEvent(
|
||||
"beforefeaturesremoved", {features: features}
|
||||
);
|
||||
}
|
||||
var feature;
|
||||
for (var i = features.length-1; i >= 0; i--) {
|
||||
feature = features[i];
|
||||
if (notify) {
|
||||
this.events.triggerEvent("beforefeatureremoved", {
|
||||
feature: feature
|
||||
});
|
||||
}
|
||||
feature.layer = null;
|
||||
if (notify) {
|
||||
this.events.triggerEvent("featureremoved", {
|
||||
feature: feature
|
||||
});
|
||||
}
|
||||
}
|
||||
this.renderer.clear();
|
||||
this.features = [];
|
||||
this.unrenderedFeatures = {};
|
||||
this.selectedFeatures = [];
|
||||
if (notify) {
|
||||
this.events.triggerEvent("featuresremoved", {features: features});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroyFeatures
|
||||
* Erase and destroy features on the layer.
|
||||
|
||||
@@ -442,14 +442,17 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
* Remove all the elements from the root
|
||||
*/
|
||||
clear: function() {
|
||||
if (this.vectorRoot) {
|
||||
while (this.vectorRoot.childNodes.length > 0) {
|
||||
this.vectorRoot.removeChild(this.vectorRoot.firstChild);
|
||||
var child;
|
||||
var root = this.vectorRoot;
|
||||
if (root) {
|
||||
while (child = root.firstChild) {
|
||||
root.removeChild(child);
|
||||
}
|
||||
}
|
||||
if (this.textRoot) {
|
||||
while (this.textRoot.childNodes.length > 0) {
|
||||
this.textRoot.removeChild(this.textRoot.firstChild);
|
||||
root = this.textRoot;
|
||||
if (root) {
|
||||
while (child = root.firstChild) {
|
||||
root.removeChild(child);
|
||||
}
|
||||
}
|
||||
if (this.indexer) {
|
||||
|
||||
Reference in New Issue
Block a user