walkermatt / ol-layerswitcher

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

Selection of layers that depend on other layers #482

Closed alexgao1 closed 2 years ago

alexgao1 commented 2 years ago

Using https://raw.githack.com/walkermatt/ol-layerswitcher/master/examples/select-groups.html as example, given the structure of:

Census

  • Wards
  • Districts

Could it be possible to make it such that it becomes something like:

Wards

  • Districts

so that checking off wards will show wards, and that districts can be toggled on or off regardless of wards, but toggling wards off will also disable districts?

If that isn't possible, then can there be an option to hide just one layer such that a similar effect can be recreated:

Wards

  • Wards (but hidden from the panel)
  • Districts
alexgao1 commented 2 years ago

Would it also be possible to set whether or not layers are checked off or not upon creation of the layer switcher? (Not wanting all layers on by default)

walkermatt commented 2 years ago

Hi,

The initial visible state of the layers can be set for individual layers either by specifying a visible option or by calling setVisible on a layer instance.

alexgao1 commented 2 years ago

Okay, that works for initially setting a layer to be not visible.

Is there a solution for the first issue that I described about a layer's visibility being dependent on another layer?

walkermatt commented 2 years ago

I don't think you need anything LayerSwitcher specific to solve your first requirement. You can hide the dependent layer from the LayerSwitcher by not giving it a title property and toggle it's visibility within a change:visible listener on the other layer.

alexgao1 commented 2 years ago

That worked out, makes sense.

Thank you.