Skip to content

Commit b42052c

Browse files
committed
Enable offline reproduction of results
1 parent 3e73815 commit b42052c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

intro-spatial.Rmd

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,17 @@ To create a basemap with tmap, you can use the `read_osm` function, from the [**
10751075
```{r, fig.cap="London's population in 2001.", fig.width=4}
10761076
# Transform the coordinate reference system
10771077
lnd_wgs = spTransform(lnd, CRS("+init=epsg:4326"))
1078-
osm_tiles = tmaptools::read_osm(bbox(lnd_wgs)) # download images from OSM
1079-
tm_shape(osm_tiles) + tm_raster() + tm_shape(lnd_wgs) +
1080-
tm_fill("Pop_2001", fill.title = "Population, 2001", scale = 0.8, alpha = 0.5) +
1081-
tm_layout(legend.position = c(0.89,0.02))
1078+
if(curl::has_internet()) {
1079+
osm_tiles = tmaptools::read_osm(bbox(lnd_wgs)) # download images from OSM
1080+
tm_shape(osm_tiles) + tm_raster() +
1081+
tm_shape(lnd_wgs) +
1082+
tm_fill("Pop_2001", fill.title = "Population, 2001", scale = 0.8, alpha = 0.5) +
1083+
tm_layout(legend.position = c(0.89, 0.02))
1084+
} else {
1085+
tm_shape(lnd_wgs) +
1086+
tm_fill("Pop_2001", fill.title = "Population, 2001", scale = 0.8, alpha = 0.5) +
1087+
tm_layout(legend.position = c(0.89, 0.02))
1088+
}
10821089
```
10831090

10841091
Another way to make **tmap** maps have a basemap is by entering `tmap_mode("view")`. This will make the maps appear on a zoomable webmap powered by **leaflet**.

0 commit comments

Comments
 (0)