Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

3 Answers

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 ;)

share|improve this answer
    
in my experience this approach could fail in some cases when style is null. Similar solution provided by Rayiez works fine in such situations. –  Andrew Nov 30 '13 at 20:30
add comment

Let me put it another way:

to hide:

vectorLayer.features[0].style.fillOpacity = 0;
vectorLayer.redraw();

to show:

vectorLayer.features[0].style.fillOpacity = 1;
vectorLayer.redraw();

i hope it helps you...

share|improve this answer
    
could fail if style is null... –  Andrew Nov 30 '13 at 20:31
add comment

To hide features

    for( var i = 0; i < features.length; i++ ) {
      features[i].style = { display: 'none' };
    }
    layer.redraw();

To display back the hidden features

    for( var i = 0; i < features.length; i++ ) {
      features[i].style = null;
    }
    layer.redraw();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.