[OpenLayers-Users] check if a layer exists and remove it
sunny74
sb.ray at hotmail.com
Mon Sep 7 01:11:35 EDT 2009
Hi,
I am declaring a layer at PageLoad in the following way:
choice_features = new OpenLayers.Layer.Vector("choice_features", { style:
v_style });
Then I am adding the layer in a different function as below:
map.addLayer(new OpenLayers.Layer.GML("choice_features",
"XML1/FeatureGML.xml"));
But I want to check if this layer exists and remove it before adding it to
the map using the addLayer function. This will ensure that the layer is
created afresh with every fresh request.
For this I have done the following but it doesn't work:
if (map.getLayersByName("choice_features") != null) {
map.layers["choice_features"].removeFeatures(map.layers["choice_features"].features);
//alert("layer removed");
}
But I get error in the getLayersByName() function.It says object doesn't
support this property.
Can u suggest an alternative method.
Thanks.
--
View this message in context: http://n2.nabble.com/check-if-a-layer-exists-and-remove-it-tp3595535p3595535.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090907/91012a73/attachment.html
More information about the Users
mailing list