import basemapper as bm
slc = (-111.8887, 40.7556)
def view(style, **kw):
return bm.basemap(style, 720, 405, center=slc, zoom=12.4, **kw)Stacking, labels and features
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.
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:
from collections import Counter
layers = bm.list_layers("OpenFreeMap.Liberty")
print(len(layers), "layers")
for l in layers[:10]:
print(f"{l['id']:<22} {l['type']:<10} {str(l['source_layer']):<14} {l['feature']}")
print(Counter(l["feature"] for l in layers))111 layers
background background None background
natural_earth raster None terrain
park fill park parks
park_outline line park parks
landuse_residential fill landuse landcover
landcover_wood fill landcover landcover
landcover_grass fill landcover landcover
landcover_ice fill landcover landcover
landcover_wetland fill landcover landcover
landuse_pitch fill landuse landcover
Counter({'roads': 58, 'rail': 12, 'landcover': 11, 'places': 9, 'water': 7, 'poi': 5, 'boundaries': 3, 'parks': 2, 'buildings': 2, 'background': 1, 'terrain': 1})
Labels
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 list 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 = ["Esri.WorldImagery", bm.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:
for style in bm.basemap_provider("UGRC.Lite"):
print(style)
bm.basemap("UGRC.Lite", 720, 405, center=(-111.75, 40.62), zoom=10.5)https://tiles.arcgis.com/tiles/99lidPhWCzftIe9K/arcgis/rest/services/VectorHillshade/VectorTileServer/resources/styles/root.json
https://tiles.arcgis.com/tiles/99lidPhWCzftIe9K/arcgis/rest/services/LiteBase/VectorTileServer/resources/styles/root.json
https://tiles.arcgis.com/tiles/99lidPhWCzftIe9K/arcgis/rest/services/LiteLabels/VectorTileServer/resources/styles/root.json

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:
bm.basemap("UGRC.Lite", 720, 405, center=(-111.75, 40.62), zoom=10.5, labels=False)
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=["background", "water", "parks", "roads"])
view("OpenFreeMap.Liberty", features=["-roads", "-rail", "-poi"])
list_layers() takes the same filters and lists what a render with them draws, to check a filter before rendering:
for l in bm.list_layers("OpenFreeMap.Liberty", labels=False, features=["water", "parks"]):
print(f"{l['id']:<22} {l['type']:<6} {l['feature']}")park fill parks
park_outline line parks
waterway_tunnel line water
waterway_river line water
waterway_other line water
water fill water
Layers
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=["-road_*", "-bridge_*", "-tunnel_*"])
A name that matches no layer warns, so a typo does not go unnoticed:
m = view("OpenFreeMap.Liberty", layers=["-lable_village"])
_ = m.render_array()/home/runner/work/basemapper/basemapper/py-basemapper/src/basemapper/_basemap.py:200: UserWarning: layers: "-lable_village" matches no layer
In plots
The plot layers take the same arguments:
import geodatasets
import geopandas as gpd
from plotnine import geom_map, ggplot, theme, theme_void
nc = gpd.read_file(geodatasets.get_path("geoda.sids"))
water = bm.basemap_provider("OpenFreeMap.Liberty", features=["water"], labels=False)
(
ggplot(nc)
+ bm.geom_basemap(["Esri.WorldShadedRelief", water])
+ geom_map(fill=None, color="#262626", size=0.25)
+ theme_void()
+ theme(figure_size=(8, 3.6))
)