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

Remove legend from control #10

Open
joffreyj opened this issue Nov 7, 2019 · 2 comments
Open

Remove legend from control #10

joffreyj opened this issue Nov 7, 2019 · 2 comments

Comments

@joffreyj
Copy link

joffreyj commented Nov 7, 2019

I would like to be able to remove the legend from the control. My use case: I have users who will add raster images to the map from db search results. This could be a large number of images.

It would be very helpful to have an option "allowRemove" which would place an (X) on the "htmlLegend" control for the layer which would allow the user to remove the layer from the "l.control.layers" control. I know I can keep track of the ids and allow the user to remove the layer from somewhere else (like in your example) but this seems much more intuitive.

@ka7eh
Copy link
Collaborator

ka7eh commented Nov 7, 2019

You should be able to do this with removeLegend method. See this part in the example:
https://github.com/consbio/Leaflet.HtmlLegend/blob/master/index.html#L396

You need to keep track of your legend indexes and then pass the ones you'd like to remove to removeLegend.

I can look into adding a close button to the code, but it might take some time. If you'd like to implement this, feel free to submit a PR.

@ka7eh
Copy link
Collaborator

ka7eh commented Jan 12, 2020

Sorry for taking so long to get back to this. Turned out I didn't read your comment completely and missed the part that you mentioned you're already aware of the current way of removing legend.
Anyhow, I added support for allowRemove and it's in review (see #13). I'll let you know when it's updated on npm too.

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

No branches or pull requests

2 participants