Can anyone explain me how I can include one dynamic legend within a Leaflet map for 16 individual WMS layers? Is it possible to create ONE legend with the WMS service for multiple layers?
My code to add and remove the layer is like the Leaflet.Control.Layers.Tree https://github.com/jjimenezshaw/Leaflet.Control.Layers.Tree
Now I want to show a legend on my leaflet map - depending on the visibility of the layers: If a layer is not visible (removed) the legend symbols of this layer should not bee shown.
The WMS service works fine. I tried to use the wms request
like in this plugin: https://github.com/kartoza/leaflet-wms-legend
I checked in my code if a layer is active. Then I requested the legend only for the active ones. I then displayed the legend images together on one control. But: If all 16 layers are active/visible, then this legend is very big. Now I'm looking for a solution to make the legend more user-friendly.
And it would be great if - depending on the visibility of the layers - it should also display only the necessary symbols. I mean, if a symbol is not in the current display area, then it should not be displayed.
Is that possible and if so, how would you do that?
Edit: My question in more concrete form: Is it possible to create ONE legend with the WMS service for multiple layers?