scottsmith
scottsmith

Reputation: 401

Loading provider tiles over ssl using leaflet in R

I have generated a map using the leaflet package in R. Everything works well and I can post the map to my website. My website uses SSL, however, and when the map is loaded I get mixed content notices because CartonDB.Positron is being loaded over http. Specifically, I get this message in the "Developer Tools - Console" in Chrome:

Mixed Content: The page at 'https:// mywebsite.com' was loaded over HTTPS, but requested an insecure image 'http://b.basemaps.cartocdn.com/light_all/12/1171/1566.png'. This content should also be served over HTTPS.

Is there a way to load provider tiles in Leaflet over SSL in R?

For example, can I specify in addProviderTiles to load from SSL? Right now I just have addProviderTiles("CartoDB.Positron").

Upvotes: 0

Views: 466

Answers (2)

ndevln
ndevln

Reputation: 183

The fix @iH8 suggested works. Here is my corresponding R code.

m <- leaflet() %>% addTiles('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
    attribution = paste(
      '&copy; <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',
      '&copy; <a href="https://cartodb.com/attributions">CartoDB</a>'
    ))

Carto recommends the url (1) :

https://cartodb-basemaps-{s}.global.ssl.fastly.net/{style}/{z}/{x}/{y}.png

But just adding https:// to the normal url also works.

Upvotes: 2

iH8
iH8

Reputation: 28678

They have hardcoded the http protocol into the URL so using the Carto provider isn't an option. I've raised an issue at their tracker: https://github.com/rstudio/leaflet/issues/472

For the time being you could use a custom template:

addTiles(
    urlTemplate = "https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png",
    attribution = '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, | &copy; <a href="https://carto.com/attribution">Carto</a>', 
    options = tileOptions(minZoom = 0, maxZoom = 18)
)

Taken from: https://rpubs.com/walkerke/custom_tiles

Disclaimer, i am unable to test the function call above because i currently do not have RStudio installed on my system but as far as i know, it should work.

Upvotes: 0

Related Questions