使用浏览器

时间:2017-07-28 11:27:55

标签: html r knitr r-leaflet

现在好几天了,基本层瓦片" OSM"和" Stamen.TonerLite" (我已经使用超过一年作为我的地图的标准瓷砖)没有正确显示 - 即它们不再可能在它们之间切换。

只要地图显示在RStudio和RStudio Viewer中,一切都很完美。但是,只要我在浏览器中打开.Rmd输出的相应.html文件(我尝试过chrome,Internet Explorer,edge和firefox),就不可能在切片之间切换了。要么" OSM"显示,我无法切换到" Stamen.TonerLite"反之亦然。
我尝试过不同的图层图块或超过2层图块,但效果相同。即使我切换到其他人,也始终只能看到一个图层图块。

我的案例的

可重复的示例

---
title: "stackoverflow"
author: " "
date: " "
output: html_document
---

```{r, echo = T}
library(leaflet)

m <- leaflet() %>%
     addTiles(group = "OSM") %>%
     addProviderTiles("Stamen.TonerLite") %>%
     addLayersControl(baseGroups = c("OSM", "Stamen.TonerLite")) %>%
     addCircleMarkers(lat = 47.4,
                      lng = 9.37,
                      radius = 10,
                      fillOpacity = 1.0)
m
```

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:4)

尝试这一点,重点是将两个提供者切片管道传递给addTiles()参数

---
title: "stackoverflow"
author: " "
date: " "
output: html_document
---

```{r, echo = T}
library(leaflet)

m <- leaflet() %>%
 addTiles() %>%
 addProviderTiles(providers$OpenStreetMap, group = "OSM") %>%
 addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite") %>%
 addLayersControl(baseGroups = c("OSM", "Toner Lite")) %>%
 addCircleMarkers(lat = 47.4,
                  lng = 9.37,
                  radius = 10,
                  fillOpacity = 1.0)
m
```