Also available for Python — the same Rust core, and the same functions and argument names (
verb(m, ...)here ism.verb(...)in Python). Python documentation →
basemapper renders MapLibre GL basemaps (vector and raster styles) headlessly with a Rust core: to PNG, arrays, {terra} rasters or true vector SVG, at any fractional zoom and pixel ratio, and as {ggplot2} and {tmap} v4 layers that render at the output device’s resolution.
Installation
Prerequisites
The package compiles a Rust extension during installation. Install the dependencies for your platform before proceeding.
Install the package
# Any one of these installs the v0.1.1 release; each compiles the Rust core.
pak::pak("ar-puuk/basemapper/r-basemapper@v0.1.1")
remotes::install_github("ar-puuk/basemapper", subdir = "r-basemapper", ref = "v0.1.1")
devtools::install_github("ar-puuk/basemapper", subdir = "r-basemapper", ref = "v0.1.1")These install the latest release, v0.1.1 (all releases). For the development version, leave out the version: pak::pak("ar-puuk/basemapper/r-basemapper").
Quick example
library(basemapper)
# Built-in basemaps by leaflet name (list_providers(), providers$...);
# the name works as a style
style <- "OpenFreeMap.Liberty"
style <- basemap_provider("Esri.WorldGrayCanvas", type = "raster") # pick the form
style <- basemap_provider("OpenFreeMap.Liberty", tiles = "data/omt.pmtiles") # your own tiles
# Stack parts of basemaps: imagery under a vector basemap's labels
hybrid <- c("Esri.WorldImagery", basemap_provider("OpenFreeMap.Liberty", labels = "only"))
# labels = FALSE / "only", features = c("water", "roads") / "-buildings"
# A view: centre + zoom, or bounds to fit
m <- basemap(style, 800, 600, center = c(-122.45, 37.75), zoom = 12, pixel_ratio = 2)
render_png(m, path = "sf.png") # 1600 x 1200
render_svg(m, path = "sf.svg") # true vector
get_bounds(set_view(m, zoom = 13), lonlat = TRUE)
# One-shot render of bounds to a georeferenced [height, width, 4] array
a <- render_basemap_raw(c(-122.5, 37.7, -122.4, 37.8), 400, 300, style)
# Your own tile data works as a style: tile URLs, TileJSON, PMTiles
# archives (URL or local file), ArcGIS services
m <- basemap("data/area.pmtiles", 800, 600, bounds = c(-122.5, 37.7, -122.4, 37.8))
style <- tile_style("https://example.com/{z}/{x}/{y}.png", maxzoom = 16) # with overrides
style <- wms_style("https://gis.example.com/wms", layers = "imagery")Get started
See the Getting Started vignette for a walkthrough of rendering basemaps with {ggplot2}, {tmap}, and raw RGBA output.
Related
- Python docs — the Python package exposes the same Rust core via PyO3.