Hi,
I'm using OpenLayers 2.9.1 and I found that if I have a SelectFeature control
configured for multiple layers, and that the control is active when I delete
one of the layers the control is configured for, that the deleted layer's
features are not removed from the map.
Through modifying the control's RootContainer to listen for map 'removelayer'
events, and in the event handler removing its copy of the layer data, I am able
to completely remove the layer when the control is active. Below is my patch
to OpenLayers.Layer.Vector.RootContainer.
I'm not sure if the call: this.renderer.eraseFeatures(layer.features); is the
right way to go about removing the rendered features for the deleted layer but
it seems to work in practice.
Cheers
Adam
OpenLayers.Layer.Vector.RootContainer.prototype.setMap = function(map) {
OpenLayers.Layer.Vector.prototype.setMap.apply(this, arguments);
this.collectRoots();
map.events.on({
'changelayer': this.handleChangeLayer,
'removelayer': this.handleRemoveLayer,
scope: this
});
};
OpenLayers.Layer.Vector.RootContainer.prototype.handleRemoveLayer =
function(evt) {
var layer = evt.layer;
for(var i = 0; i < this.layers.length; i++) {
if(layer == this.layers[i]) {
this.layers.splice(i, 1);
this.renderer.eraseFeatures(layer.features);
return;
}
}
};
_______________________________________________
Dev mailing list
[email protected]
http://openlayers.org/mailman/listinfo/dev