On 26/09/2011 05:31, Puneet Kishor wrote:
The following code does what I want --
var lyr_list = map.getLayersByName("a_layer");
if (typeOf(lyr_list) === "array") {
for (var i in lyr_list) {
lyr_list[i].removeAllFeatures();
removeLayer(lyr_list[i]);
}
}
> Surely, the above couldn't be the most optimum way, could it?
it will not change anything for your particular case, but I usually
reference layers via their ID. This requires to add the ID after creation.
something like
var myLayer = new OpenLayers.Layer...;
myLayer.addOptions({id:'theLayerId'});
then you can always access the layer later on like
var mapLayer = map.getLayer('theLayerId');
For completely deleting a layer it might be necessary to also run the
.destroy() method on the layer, but I'm not sure when this is required
and when not.
Regards
Armin
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users