Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only hide base layers from the same group. #360

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paul121
Copy link

@paul121 paul121 commented Sep 12, 2020

It would be nice to make the base layer functionality (only one layer visible) apply to individual layer groups. This way only one layer from the layer group could be shown, while still showing a different base layer from a base layer group.

I believe this is functionality requested in #315

The way I have implemented this it would be "breaking" in the sense that it changes the current functionality of this library. If this is a problem, is there maybe an alternative way we could specify Layer Groups to behave in this manner? eg: Specify the Layer Group type = 'base', and then limit this behavior to "base" layer groups?

A specific use case is Drone imagery layers, where we want to display multiple raster TileLayers, but only one at a time from the "Drone Imagery" group. Example:
base_layer_groups

@paul121
Copy link
Author

paul121 commented Sep 28, 2020

After looking closer at how the fold and combine layer group settings work I decided to make this functionality a setting on the layer group, too. If a layer group has the exclusive option set to true, its base layers will be treated separately from others. I chose the "exclusive" term as that is what the leaflet-groupedlayercontrol library uses to declare a similar feature.

The last thing that is bugging me is that individual layers need to be added with type = 'base', when they aren't really base layers. Perhaps we could introduce a new `type = 'exclusive`` layer type?

I've also updated this PR on top of the most recent v3.7.0 changes. @walkermatt I'm curious what you think; I think this would be a useful feature. I'm happy to help write tests and make any other changes to get this in!

@walkermatt
Copy link
Owner

I'm in support of this. I'd be happy to move away from having to set type: 'base' on individual layers and instead simply have the group have exclusive set as you've done. Do you have an example that you could provide a link to?

@walkermatt walkermatt self-assigned this Oct 18, 2020
@paul121
Copy link
Author

paul121 commented Oct 19, 2020

I added an exclusive layer to the basic usage example included with this commit: 06750f5

I'd be happy to move away from having to set type: 'base' on individual layers and instead simply have the group have exclusive set as you've done.

The limitation with this is that you couldn't have base layers spanning multiple groups, which is the current behavior and perhaps seen as a feature (in other words, layers across multiple groups that are all mutually "exclusive"). Dropping support for type: 'base' would be a bit of a breaking change as well, but understand why you might want to.

@walkermatt
Copy link
Owner

I'm wondering about adding a property to each layer in an exclusive group equivalent to the radio button name. In this WIP branch I've used groupName but I'm not entirely happy with the name...

I think this could allow us to eventually drop type: base while still supporting having exclusive layers spanning multiple groups.

Demo with two separate exclusive groups: http://raw.githack.com/walkermatt/ol-layerswitcher/exclusive/examples/layerswitcher.html

@paul121
Copy link
Author

paul121 commented Dec 9, 2020

@walkermatt that looks great!

Maybe exclusiveGroup instead of groupName? It's tricky.. breaking this down a bit.. one level is configuring the exclusivity on the group level, another is configuring it on the layer level. Another level is a boolean exclusive config, vs a string exclusiveGroup name, where the string doesn't necessarily reference a layer group, but instead is just a unique identifier for the exclusive set.

A simplification would be to allow this configuration on just the group. So that group.exclusiveGroup = 'base`` would make all layers in that group radios. Another group could specify the same exclusiveGrouptobase`, thus creating two groups that are mutually exclusive.

By allowing an exclusiveGroup to be configured on individual layers, this allows only SOME layers within the same group to have "exclusive" behavior, while others could still be checkboxes. I guess as this is the current behavior, so that should continue to be supported. So in this case, if the exclusiveGroup option is set on a layer's group, then it should inherit that same group.

This could maybe allow type: base to be a backwards compatible/deprecated way of assigning exclusiveGroup = 'base' on individual layers. So that option would still be supported & maintain its current behavior going forward, but the type option could be dropped in a later major release?

@cmalzer
Copy link

cmalzer commented Apr 14, 2021

Hi everyone, I have the same problem (a layer group where I would like to have radio buttons, plus a group of basemaps) and just wanted to ask whether there are currently any plans for adding this feature? It would be really useful! :)

@koba-1
Copy link

koba-1 commented Nov 29, 2021

Hi everyone... I have the same need to have layers that can be viewed in an exclusive way...

@kage212
Copy link

kage212 commented Sep 14, 2022

Hello, will this issue ever be closed? I mean this issue has been opened by two years and showed a potential fix, but still is not on the master branch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants