Skip to content

Cloud-native data

A GeoJSON file of tens of megabytes is slow to download and slow to draw. Large-data formats (also called cloud-native) are made to be read in parts: the browser asks the web server for only the bytes it needs, so a map can show one city from a country-sized file. maplibre-yaml reads four of them with nothing but YAML, in a plain HTML page, in Astro and under any bundler.

You haveUsePage
Many features that don’t change (buildings, parcels, roads), any sizePMTiles: vector tiles cut in advance, in one filePMTiles
A file of features with properties to click, filter or classifyFlatGeobuf (.fgb)FlatGeobuf
A table from Python, R or DuckDB, especially one with many columnsGeoParquet (.parquet)GeoParquet
Imagery, elevation, or a grid of measurementsCloud Optimized GeoTIFF (.tif)COG
Raster or elevation tiles you already cutPMTiles (a raster archive)PMTiles
A whole basemap with no tile serverProtomaps .pmtilesHost your own basemap

Under about 10 MB, plain GeoJSON is fine (Loading data). For which format to use at which size, with the command that writes it and the YAML to paste, see Choose a format for large data. npx maplibre-yaml@latest prepare <file> looks at a file and prints that advice for it. FlatGeobuf and GeoParquet files become ordinary GeoJSON sources, so popups, classify:, clustering and fitTo work on them as on any GeoJSON. PMTiles holds tiles, cut in advance, which is what keeps a huge dataset fast.

This document draws a PMTiles archive (imagery and district outlines) and a FlatGeobuf file (the coloured districts):

large-data.yaml
# A PMTiles archive (imagery and district outlines) and a FlatGeobuf file
# (the coloured districts), read with no page JavaScript. Synthetic,
# public-domain data for a made-up coast.
type: map
id: cloud-native-demo
config:
center: [10.2, 42.15]
zoom: 8
mapStyle: "https://tiles.openfreemap.org/styles/positron"
fitTo: { source: districts, padding: 24 }
legend:
title: District plan
sources:
imagery:
type: raster
url: /gallery-assets/cloud-native/imagery.pmtiles
tileSize: 256
outlines:
type: vector
url: /gallery-assets/cloud-native/districts.pmtiles
districts:
type: geojson
url: /gallery-assets/cloud-native/districts.fgb
layers:
- id: imagery
type: raster
source: imagery
paint: { raster-opacity: 0.8 }
- id: districts
type: fill
source: districts
paint:
fill-color: ["match", ["get", "category"], "park", "#2a9d8f", "residential", "#e9c46a", "industrial", "#e76f51", "#8d99ae"]
fill-opacity: 0.6
legend: { label: "Districts (FlatGeobuf)", color: "#e9c46a", shape: square }
interactive:
click:
popup:
- h3: [{ property: name }]
- p: [{ str: "Population " }, { property: population }]
- id: outlines
type: line
source: outlines
source-layer: districts
paint: { line-color: "#1d3557", line-width: 1.2 }
legend: { label: "Outlines (PMTiles)", color: "#1d3557", shape: line }
A PMTiles archive (imagery and outlines) and a FlatGeobuf file (the coloured districts). Click a district.

Edit this map in the playground

The /gallery-assets/… files are on this documentation site, which doesn’t let other sites read them. To run the document on your own site, download imagery.pmtiles, districts.pmtiles and districts.fgb into a gallery-assets/cloud-native/ folder (in public/ for Astro), and serve it with a server that supports range requests, such as npx serve.

There is no <script> to register anything and no extra import map entry.

The rule: type: is what MapLibre draws, the URL is what the file is

Section titled “The rule: type: is what MapLibre draws, the URL is what the file is”

You keep writing the source type MapLibre knows (vector, raster, raster-dem, geojson) and point url: at the file. The file name tells maplibre-yaml how to read it.

  • pmtiles:// in front of the URL works too (url: pmtiles://data/x.pmtiles), the form MapLibre’s own examples use; so does cog:// for a COG.

  • format: names the format when the URL can’t, such as a signed link or an API endpoint with no file extension. It wins over the URL:

    sources:
    parcels:
    type: geojson
    url: "https://data.example.org/api/parcels?f=fgb"
    format: flatgeobuf # pmtiles, flatgeobuf, geoparquet or cog

These files are read in parts with HTTP range requests, so the server has to support them. GitHub Pages, Netlify, Cloudflare, S3 and R2 do, and so do npx serve, astro dev and astro preview on your computer; python -m http.server doesn’t. A file on another site also needs CORS that allows the Range header. The full host list and the CORS rule are in Publishing › Large files.

maplibre-yaml downloads the reader for a format only when a map uses it. From the CDN that is automatic; if you host maplibre-yaml’s own files, copy the whole dist/ folder, not only register.js (Hosting the files yourself).

A problem with one file never takes down the map: the basemap and every other layer still draw, and the map’s notice (“Part of this map couldn’t load”) says what happened. The common cases:

The notice saysFix
”…was served without range-request support”Use a server with range requests (above). Locally, npx serve instead of python -m http.server.
”…comes from a server that compresses the parts of files it sends”cdn.jsdelivr.net does this. Put the file on your own site, or use fastly.jsdelivr.net.
”The browser couldn’t read …” (CORS, or unreachable)The other server must allow your site and the Range header (Publishing).
“…isn’t a PMTiles file. A wrong path often returns a web page instead”Check the file name and folder.
”…didn’t load (404 Not Found)”, with where the browser lookedCheck the path; on a project site, set base (Loading data › paths).
“…is 180 MB, too large to load whole in a browser”Add load: viewport (FlatGeobuf, GeoParquet), or convert the data to PMTiles.
”…is in EPSG:…”The file is in the wrong projection; the notice gives the command that converts it (FlatGeobuf, GeoParquet, COG).
”The PMTiles reader (…/chunks/pmtiles.js) couldn’t be downloaded”Copy maplibre-yaml’s whole dist/ folder, or load it from the CDN (above).

Problems specific to one format are on its page. More symptoms: Troubleshooting › Large data.

In a format v2 document the URL stays in the source, and format:, load:, columns: and colorRamp: move under the source’s runtime:. A Protomaps basemap is written under style: as basemap: data/nyc.pmtiles, the same forms as mapStyle:.

version: 2
type: map
id: large-data-v2
style:
basemap: "https://tiles.openfreemap.org/styles/positron"
center: [10.2, 42.15]
zoom: 10
sources:
outlines: { type: vector, url: /gallery-assets/cloud-native/districts.pmtiles }
points:
type: geojson
url: /gallery-assets/cloud-native/points.fgb
runtime:
load: { mode: viewport, minzoom: 11 }
districts:
type: geojson
url: /gallery-assets/cloud-native/districts.parquet
runtime:
columns: [name, category]
layers:
- { id: districts, type: fill, source: districts, paint: { fill-color: "#e9c46a", fill-opacity: 0.5 } }
- { id: outlines, type: line, source: outlines, source-layer: districts }
- { id: points, type: circle, source: points }

Each format now has its own page.

See PMTiles.

See PMTiles › Inside a basemap style.

See Host your own basemap.

See FlatGeobuf.

See GeoParquet.

See Cloud Optimized GeoTIFF (COG).

See Export to style.json › Large-data files.