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.
Same map, two ways
Section titled “Same map, two ways”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: 2type: mapid: quakesstyle: 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: trueruntime: controls: navigation: truetype: mapid: quakesconfig: mapStyle: https://tiles.openfreemap.org/styles/liberty center: [-120, 37] zoom: 4sources: quakes: type: geojson url: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson refresh: refreshInterval: 30000layers: - id: quakes type: circle source: quakes paint: circle-radius: 6 circle-color: "#dc2626" label: "Earthquakes" toggleable: truecontrols: navigation: trueOnly 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.
Where did my key go?
Section titled “Where did my key go?”If you know a v1 document, this table is the whole migration.
| v1 location | v2 location |
|---|---|
top-level title / description | unchanged: the document root |
config.mapStyle | style.basemap (renamed) |
config.center / zoom / pitch / bearing | style.center / zoom / pitch / bearing |
config.bounds / minZoom / maxZoom / maxBounds / minPitch / maxPitch | runtime.map.* |
config.locale | runtime.map.locale |
config.fitTo | runtime.fitTo |
config.interactive / scrollZoom / boxZoom / dragRotate / dragPan / keyboard / … | runtime.map.* |
config.hash / attributionControl / logoPosition / trackResize | runtime.map.* |
top-level sources | style.sources |
source refresh / stream / cache / loading | source runtime.* |
source format / load / columns / colorRamp | source runtime.* |
top-level layers | style.layers |
layer classify / before | unchanged: on the layer |
layer interactive / legend / label / toggleable / effect | layer runtime.* |
top-level images / terrain / sky / light / projection | style.* |
top-level markers / popups | runtime.markers / runtime.popups |
top-level controls | runtime.controls |
top-level legend | runtime.legend |
block style: / className: | runtime.container.style / runtime.container.className |
top-level state | style.state (or document root) |
top-level parameters | runtime.parameters (or document root) |
Every v2 key is in the map document (format v2) reference.
The two halves
Section titled “The two halves”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’smapStyle, and it takes the same forms, including a Protomaps basemap from one.pmtilesfile (basemap: data/nyc.pmtiles, orbasemap: { pmtiles: data/nyc.pmtiles, flavor: dark }).- the camera:
center,zoom,pitch,bearing, at thestyle: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 withglobal-state, and optionalmetadata.images,terrain,sky,light,projection: the style’s root properties, as in v1.
The runtime: half: behaviour
Section titled “The runtime: half: behaviour”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: MapLibreMapoptions (minZoom,maxZoom,scrollZoom,interactive,bounds,maxBounds,locale, and the rest).fitTo: frame the map on a source’s data when it loads.markersandpopups: map-level markers and popups.controls: navigation, scale, geolocate, fullscreen, attribution.legend: the map’s legend.parameters: labels and ranges for yourstatekeys, which a control needs but a style has nowhere to put.container: the map element’s ownstyleandclassName.
version: 2type: mapid: chrome-demostyle: 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: 2type: mapid: live-quakesstyle: 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: 2type: mapid: interactive-quakesstyle: 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: titlestate: and parameters:
Section titled “state: and parameters:”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: 2type: mapid: parameterizedstyle: 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.
Troubleshooting
Section titled “Troubleshooting”A v1 key in a v2 document gets a warning
Section titled “A v1 key in a v2 document gets a warning”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?
My editor underlines a v2 document
Section titled “My editor underlines a v2 document”The published JSON Schemas describe format v1. Leave the schema modeline
out of a v2 file and check it with mlym validate
(Editor setup).
Next steps
Section titled “Next steps”- Export to style.json: what you do with the style half.
- Live data: the keys that go under a source’s
runtime:. - Layers & styling: paint, layout and filters, the same in v1 and v2.
- Map document (format v2) reference: every v2 key.