[GIS] How to show vector features in OpenLayers after hiding it

filteropenlayers-2stylevector

I did change some vector features style (through check-boxes) using style property :

var features = layer.features;

for( var i = 0; i < features.length; i++ ) {
  //features[i].style = { visibility: 'hidden' };
    features[i].style = 'none'; 
}

layer.redraw();

But now if I check the box again, it supposed to display again but nothing happens! I tried:

     features[i].style = 'block'; 
OR
     features[i].style = 'delete'; 

then redraw the layer.. but this doesn't work

Any Idea ?

Best Answer

It's my understanding that you need to change the display property of style:

features[i].style.display = 'none'; // hide

or

features[i].style.display = ''; // show. Set to anything but 'none'

Then you need to do a redraw on the layer after changing the vectors in it:

affectedlayer.redraw();

Of course.. I'm having trouble with this now too ( which is how I found this question). If I change it manually in the debugger it seems to work ( zooming in to cause a redraw) but in code it's not working for me at the moment.

Update: Too funny... I went back and looked with new eyes.. was missing the .style bit in some copy-paste edits! Glad I found your question ;)