addWMS: Add Queryable WMS Layer

View source: R/wms.R

addWMSR Documentation

Add Queryable WMS Layer

Description

A Leaflet plugin for working with Web Map services, providing: single-tile/untiled/nontiled layers, shared WMS sources, and GetFeatureInfo-powered identify.

You can also use CQL-Filters by appending a string to the 'baseUrl'.

Something like 'http://server/wms?cql_filter=attribute=value'

Usage

addWMS(
  map,
  baseUrl,
  layerId = NULL,
  group = NULL,
  options = WMSTileOptions(),
  attribution = NULL,
  layers = NULL,
  popupOptions = NULL,
  checkempty = FALSE,
  headers = NULL,
  data = getMapData(map)
)

Arguments

map

a map widget object created from leaflet()

baseUrl

a base URL of the WMS service

layerId

the layer id

group

the name of the group the newly created layers should belong to (for clearGroup() and addLayersControl() purposes). Human-friendly group names are permitted–they need not be short, identifier-style names. Any number of layers and even different types of layers (e.g., markers and polygons) can share the same group name.

options

a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements

attribution

the attribution text of the tile layer (HTML)

layers

comma-separated list of WMS layers to show

popupOptions

List of popup options. See popupOptions. Default is NULL.

checkempty

Should the returned HTML-content be checked for emptiness? If the HTML-body is empty no popup is opened. Default is FALSE

headers

Optional HTTP headers for authenticated WMS requests, as a named character vector (c(Authorization = "Bearer <token>")) or a list of list(header = "Authorization", value = "Bearer <token>").

data

the data object from which the argument values are derived; by default, it is the data object provided to leaflet() initially, but can be overridden

Value

the new map object

Note

The WMS attribution is shown only while the layer (or its group) is visible, matching addWMSTiles. GetFeatureInfo requests accept HTTP redirects (e.g. 301) and upgrade http:// WMS URLs to https:// on HTTPS pages so popups still work behind a reverse proxy. To change WMS request parameters such as time in Shiny, keep the map in renderLeaflet() and call setWMSParams on a leafletProxy instead of recreating the whole map. Custom headers (Basic/Bearer) are sent for tiles, the single-image overlay and GetFeatureInfo. The WMS server must allow CORS for those header names. Tokens travel in the browser; do not use them for secrets that must stay on the server.

References

https://github.com/heigeo/leaflet.wms

See Also

Other WMS Functions: setWMSParams()

Examples

library(leaflet)
library(leaflet.extras2)

leaflet() %>%
  addTiles(group = "base") %>%
  setView(9, 50, 5) %>%
  addWMS(
    baseUrl = "https://maps.dwd.de/geoserver/dwd/wms",
    layers = "dwd:BRD_1km_winddaten_10m",
    popupOptions = popupOptions(maxWidth = 600),
    checkempty = TRUE,
    options = WMSTileOptions(
      transparent = TRUE,
      format = "image/png",
      info_format = "text/html"
    )
  )

leaflet.extras2 documentation built on Sept. 10, 2026, 1:11 a.m.