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


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

  • There isn't anything linked to your code? – whyzar Feb 29 '16 at 22:10
  • Hello whyzar. Before too I apologize for the way I put the question on the platform. It was the first I used this forum. I did what you told me about the first choice,and i used the service getLegendGraphic from Geoserver. Then i put the link generated by this service, before the layer code, like this: var groupedmaps={ "Qualificação do Espaço": {"<img src='Link from Geoserver GetLegendgraphic ' height=...>Layer name":Data layer }; . Thanks – mauricio santos Mar 2 '16 at 11:08
  • If you use the layout option on the GetMap request, each tile contains a legend. Your typical map uses 12 tiles. That is a lot of legends. How do you configure geoserver to only return one legend instead returning a legend for each Tile? – Nathan Reese Apr 21 '17 at 16:27
  • That's a great question. I think it would be best if you created a new post with your exact question. Including what you have tried and what you searched and haven't been able to find an answer. – whyzar Apr 21 '17 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.