Skip to content

Replicates the MapLibre example PMTiles source and protocol. It is YAML only: maplibre-yaml sees the pmtiles:// URL (or a .pmtiles file name), registers the PMTiles protocol itself — once, on the maplibre-gl module the map renders with — and reads the archive with HTTP range requests.

Edit this map in the playground

pmtiles-source-and-protocol.yaml
# PMTiles vector source via the pmtiles:// protocol — YAML only:
# maplibre-yaml registers the protocol itself when a source's URL is a
# pmtiles:// URL or a .pmtiles file. Data: Protomaps' Florence sample (ODbL).
type: map
id: pmtiles-source-and-protocol
config:
center: [11.2558, 43.7696]
zoom: 12.5
mapStyle: "https://demotiles.maplibre.org/style.json"
sources:
firenze:
type: vector
url: "pmtiles://https://pmtiles.io/protomaps(vector)ODbL_firenze.pmtiles"
layers:
- id: firenze-landuse
type: fill
source: firenze
source-layer: landuse
paint:
fill-color: "#7b2cbf"
fill-opacity: 0.25
- id: firenze-roads
type: line
source: firenze
source-layer: roads
paint:
line-color: "#5a189a"
line-width: 1
  • type: vector stays the MapLibre source type; the URL says the file is a PMTiles archive. url: https://…/firenze.pmtiles (no scheme) works the same — and so does a file on your own site, url: data/firenze.pmtiles.
  • No page JavaScript, no import-map entry: the PMTiles reader is part of @maplibre-yaml/core (CDN build and npm package alike).
  • The archive is read in parts (range requests), so the host must support them — GitHub Pages, Netlify, S3 and R2 do; python -m http.server doesn’t. See Publishing › Large files.
  • Data: Protomaps Florence sample extract (ODbL).

Register the protocol in page JavaScript when you need custom headers or a custom Source; a page that registers pmtiles itself keeps its registration. Register through @maplibre-yaml/core/maplibre, so the protocol lands on the same maplibre-gl module <ml-map> renders with:

import { addProtocol } from "@maplibre-yaml/core/maplibre";
import { Protocol } from "pmtiles";
addProtocol("pmtiles", new Protocol().tile);

It is also how to use PMTiles inside a basemap style loaded from a URL (a Protomaps basemap): maplibre-yaml can’t see inside that style before MapLibre loads it.