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

Legend is empty but visible when no linked layers are visible #946

Closed
jmgomezpoveda opened this issue May 24, 2023 · 5 comments
Closed

Legend is empty but visible when no linked layers are visible #946

jmgomezpoveda opened this issue May 24, 2023 · 5 comments

Comments

@jmgomezpoveda
Copy link

Legends can be associated to layers, as we can see in the corresponding sample: https://viglino.github.io/ol-ext/examples/legend/map.control.legend.layer.html

If none of the layers are visible, the legend balloon and the close icon are still visible. In the above example, just unselect both layers, and the balloon stays with just "Legend" and the close icon.

Ideally, I would expect that the whole legend would be invisible if none of the associated layers are visible (and maybe the contracted legend button could be grayed out).

Viglino added a commit that referenced this issue May 25, 2023
@Viglino
Copy link
Owner

Viglino commented May 25, 2023

I've added the feature to hide the legend when empty : see https://viglino.github.io/ol-ext/examples/legend/map.control.legend.layer.html

@jmgomezpoveda
Copy link
Author

That looks beautiful!

@jmgomezpoveda
Copy link
Author

I have just tried the 4.0.9 version and it is not hiding the label for me.

Now, the way I am adding or removing layers is by enabling/disabling them:

myLayer.setVisible(false);

Should this be triggering the new mechanism to detect empty legends? Or would I need to remove the layer from the map?

@Viglino
Copy link
Owner

Viglino commented Jun 27, 2023

The map legend collapse when there is no item in it.
Hidding the layers remove the layer legend from the map legend.
You should not have to do something else.
Do you have an example to see what's up?

@jmgomezpoveda
Copy link
Author

You are right. Just doing setVisible disables the legend: https://jsfiddle.net/t95u7bcp/

Let me review my code. For some reason the ol-empty class is not being added to the legend's button's parent. Maybe I did something wrong in the upgrade steps.

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

No branches or pull requests

2 participants