0

How can I toggle the visibility of a feature in OpenLayers?

There are similar posts, which answers suggests to change the feature style. However, I have a scenario where the style is unknown, so I can't assign it back when I want to show the feature again. Similar posts:

Here is a JSFiddle to make demonstration easier: https://jsfiddle.net/aejko5n6/

It would be great if something like this was possible:

function toggleVisiblity() {
  console.log('button click!');
  
  if(lineFeature.get('hidden')) {
    lineFeature.unset('hidden');
  } else {
    lineFeature.set('hidden', true);
  }
  
  vector.changed();
}
geocodezip
  • 158,664
  • 13
  • 220
  • 245
robtot
  • 863
  • 1
  • 9
  • 31

0 Answers0