[OpenLayers-Users] Re: removing a layer
Imran Rajjad
rajjad at gmail.com
Thu Jan 19 23:40:45 EST 2012
I think the correct function is
layer.destroyFeatures();
which will empty the vector layer. You should not remove or re-initialize
the layer. It makes sense to remove the layer from the map if you do not
need it further.
regards,
Imran
On Fri, Jan 20, 2012 at 3:19 AM, Puneet Kishor <punk.kish at gmail.com> wrote:
> I am completely at my wits end. I am trying to check if a vector layer
> exists, and if it does, I need to either completely remove it or remove all
> the features from it (whichever is more efficient from the point of speed
> and memory), and then redraw that layer. Have been trying all sorts of
> permutations and combinations, but am just not successful.
>
> My latest code attempt is below, and the original attempt is below that
> from my OP.
>
> var arr = map.getLayersByName("Vector layer");
>
> if (arr.length) {
> //map.removeLayer(arr[0]);
> layer.removeAllFeatures();
> }
> else {
> layer = new OpenLayers.Layer.Vector("Vector layer", {styleMap:
> myStyles});
> }
>
> Neither `map.removeLayer(arr[0])` nor `layer.removeAllFeatures()` works.
>
> Would appreciate suggestions.
>
> On Jan 19, 2012, at 3:00 PM, Puneet Kishor wrote:
>
> > I am trying to remove a layer with
> >
> > if (map.getLayerIndex(layer) > 0) {
> > map.removeLayer(layer);
> > }
> >
> > but no joy. How can I remove a layer?
> >
> > A bonus question: if I want to reconstruct a vector layer on map
> "zoomend", that is, redraw all the features on it so they are resized
> accordingly, should I remove the layer (hence, the question above), or
> simply remove all the features and redraw the features? If the latter, then
> how?
> >
> > Many thanks,
> >
> > --
> > Puneet Kishor
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
--
I.R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120120/99c982c5/attachment.html
More information about the Users
mailing list