WMS from password protected portal not loading in Leaflet on R - works fine in QGIS

75 Views Asked by At

After creating a few WMS, I have tried loading them in R to display them on a map but sadly the leaflet map doesn't show them - only the backdrop does. I had no issue displaying them in QGIS with authentication, etc.

The layers contained in the WMS are all rasters from tiff files that have a global coverage, CRS is EPSG:3857.

I suspect that the authorisation is causing some problems. I have tried to either add the credentials as part of the WMS link, as options in the leaflet map code or in add_headers.

Any help would be very appreciated, thank you. I cannot provide the original links due to the related data being unpublished, but I have retained structure of links and code - and I would like to stress again that the WMS and the authentication works fine in QGIS.

# alternative 1
url_path <- "https://datasets.unim.global/maps/a3910gki-edpo-09f1-836e-e6ce1867b78e?
request=getCapabilities&service=WMS&cache=false&username=MY_USER&password=MYPASS"

### Note that I have also tried to call url_path with a shorter url but still no luck:
# https://datasets.unim.global/maps/a3910gki-edpo-09f1-836e-e6ce1867b78e?

leaflet() %>%
  addTiles() %>%
  addWMSTiles(url_path,
              layers = 'alba',
              options = WMSTileOptions(format = "image/png",transparent = TRUE))


# alternative 2
url_path <- "https://datasets.unim.global/maps/a3910gki-edpo-09f1-836e-e6ce1867b78e?
request=getCapabilities&service=WMS&cache=false&"

username <-'MY_USER'
password<- 'MYPASS'

auth_headers <- add_headers(Authorization = paste("Basic", enc2utf8(paste(username, ":", password))))

leaflet() %>%
  addTiles() %>%
  addWMSTiles(url_path,
              layers = 'alba',
              options = WMSTileOptions(format = "image/png",transparent = TRUE, headers = auth_headers))
0

There are 0 best solutions below