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:
- OpenLayers toggle feature visibility (Show/hide)
- https://gis.stackexchange.com/questions/270387/show-hide-features-on-layer-in-openlayers
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();
}