2017-10-21 47 views
0

我使用R中的leaflet包生成了一张地图。一切正常,我可以将贴图发布到我的网站。然而,我的网站使用SSL,当地图加载时,我得到混合内容通知,因为CartonDB.Positron通过http加载。使用小册子在ssl中载入供应商瓷砖R

混合内容:在该页面的“https:// mywebsite.com”装载了HTTPS,但要求一个不安全的形象“http://b.basemaps.cartocdn.com/light_all/12/1171/1566.png在Chrome中 - 特别是,我得到的这条消息“控制台开发者工具” ”。此内容也应通过HTTPS提供。

有没有一种方法可以在R中通过SSL在Leaflet中加载提供者切片?

例如,我可以在addProviderTiles中指定从SSL加载吗?现在我只有addProviderTiles("CartoDB.Positron")

回答

0

他们已将http协议硬编码到URL中,因此不能使用Carto提供程序。 https://github.com/rstudio/leaflet/issues/472

暂且可以使用自定义模板:

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) 
) 

来自我在他们的跟踪器提出的问题https://rpubs.com/walkerke/custom_tiles

声明,我无法测试功能以上呼吁,因为我目前没有在我的系统上安装RStudio,但据我所知,它应该工作。

+0

我同意这应该工作,但事实并非如此。问题是'urlTemplate =“https'中的”s“,如果你使用”s“运行上面的代码,数据点会被绘制出来,但背景图像是纯灰色的,如果你删除了”s“ “http”,地图加载并成为背景图像,似乎调用“https”是问题,不幸的是,'addTiles'选项似乎不是一种可行的解决方法。 – scottsmith

1

修复@iH8建议的作品。这是我相应的R代码。

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>' 
    )) 

卡托建议网址(1)

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

但只是添加https://开头到正常的URL也有效。

相关问题