[GIS] WMS in leaflet R

leafletrwms

I'm am trying to add a WMS-map with leaflet, however, I can't get it to work. Is it because the WMS-service has to be tiled or is there another reason?

library(leaflet)
leaflet() %>%
  setView(lng = 12.526906, lat = 55.680339, zoom = 17) %>%
  addTiles() %>%
  addWMSTiles(
    "https://gis.frb-forsyning.dk/Varme/service.svc/get?request=GetCapabilities&service=WMS",
    layers = "Ledninger",
    options = WMSTileOptions(format = "image/png", transparent = FALSE)
  )

The WMS is unfortunately password protected, but you can find a XML-transcript of the WMS here.

Best Answer

It's hard to test your exact code, because the WMS service requires a password. I have tested it with a different WMS service and you probably have to remove the ?request=GetCapabilities&service=WMS part from the url, because you don't need the GetCapabilities request for the tiles. It needs the GetMap request, but that is added by the Leaflet Library.

library(leaflet)
leaflet() %>% setView(lng = 12.526906, lat = 55.680339, zoom = 17) %>% addTiles() %>%
addWMSTiles(
"https://gis.frb-forsyning.dk/Afloeb/service.svc/get",
layers = "Ledninger",
options = WMSTileOptions(format = "image/png", transparent = F)
)

The code I tested and that worked is:

library(leaflet)
leaflet() %>% setView(lng = 5.3, lat = 50.9, zoom = 17) %>% addTiles() %>%
addWMSTiles(
"https://geoservices.informatievlaanderen.be/raadpleegdiensten/GRB-basiskaart-grijs/wms",
layers = "GRB_BSK_GRIJS",
options = WMSTileOptions(format = "image/png", transparent = F)
)
Related Question