宣传单地图不会在浏览器中呈现

时间:2017-07-04 00:42:12

标签: html r leaflet r-markdown

我有一张使用Leaflet的地图,它在r markdown的html输出中有效,但是当我在Google或IE中打开html时,地图不会渲染。 Ggmap工作正常,但我更喜欢交互式地图。有什么想法吗?

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = FALSE,
  warning = FALSE,
  message = FALSE,
  comment=NA,
  fig.height=7,
  fig.width = 9)
```

```{r Libraries}
library(leaflet)
library(ggmap)
```

Plot map with leaflet package.    
```{r Leaflet}
#using leaflet
Pin <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))

Bne2 <- leaflet() %>%
  addTiles()  %>%
  addMarkers(data=Pin)
Bne2

```

Plot map with ggmap package.   
```{r Ggmap}
#using ggmap
Sa2 <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Brisbane <- get_map("Brisbane,Australia",zoom=11)

BNE <- ggmap(Brisbane)+
  geom_point(data=Sa2,aes(x=Lng,y=Lat),color="black",size=3)

plot(BNE)

```

1 个答案:

答案 0 :(得分:1)

我看到同样的问题,似乎与浏览器中未呈现的默认图块有关。但是,我不知道为什么会这样。

所以有几个选项

  1. 更改切片图层(https://leaflet-extras.github.io/leaflet-providers/preview/
  2. 使用其他映射包。在这里,我演示了用于绘制交互式Google地图的googleway套餐
  3. ```{r Libraries}
    library(leaflet)
    library(ggmap)
    library(googleway)
    ```
    
    Plot map with leaflet package.    
    ```{r Leaflet}
    #using leaflet
    Pin <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
    
    Bne2 <- leaflet() %>%
      addTiles(urlTemplate = 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png')  %>%
      addMarkers(data=Pin)
    Bne2
    
    ```
    
    Plot map with ggmap package.   
    ```{r Ggmap}
    #using ggmap
    Sa2 <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
    Brisbane <- get_map("Brisbane,Australia",zoom=11)
    
    BNE <- ggmap(Brisbane)+
      geom_point(data=Sa2,aes(x=Lng,y=Lat),color="black",size=3)
    
    plot(BNE)
    
    ```
    
    Plot map with googleway
    ```{r googleway}
    ## you need an api key to use google maps
    mapKey <- 'your_api_key'
    
    google_map(key = mapKey) %>%
        add_markers(data = Pin)
    
    ```
    

    这三个人都在Chrome中工作

    enter image description here