Learn R Programming

leaflet.extras (version 2.0.1)

addWMSLegend: Add WMS Legend

Description

Add a WMS Legend

Usage

addWMSLegend(
  map,
  uri,
  position = "topright",
  layerId = NULL,
  group = NULL,
  title = "",
  titleClass = "wms-legend-title",
  titleStyle = ""
)

Arguments

map

a map widget object created from leaflet()

uri

The legend URI

position

the position of the legend

layerId

When the layerId of the WMS layer is properly set, the legend will appear or disappear accordingly based on whether the layer is visible or not. If no layerId is given, it will try to get the layer name from the `uri`, otherwise a random ID will be assigned.

group

The group argument is not used. Please set the `layerId` correctly.

title

A title that is prepended before the image.

titleClass

CSS-class for the title div

titleStyle

Style the title with CSS

Examples

Run this code
leaflet() %>%
  addTiles() %>%
  setView(11, 51, 6) %>%
  addWMSTiles(
    baseUrl = "https://www.wms.nrw.de/wms/unfallatlas?request=GetMap",
    layers = c("Unfallorte", "Personenschaden_5000", "Personenschaden_250"),
    options = WMSTileOptions(format = "image/png", transparent = TRUE)
  ) %>%
  addWMSLegend(
    title = "Personenschaden_5000", titleStyle = "font-size:1em; font-weight:800",
    uri = paste0(
      "https://www.wms.nrw.de/wms/unfallatlas?request=",
      "GetLegendGraphic&version=1.3.0&",
      "format=image/png&layer=Personenschaden_5000"
    )
  )

Run the code above in your browser using DataLab