Closed bmaparicio closed 2 months ago
Hi, Is it possible to only show a WMS legend when the WMS layer is displaying? This is usually done by using setting a group in the legend, but group is not an argument of addWMSLegend.
Here is a reproducible example:
leaflet::leaflet()%>% leaflet::addTiles() %>% setView(73.917, 15.500 , zoom = 7)%>% leaflet::addWMSTiles("https://bhuvan-vec2.nrsc.gov.in/bhuvan/wms",layers = "GA_LULC50K_0506", options = leaflet::WMSTileOptions(format = "image/png", transparent = TRUE), group = "Exposure", attribution = "")%>% leaflet.extras::addWMSLegend(uri="https://bhuvan-vec2.nrsc.gov.in:443/bhuvan/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=lulc%3AGA_LULC50K_0506", layerId="Exposure")%>% leaflet::addLayersControl(overlayGroups = all_groups) %>% leaflet::hideGroup(all_groups)
Just add layerId = "Exposure" to your addWMSTiles.
layerId = "Exposure"
addWMSTiles
The WMS-Tiles and the Legends are linked through their layerId
layerId
Hi, Is it possible to only show a WMS legend when the WMS layer is displaying? This is usually done by using setting a group in the legend, but group is not an argument of addWMSLegend.
Here is a reproducible example: