2017-06-23 46 views
2

简介:传单地图图块在R中的reveal.js演示文稿中不可见?

我试图嵌入单张地图到RMarkdown文件中的revealjs演示。我的下面的例子非常接近,但它是(1)缺少tile,(2)弹出窗口不显示,(3)图例和字体太大了!

我并不太在意代码块如何看待这一刻。我打算为我的最终产品使用results = "hide"幻灯片选项。

在此先感谢!

重复的例子:

--- 
title: "My Presentation" 
author: Me 
date: 2017-06-23 
output: 
    revealjs::revealjs_presentation: 
     theme: black 

--- 

## Loading in necessary packages: 
```{r} 
library(dplyr) 
library(sp) 
library(rgdal) 
library(rgeos) 
library(RColorBrewer) 
library(classInt) 
library(leaflet) 
library(htmlwidgets) 
``` 

## Defining our data: 
```{r} 
lat <- c(45.51158000, 45.50431159, 45.496539) 
lon <- c(-122.548056, -122.54775, -122.54788) 
no2 <- c(17.37, 25.61, 24.69) 

dta <- data.frame(lat, lon, no2) 
colnames(dta) <- c("lat","lon","no2") 
``` 

## Create layer of spatial points: 
```{r} 
points <- SpatialPointsDataFrame(data.frame(x=dta$lon, y=dta$lat), data = data.frame(dta$no2)) 

plotclr <- (brewer.pal(7, "RdYlGn")) 
class <- classIntervals(dta$no2, n = 7, style = "fixed", fixedBreaks = c(0,5,10,15,20,25,30)) 
colcode <- findColours(class, rev(plotclr)) 
plot(points, col=colcode, pch=19) 

pop1<-paste0("<b>NO2:</b> ", dta$no2, " ppb", 
     "<br /> <b>Lat:</b> ", dta$lat, 
     "<br /> <b>Lon:</b> ", dta$lon) 
``` 

## Creating the leaflet map: 
```{r} 
no2_map <-leaflet()%>% 
    addTiles('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png') %>% 
    addCircleMarkers(data=points, color = "black", radius = dta$no2, fillColor = colcode, fillOpacity=0.7, weight=1, popup=pop1) %>% 
    addLegend(position = "bottomright", colors = rev(plotclr), labels = rev(c("30","25","20","15","10","5","0")), opacity = 0.9, title = "NO2 (ppb)") 
``` 

--- 
```{r} 
no2_map 

saveWidget(no2_map, file="map.html") 

``` 

回答

0

不幸的是,reveal.js和单张不玩很好地结合在一起,并与您的地图幻灯片可能会丢失层。这是由于Leaflet无法辨别作为地图容器的DOM元素的大小,因为reveal.js将所有元素的大小调整为dinamically。

最简单的解决方法是只需刷新页面,当您在带有Leaflet地图的幻灯片中。您也可以尝试延期拨打电话map.invalidateSize()(使用平头Javascript中的setTimeout()

+0

我已经在[here](http://www.jacksonvoelkel.com/presentations/sar/GIA.html# /部分-65)。但在Javascript中没有经验。如果没有明确的方法让地图看起来很正确,那么我可以放弃这种方法来更容易一些。 – spacedSparking