A style is a stack of layers: background, water, roads, labels and so on. basemapper can draw only some of them, and can stack several styles into one map.
library(basemapper)
slc <- c(-111.8887, 40.7556)
view <- function(style, ...) basemap(style, 720, 405, center = slc, zoom = 12.4, ...)What a style draws
list_layers() lists a style’s layers in drawing order,
with the vector tile layer each one draws (source_layer)
and the feature it shows:
l <- list_layers("OpenFreeMap.Liberty")
nrow(l)
#> [1] 111
head(l, 10)
#> id type source_layer feature
#> 1 background background <NA> background
#> 2 natural_earth raster <NA> terrain
#> 3 park fill park parks
#> 4 park_outline line park parks
#> 5 landuse_residential fill landuse landcover
#> 6 landcover_wood fill landcover landcover
#> 7 landcover_grass fill landcover landcover
#> 8 landcover_ice fill landcover landcover
#> 9 landcover_wetland fill landcover landcover
#> 10 landuse_pitch fill landuse landcover
table(l$feature)
#>
#> background boundaries buildings landcover parks places poi
#> 1 3 2 11 2 9 5
#> rail roads terrain water
#> 12 58 1 7Labels
labels = FALSE draws a style without its labels (text
and icons):
view("OpenFreeMap.Liberty", labels = FALSE)
labels = "only" draws just the labels, on a transparent
background, to go over another map.
Stacking
A vector of styles is drawn bottom to top. To filter one style of a
stack, give the filter to basemap_provider(); this puts
satellite imagery under a vector basemap’s labels:
hybrid <- c("Esri.WorldImagery", basemap_provider("OpenFreeMap.Liberty", labels = "only"))
view(hybrid)
ArcGIS basemaps are often published as separate services, drawn in order. The Utah Geospatial Resource Center’s Lite basemap is a hillshade, a base map and labels; its catalogue name stands for the three:
basemap_provider("UGRC.Lite")
#> [1] "https://tiles.arcgis.com/tiles/99lidPhWCzftIe9K/arcgis/rest/services/VectorHillshade/VectorTileServer/resources/styles/root.json"
#> [2] "https://tiles.arcgis.com/tiles/99lidPhWCzftIe9K/arcgis/rest/services/LiteBase/VectorTileServer/resources/styles/root.json"
#> [3] "https://tiles.arcgis.com/tiles/99lidPhWCzftIe9K/arcgis/rest/services/LiteLabels/VectorTileServer/resources/styles/root.json"
basemap("UGRC.Lite", 720, 405, center = c(-111.75, 40.62), zoom = 10.5)
Filters treat a stack as one basemap: a service they leave nothing of is skipped. Without labels, the labels service drops out, and the base map’s own labels go too:

Features
features keeps or drops parts of the map by what they
show: background, water, landcover, parks, buildings, roads, rail,
boundaries, places, poi and terrain. Plain names keep,
"-name" drops.
view("OpenFreeMap.Liberty", labels = FALSE, features = c("background", "water", "parks", "roads"))
view("OpenFreeMap.Liberty", features = c("-roads", "-rail", "-poi"))
list_layers() takes the same filters and lists what a
render with them draws, to check a filter before rendering:
list_layers("OpenFreeMap.Liberty", labels = FALSE, features = c("water", "parks"))
#> id type source_layer feature
#> 1 park fill park parks
#> 2 park_outline line park parks
#> 3 waterway_tunnel line waterway water
#> 4 waterway_river line waterway water
#> 5 waterway_other line waterway water
#> 6 water fill water waterLayers
Features are sorted from each layer’s source layer, as a convenience.
For exact control, layers keeps layers by id, or drops them
with "-"; * and ? are
wildcards:
view("OpenFreeMap.Liberty", layers = c("-road_*", "-bridge_*", "-tunnel_*"))
A name that matches no layer warns, so a typo does not go unnoticed:
m <- view("OpenFreeMap.Liberty", layers = "-lable_village")
invisible(render_array(m))
#> Warning: layers: "-lable_village" matches no layerIn plots
The plot layers take the same arguments:
library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
geom_basemap(c("Esri.WorldShadedRelief", basemap_provider("OpenFreeMap.Liberty", features = "water", labels = FALSE))) +
geom_sf(fill = NA, colour = "grey15", linewidth = 0.25) +
theme_void()