consbio / Leaflet.HtmlLegend

A simple Leaflet plugin for creating legends with HTML elements
ISC License
56 stars 59 forks source link

allow disableVisibilityControls key for each legend entry #12

Open brentfraser opened 4 years ago

ka7eh commented 4 years ago

Can you elaborate more on this? Do you mean you'd like to be able to change the transparency of all the layers within a layer that is attached to a legend control? I'm afraid such a thing is beyond the scope of this plugin. Items in legend elements have no concept of which sub-layer they are representing.

brentfraser commented 4 years ago

No. For some entries, I just use the control to show colors with description (see Layer 1 in your example site), but I don't want to have the show/hide symbol or the transparency control. I DO want the controls for the second layer (Layer 2 in your example).

Currently the disableVisibilityControls applies to all the entries in the legend. I would like to set it per entry.

One work-around would be to have separate legends, but that would clutter the map.

ka7eh commented 4 years ago

I see what you mean. I updated the code and moved disableVisibilityControls to legend options. Now you can set that option to true for each legend that you don't want to have a visibility slider.

The new changes are in https://github.com/consbio/Leaflet.HtmlLegend/pull/13 and waiting for review. You can see its usage in layer 4 in the updated example.