walkermatt / ol-layerswitcher

Layer control for OpenLayers
MIT License
387 stars 176 forks source link

Getting layer selection events #411

Closed minorsecond closed 3 years ago

minorsecond commented 3 years ago

I'm trying to have a legend which changes depending on the current layer visible, but can't figure out how to get layer selection events so that I can then check which layer is selected in order to change the legend.

Is there any way to do this? I've tried adding an EventListener, but can't get that to work. I'm wondering if there are any built-in ways to do what I'm trying to do.

walkermatt commented 3 years ago

Hi, you can probably achieve what you are after by listening to visibility events on the layers themselves. See https://github.com/walkermatt/ol-layerswitcher/issues/30#issuecomment-190136675