[GIS] How to add WMS legend in leaflet from Geoserver

geoserverleafletlegendsymbologywms

Can anyone explain me how I can include a legend within the layer control for any individual WMS layers in leaflet?


The wms service works fine. I just want assign the symbol label to each layer of the group.

This is an example of my app:

enter image description here

My code is similar to the leaflet groupedlayercontrol plugin: https://github.com/ismyrnow/Leaflet.groupedlayercontrol

Best Answer

There may be other options at your disposal, however I will mention two options that you can explore to add a legend to your WMS on Geoserver.

You could always utilize the request GetMap which will allow you to make modification/changes to your layout properties. You can read more on the Geoserver webapage here

Another option I came across is github user: kartoza webpage were he provides a simple WMS legend plugin to use.

This is a simple plugin for leaflet that will display a WMS GetLegendGraphic request result in a legend. At the moment the plugin is really, really simple in that is actually will display any image URI you pass it on initialisation. However that is enough to create a nice looking legend on your map like this:

enter image description here

Related Question