Universe

Render offline vector maps in Typst documents from a local PMTiles file! Draw GeoJSON overlays (RFC 7946) on your maps for sights and routes.

#import "@preview/mappa-mundi:0.1.0": map

#map(
  source: read("region.pmtiles", encoding: none),   // local basemap extract
  bbox: (10.662, 53.848, 10.712, 53.880),
  width: 10cm,
  geojson: read("overlay.geojson", encoding: none),
)

How to get the raw map data

You need a PMTiles file of the region:

  1. Install the pmtiles CLI from the go-pmtiles releases or your favorite package repository.
  2. Get your region with the coordinates (see the Protomaps guide):
    pmtiles extract https://build.protomaps.com/20261201.pmtiles region.pmtiles \
      --bbox=minlon,minlat,maxlon,maxlat
    
  3. Alternatively download the world from maps.protomaps.com/builds or source.coop/protomaps/openstreetmap, or tile your own Geofabrik .osm.pbf with tilemaker.

Keep the cut small (a city or district) so compiles stay fast.

Usage

Rendering in your Typst project

#map(
  source: read("region.pmtiles", encoding: none),
  bbox: (10.662, 53.848, 10.712, 53.880),  // area to render
  width: 10cm,
  height: 6.25cm,                          // or leave auto for the aspect
  geojson: read("overlay.geojson", encoding: none),
)

Instead of bbox you can pass center: (lat, lon) together with zoom.

GeoJSON overlays

Overlays are RFC 7946 GeoJSON: all seven geometry types, plus Feature and FeatureCollection wrappers. Positions are [lon, lat], bbox and foreign members are ignored, null geometries are skipped, and geometries crossing the antimeridian are drawn on both sides of the edge.

Per-feature styling comes from each Feature’s properties (simplestyle-compatible), falling back to the global geojson-* defaults:

Property Default Applies to
stroke #2660a4 Lines, polygon outlines
stroke-width 1.0 Lines, polygon outlines
stroke-opacity 1.0 Lines, polygon outlines
fill none Polygon interiors
fill-opacity 1.0 Polygon interiors
marker-color #ff0000 Point markers
marker-size 12.0 Point markers

Colors are hex strings (#rgb, #rrggbb, #rrggbbaa); widths/sizes are numbers in typographic points. Polygon interior rings cut holes (even-odd fill).

{
  "type": "Feature",
  "geometry": {
    "type": "LineString",
    "coordinates": [[10.687, 53.864], [10.6955, 53.870], [10.7012, 53.8752]]
  },
  "properties": { "stroke": "#c01c28", "stroke-width": 1.6 }
}

#map reference

Parameter Default Description
source none Raw bytes of a .pmtiles extract; renders at compile time via the bundled WASM plugin. Mutually exclusive with file.
center / zoom none / 14 Map center as (lat, lon) plus zoom level — the area to render in source mode.
bbox none Bounding box (west, south, east, north) — the area to render in source mode.
file none A pre-rendered SVG instead: bytes read from your document (read("map.svg", encoding: none)).
style-toml none Theme TOML (bytes or string) for source mode.
attribution © OpenStreetMap contributors, ODbL Map attribution line for source mode.
width 100% Display width (an absolute length is required for geojson).
height auto Display height; derived from the map’s aspect ratio when auto.
fit "contain" How the map fills the box: "contain", "cover", or "stretch".
alt none Alternative description for assistive technology; only embedded in PDF output.
pixel-density 192 Render resolution in dpi — only needed for geojson overlays with an explicit center on an SVG without an embedded viewport.
pixel-width / pixel-height auto Render resolution in pixels, instead of pixel-density.
geojson none GeoJSON data (RFC 7946): raw bytes (read("data.geojson", encoding: none)) or decoded data.
geojson-stroke rgb("#2660a4") Default stroke color for lines and polygon outlines.
geojson-stroke-width 1pt Default stroke width.
geojson-fill none Default fill for polygon interiors.
geojson-point-color red Default fill color of point markers.
geojson-point-size 12pt Default size of point markers.

Placement of overlays on file: SVGs is automatic: the renderer embeds its resolved viewport in the SVG and the package reads it back, so overlays line up without passing bbox/center (those are honored only for SVGs from other tools).

Themes

The built-in default theme is a light-mode style in the look of OpenStreetMap’s standard map.

A custom theme replaces any subset of the default and is passed as style-toml:

#map(
  source: read("region.pmtiles", encoding: none),
  bbox: (10.662, 53.848, 10.712, 53.880),
  width: 10cm,
  style-toml: read("theme.toml", encoding: none),
)
[water]
fill = "#1c5f8a"        # deep blue water

