Skip to content

Format v2 (opt-in)

Format v1 is the default, and every other page of these docs uses it. Format v2 is an opt-in layout of the same map document: it splits the document into style:, the parts that become a MapLibre style.json, and runtime:, the behaviour that only exists while the map runs. Choose it when you export maps and want that line visible in the file, or when you generate or transform documents in code and want the style half to be the style spec’s shape. Both formats draw the same map, so you can change one file at a time.

Here is one map written both ways. A v2 document and its v1 twin parse to the same model, so <ml-map> renders them the same and mlym emit exports the same style.json.

version: 2
type: map
id: quakes
style:
basemap: https://tiles.openfreemap.org/styles/liberty
center: [-120, 37]
zoom: 4
sources:
quakes:
type: geojson
url: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson
runtime:
refresh:
refreshInterval: 30000
layers:
- id: quakes
type: circle
source: quakes
paint:
circle-radius: 6
circle-color: "#dc2626"
runtime:
label: "Earthquakes"
toggleable: true
runtime:
controls:
navigation: true

Only where the keys sit differs. In v1 the live-data keys sit on the source and the layer-panel keys on the layer; in v2 each group is under a nested runtime:. Every value keeps its meaning and its spelling, except one rename: v1’s mapStyle is v2’s basemap.

mlym validate and mlym emit read both formats, and so do <ml-map>, the Astro components and the JavaScript API. A v2 document starts with version: 2 and type: map.

If you know a v1 document, this table is the whole migration.

v1 locationv2 location
top-level title / descriptionunchanged: the document root
config.mapStylestyle.basemap (renamed)
config.center / zoom / pitch / bearingstyle.center / zoom / pitch / bearing
config.bounds / minZoom / maxZoom / maxBounds / minPitch / maxPitchruntime.map.*
config.localeruntime.map.locale
config.fitToruntime.fitTo
config.interactive / scrollZoom / boxZoom / dragRotate / dragPan / keyboard / …runtime.map.*
config.hash / attributionControl / logoPosition / trackResizeruntime.map.*
top-level sourcesstyle.sources
source refresh / stream / cache / loadingsource runtime.*
source format / load / columns / colorRampsource runtime.*
top-level layersstyle.layers
layer classify / beforeunchanged: on the layer
layer interactive / legend / label / toggleable / effectlayer runtime.*
top-level images / terrain / sky / light / projectionstyle.*
top-level markers / popupsruntime.markers / runtime.popups
top-level controlsruntime.controls
top-level legendruntime.legend
block style: / className:runtime.container.style / runtime.container.className
top-level statestyle.state (or document root)
top-level parametersruntime.parameters (or document root)

Every v2 key is in the map document (format v2) reference.

The style: half: what goes into style.json

Section titled “The style: half: what goes into style.json”

Everything under style: ends up in the exported style.json, sometimes transformed on the way. It holds:

  • basemap: the basemap, merged in on export. This is v2’s name for v1’s mapStyle, and it takes the same forms, including a Protomaps basemap from one .pmtiles file (basemap: data/nyc.pmtiles, or basemap: { pmtiles: data/nyc.pmtiles, flavor: dark }).
  • the camera: center, zoom, pitch, bearing, at the style: root because they are root properties of a style.
  • sources: your data sources, each under its name.
  • layers: your layers, in drawing order.
  • state: values that expressions read with global-state, and optional metadata.
  • images, terrain, sky, light, projection: the style’s root properties, as in v1.

Everything under runtime: is behaviour and page furniture: what the map does while it runs. Most of it has no style.json form and is left out of an export, with a warning naming each key. Three keys export with a fallback instead: markers become a symbol layer with pin images, fitTo becomes a fixed camera, and a layer’s effect exports as the layer’s own static style. Export classes lists what happens to each key. runtime: holds:

  • map: MapLibre Map options (minZoom, maxZoom, scrollZoom, interactive, bounds, maxBounds, locale, and the rest).
  • fitTo: frame the map on a source’s data when it loads.
  • markers and popups: map-level markers and popups.
  • controls: navigation, scale, geolocate, fullscreen, attribution.
  • legend: the map’s legend.
  • parameters: labels and ranges for your state keys, which a control needs but a style has nowhere to put.
  • container: the map element’s own style and className.
version: 2
type: map
id: chrome-demo
style:
basemap: https://tiles.openfreemap.org/styles/liberty
center: [-73.98, 40.75]
zoom: 11
layers: []
runtime:
map:
minZoom: 4
maxZoom: 16
controls:
navigation: true
scale: true
legend:
title: "Legend"
position: top-left
container:
style: "height: 480px;"
className: "map-embed"

A source’s runtime: live data stays beside its source

Section titled “A source’s runtime: live data stays beside its source”

A source’s live-data settings (refresh, stream, cache, loading) go under that source’s own runtime:, as do the keys that say how a large-data file is read: format, load, columns and colorRamp. They sit beside the fields they act on, so a source is still one thing to edit.

version: 2
type: map
id: live-quakes
style:
basemap: https://tiles.openfreemap.org/styles/liberty
center: [-120, 37]
zoom: 4
sources:
quakes:
type: geojson
url: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson
runtime:
refresh:
refreshInterval: 30000
cache:
enabled: true
ttl: 300000
layers:
- id: quakes
type: circle
source: quakes
paint:
circle-radius: 6
circle-color: "#ef4444"

On export, the source’s style fields (type, url, data, cluster, …) go into style.json, and its runtime: block is left out: the exported style loads the data once, with no polling.

A layer’s runtime: interactions, legend, label, toggle

Section titled “A layer’s runtime: interactions, legend, label, toggle”

A layer’s interaction and presentation keys (interactive, legend, label, toggleable, and the experimental effect) go under the layer’s own runtime: (legend: false there keeps the layer out of the legend). paint, layout, filter, type, source and before stay where they are in v1, and so does a classify: block, which becomes plain paint expressions.

version: 2
type: map
id: interactive-quakes
style:
basemap: https://tiles.openfreemap.org/styles/liberty
center: [-120, 37]
zoom: 4
sources:
quakes:
type: geojson
url: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson
layers:
- id: quakes
type: circle
source: quakes
paint:
circle-radius: 6
circle-color: "#dc2626"
runtime:
label: "Earthquakes"
toggleable: true
legend:
color: "#dc2626"
label: "Earthquake (past week)"
shape: circle
interactive:
click:
popup:
- p:
- property: title

state: goes into the style, so it belongs under style:. The labels and ranges a control shows for it don’t, so they go under runtime.parameters:, keyed by the same name.

version: 2
type: map
id: parameterized
style:
basemap: https://tiles.openfreemap.org/styles/liberty
center: [0, 20]
zoom: 1.5
state:
scenario:
default: baseline
layers: []
runtime:
parameters:
scenario:
label: "Scenario"
type: enum
values: [baseline, buildout]

v2 also accepts state: and parameters: at the document root, where v1 has them. When a key is in both places, the nested one wins.

The document still parses, but mlym validate warns about a key left where v1 puts it: Unknown key "mapStyle" for a mapStyle at the style: root, or, for a refresh: directly on a source, that it goes under the source’s runtime: block. Look the key up in Where did my key go?

The published JSON Schemas describe format v1. Leave the schema modeline out of a v2 file and check it with mlym validate (Editor setup).