basemap()
Create a basemap view.
Usage
basemap(
style,
width=800,
height=600,
*,
center=None,
zoom=None,
bounds=None,
crs=None,
pixel_ratio=1.0,
layers=None,
labels=True,
features=None,
auth_token=None,
tile_timeout_ms=10000,
max_tiles=256,
tile_concurrency=16,
fail_on_tile_error=False
)The view is a centre and MapLibre zoom (512 px tiles; fractional zooms are rendered natively, not resampled), or bounds to fit. width and height are CSS pixels; images are pixel_ratio times larger with the same view and label layout (MapLibre’s devicePixelRatio): pixel_ratio=2 gives a sharp 2x image, pixel_ratio=dpi / 96 matches a print resolution. The same function exists in R (basemap()) and Rust (Basemap::new()), with the same arguments.
Parameters
style: Union[StyleLike, Sequence[StyleLike]]-
A MapLibre GL style URL or JSON string (e.g. from basemap_provider()), or a list of those stacked bottom to top (e.g. a basemap published as separate hillshade, base and label services).
width: int = 800-
View width in CSS pixels.
height: int = 600-
View height in CSS pixels.
center: Optional[Tuple[float, float]] = None-
(longitude, latitude)of the view centre. zoom: Optional[float] = None-
MapLibre zoom (0-22, fractional allowed).
bounds: Optional[Any] = None-
Bounds to fit instead of
center/zoom: a[xmin, ymin, xmax, ymax]sequence (incrs, default EPSG:4326), a dict, or a GeoDataFrame / GeoSeries. crs: Optional[Any] = None-
CRS of
bounds(anythingpyproj.CRSaccepts). pixel_ratio: float = 1.0-
Device pixels per CSS pixel.
layers: Optional[List[str]] = None-
Optional layer filter applied to every style: plain IDs keep only those layers,
-prefixed IDs drop them;*and?are wildcards ("-label_*"). See list_layers(). labels: Union[bool, str] = True-
Truekeeps every layer,Falsedrops the labels (text and icons),"only"keeps only the labels on a transparent background, to stack over another map. Catalogue raster basemaps switch to their label-free or label-only tiles. features: Optional[List[str]] = None-
Optional feature filter applied to every style: plain names keep those features,
-prefixed names drop them, e.g.["water", "roads"]or["-buildings"]. Features: background, water, landcover, parks, buildings, roads, rail, boundaries, places, poi, terrain, other (see thefeatureof list_layers()). auth_token: Optional[str] = None-
Optional access token for the tile service.
tile_timeout_ms: int = 10000-
Per-tile HTTP timeout in milliseconds.
max_tiles: int = 256-
Maximum tiles fetched per style.
tile_concurrency: int = 16-
Parallel tile downloads.
fail_on_tile_error: bool = False- Abort on a failed tile instead of leaving it empty.
Returns
A: Basemap- class:Basemap.
Examples
>>> import basemapper
>>> # UGRC's Lite basemap: its hillshade, base and labels services
>>> m = basemapper.basemap(
... "UGRC.Lite", 800, 600, center=(-111.8887, 40.7556), zoom=12.4, pixel_ratio=2,
... )
>>> m.render_png("slc.png") # 1600 x 1200
>>> m.render_svg("slc.svg") # vector