[roads.motorway]
stroke = "#e0803a"
width = 1.2

[labels]
road-color = "#555555"

Keys not present keep their built-in values. All recognized sections: background, [landcover], [landuse], [water], [buildings], [roads.motorway], [roads.primary], [roads.secondary], [roads.tertiary], [roads.minor], [roads.path], [roads.rail], [roads.ferry], [roads.other], [labels].

The repository contains an example theme, themes/grayscale-print.toml: the same map as a more minimal black-and-white style.

Copyright notice.

The maps in this gallery use OpenStreetMap data (via Protomaps) — © OpenStreetMap contributors, ODbL. If you embed a map in your own document, keep an attribution line.

More examples live in the repository’s gallery. The overlay example shows bus line 1 (Stadtwerke Lübeck Mobil, from OpenStreetMap) and the three historic parts of Lübeck’s old town island.

Compile-time WASM render Simple example Typst-drawn overlay Baked GeoJSON overlay
Lübeck rendered by the WASM plugin Lübeck basemap Lübeck with Typst-drawn overlay Lübeck with baked overlay

The CLI

The CLI renders the same maps as standalone SVGs — a convenient way to pre-render once and embed statically:

cargo install --git https://github.com/hoppjan/typst-mappa-mundi

mappa-mundi render \
  --pmtiles region.pmtiles \
  (--bbox west,south,east,north | --center lat,lon --zoom z) \
  (--size WxH | --size-pt WxH) [--dpi 192] \
  [--geojson data.geojson ...] [--style theme.toml] \
  [--overlay-typst] [--attribution "..."] \
  [-o map.svg] [--snippet]
Option Default Description
--pmtiles — PMTiles vector extract for the basemap; without it only overlays, scale bar and attribution are rendered.
--center / --bbox — Viewport as lat,lon (+ --zoom, default 14) or as west,south,east,north (auto-fitted, 10 % margin). Mutually exclusive.
--size 1000x700 Output size in pixels at --dpi; the SVG viewBox is derived in typographic points.
--size-pt — Output size directly in points WIDTHxHEIGHT (1 SVG unit = 1 pt on paper).
--dpi 192 Pixels per inch used to convert --size to points.
--geojson — GeoJSON overlay file (RFC 7946); repeatable.
--style built-in theme Theme TOML replacing any subset of the built-in theme.
--overlay-typst off Don’t bake overlays into the SVG; the Typst package draws them as vector curves after embedding.
--attribution © OpenStreetMap contributors, ODbL Map attribution shown on the map.
-o, --out map.svg Output SVG path.
--snippet — After rendering, print a Typst snippet to copy into your document.

Embed the result with file: read("map.svg", encoding: none). Overlays are baked into the SVG by default (one self-contained file; then don’t pass geojson in Typst). With --overlay-typst the CLI skips baking and the package draws the overlays instead — styling stays editable from Typst. --snippet prints a ready-made #map(...) call, including the attribution line.

Credits

  • The map engine’s PMTiles reader and MVT decoder were originally implemented by Importantus with the help of Claude — this project is built on that foundation. Thank you!
  • Map data rendered from OpenStreetMap is © OpenStreetMap contributors, ODbL.
  • Labels are set in DejaVu Sans Mono (deflate-compressed into mappa.wasm).

License

The package code is MIT (see LICENSE). The bundled mappa.wasm embeds the DejaVu Sans Mono font for map labels, distributed under the Apache-2.0 license (see LICENSE-DejaVu) — the deflate-compressed copy of the font inside the plugin is covered by it. Map data rendered from OpenStreetMap is © OpenStreetMap contributors, Open Database Licence (ODbL).