Display legend from WMS GetLegendGraphic request #1092
-
|
The leafmap Map.add_legend method accepts either predefined legends or a dictionary of legend entry keys and color values. WMS map services can include a pre-rendered legend (per layer) that you can retrieve via GetLegendGraphic request, for instance: Currently, I can add this only as an image_overlay which is a bit clunky, because it requires fixed geographic bounds to add it to the map display. Would it be possible to add it in fixed map view coordinates (e.g. viewbounds = ((0.8, 0.7), (0.95, 0.95)) or simple layout references like, bottom right, top left, etc. It would stay fixed in that place independent from map zoom and pan actions. Not urgent, but nice to have. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can use the import leafmap
m = leafmap.Map()
hrvlcc_url = "https://geoserver.vlcc.geoville.com/geoserver/ows?"
m.add_wms_layer(
url=hrvlcc_url, layers="HRL_CPL:CTY_S2017", name="CTY 2017", format="image/png", shown=True
)
legend_url = 'https://geoserver.vlcc.geoville.com/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image/png&width=20&height=20&layer=HRL_CPL:CTY_S2017'
m.add_image(legend_url)
m |
Beta Was this translation helpful? Give feedback.

You can use the
Map.add_image()function to add the legend.