MapLibre examples in YAML
The MapLibre GL JS examples are the standard set of small web-map recipes. This gallery rebuilds them as maplibre-yaml documents: each page runs the example live and shows the YAML that draws it, ready to copy. Use it to look up one technique. For a guided start, see the examples overview.
MapLibre's gallery has 139 examples, and 104 of them have a page here: 79 in YAML alone and 25 with some page JavaScript. The rest are listed, folded, under each group, with what you would write instead. The gallery also has 4 pages of its own: files read straight from a web server, and two Mapzen classics.
Start here
Section titled “Start here”How to read a page
Section titled “How to read a page”Every gallery page has the same parts:
- A link to the MapLibre original, and what the YAML version does differently.
- The map, running live.
- The complete document: the YAML file the map above loads, exactly as it runs.
- What to notice: the lines that do the work.
- Use this map: how to put it on your own page, and the guide and reference for what it uses.
The badge next to each example says what you write:
- YAML One YAML document and nothing else.
- YAML + JavaScript A YAML document plus a
few lines of page JavaScript, for the part that is behaviour rather than a
description of the map, such as a button that moves the camera. These
pages show three parts in place of the complete document: the YAML, the
page HTML that goes inside the
<ml-map>element (an element with aslotattribute sits in a corner of the map), and the JavaScript. The JavaScript gets the map from the element’smapReady()method. - JavaScript Work that belongs in MapLibre code rather than a map document, such as a game loop or a 3D Tiles renderer. These have no page here; follow the link to the MapLibre example.
Find an example
Section titled “Find an example”Map basics
Section titled “Map basics”| Example | You write |
|---|---|
| Display a map | YAML |
| Display a satellite map | YAML |
| Display a non-interactive map | YAML |
| Change the default position for attribution | YAML |
| Display a map with MLT | YAML |
MapLibre examples in this group without a page here (1)
| MapLibre example | You write |
|---|---|
Check if WebGL is supported · <ml-map> already shows an error card when the map can't start, and fires ml-map:error; a listener for it replaces the upstream alert. The event doesn't say whether missing WebGL was the cause. | YAML + JavaScript |
No examples in this group match.
Camera & animation
Section titled “Camera & animation”| Example | You write |
|---|---|
| Fly to a location | YAML + JavaScript |
| Jump to a series of locations | YAML + JavaScript |
| Set pitch and bearing | YAML |
| Slowly fly to a location | YAML + JavaScript |
| Animate a line | YAML + JavaScript |
| Animate a point | YAML + JavaScript |
| Animate a point along a route | YAML + JavaScript |
| Animate map camera around a point | YAML + JavaScript |
| Customize camera animations | YAML + JavaScript |
| Fit a map to a bounding box | YAML |
| Fit to the bounds of a LineString | YAML |
Fly to a location based on scroll position · A story map: a type: scrollytelling document. | YAML |
| Hash routing | YAML |
| Offset the vanishing point using padding | YAML + JavaScript |
| Render world copies | YAML |
| Restrict map panning to an area | YAML |
| Set center point above ground | YAML |
MapLibre examples in this group without a page here (4)
| MapLibre example | You write |
|---|---|
Customize the map transform constrain · The constrain function is page code: call setTransformConstrain() on the map from mapReady() (maplibre-gl 5.10 or later). The zoom below 0 is set from the same code, because a document's zoom starts at 0. | YAML + JavaScript |
| Enter a 360° photosphere · A photosphere plugin, and a pitch of 175°; a document's pitch stops at 85°. | JavaScript |
Level of detail control · Sliders from parameters: fire ml-map:parameter-change; its listener makes one setSourceTileLodParams() call. | YAML + JavaScript |
| Walk around a map in first person · A game loop that moves the camera every frame, at a pitch of 90°; a document's pitch stops at 85°. | JavaScript |
No examples in this group match.
Controls & gestures
Section titled “Controls & gestures”| Example | You write |
|---|---|
| Display map navigation controls | YAML |
| Locate the user | YAML |
| Cooperative gestures | YAML |
| Disable map rotation | YAML |
| Disable scroll zoom | YAML |
| Toggle interactions | YAML + JavaScript |
| View a fullscreen map | YAML |
MapLibre examples in this group without a page here (1)
| MapLibre example | You write |
|---|---|
Navigate the map with game-like controls · interactive: false is YAML; the arrow keys call panBy and easeTo from mapReady(), the same camera code as Fly to a location. | YAML + JavaScript |
No examples in this group match.
Sources & data
Section titled “Sources & data”| Example | You write |
|---|---|
| Add a vector tile source | YAML |
| Add a GeoJSON line | YAML |
| Add a GeoJSON polygon | YAML |
| Draw GeoJSON points | YAML |
| Add multiple geometries from one GeoJSON source | YAML |
| Display line that crosses 180th meridian | YAML |
| Add a raster tile source | YAML |
| Add a WMS source | YAML |
| Add a canvas source | YAML + JavaScript |
| Add a COG raster source · Imagery, hillshade and 3D terrain from Cloud Optimized GeoTIFFs. | YAML |
| Add a video | YAML |
| Animate a series of images | YAML + JavaScript |
| Add live realtime data | YAML |
| Update a feature in realtime | YAML |
| Update GeoJSON polygons | YAML + JavaScript |
MapLibre examples in this group without a page here (2)
| MapLibre example | You write |
|---|---|
View local GeoJSON · The YAML declares an empty GeoJSON source and its fill layer; a file input in a corner slot hands the file it reads to updateLayerData(). | YAML + JavaScript |
| View local GeoJSON (experimental) · The same page code as View local GeoJSON, with the browser's file system picker (Chromium only). | YAML + JavaScript |
No examples in this group match.
Layers, icons & styling
Section titled “Layers, icons & styling”| Example | You write |
|---|---|
| Add an icon to the map | YAML |
| Add a generated icon to the map | YAML + JavaScript |
| Add a stretchable image to the map | YAML + JavaScript |
| Add an animated icon to the map | YAML + JavaScript |
| Display a remote SVG symbol | YAML |
Elevate symbols above the terrain · symbol-height-offset (maplibre-gl 6.6 or later). | YAML |
| Generate and add a missing icon to the map | YAML + JavaScript |
| Use a fallback image | YAML |
| Change a layer's color with buttons | YAML |
| Add a new layer below labels | YAML |
| Add a pattern to a polygon | YAML |
| Create a heatmap layer | YAML |
| Create and style clusters · Clustered points with counts; click a cluster to zoom in. | YAML |
| Display and style rich text labels | YAML |
| Style labels with web fonts | YAML |
Style labels with font faces · font-faces in an inline mapStyle (maplibre-gl 6.7 or later). | YAML |
| Change the case of labels | YAML |
| Style labels with local fonts | YAML |
| Variable label placement | YAML |
| Variable label placement with offset | YAML |
MapLibre examples in this group without a page here (3)
| MapLibre example | You write |
|---|---|
Animate an icon on the GPU · The YAML holds the point source and the symbol layer that names the icon; addImage() registers the WebGL-drawn icon from mapReady() (maplibre-gl 6.3 or later). | YAML + JavaScript |
Add a custom style layer · addLayer({ type: 'custom' }) from mapReady(), with MercatorCoordinate imported from @maplibre-yaml/core/maplibre. | YAML + JavaScript |
Display HTML clusters with custom properties · The clustered source, its clusterProperties and the unclustered layers are YAML; the SVG donut markers are page code, using Marker from @maplibre-yaml/core/maplibre. | YAML + JavaScript |
No examples in this group match.
Expressions & data-driven styling
Section titled “Expressions & data-driven styling”| Example | You write |
|---|---|
| Style lines with a data-driven property | YAML |
| Change building color based on zoom level | YAML |
| Create a gradient dashed line using an expression | YAML |
| Create a gradient line using an expression | YAML |
| Filter within a layer | YAML + JavaScript |
| Filter symbols by text input | YAML + JavaScript |
| Filter layer symbols using global state | YAML |
| Filter symbols by toggling a list | YAML |
| Visualize population density | YAML |
| Create a time slider | YAML |
| Draw a circle | YAML + JavaScript |
MapLibre examples in this group without a page here (1)
| MapLibre example | You write |
|---|---|
Measure distances · The YAML declares the source and its layers; map clicks call updateLayerData(), and the distance shows in a corner slot. | YAML + JavaScript |
No examples in this group match.
Terrain, 3D & globe
Section titled “Terrain, 3D & globe”| Example | You write |
|---|---|
| 3D terrain | YAML |
| Add a hillshade layer | YAML |
| Add a color relief layer | YAML |
| Add a multidirectional hillshade layer · maplibre-gl 5.5 or later. | YAML |
| Add contour lines | YAML + JavaScript |
| Display a hybrid satellite map with terrain elevation | YAML |
| Sky, fog and terrain | YAML |
| Display buildings in 3D | YAML |
| Extrude polygons for 3D indoor mapping | YAML |
Fill-extrusion rounded corners · Height and opacity sliders from parameters: (maplibre-gl 6.2 or later). | YAML |
| Display a globe with a vector map | YAML |
| Display a globe with an atmosphere | YAML |
| Create a heatmap layer on a globe with terrain elevation | YAML |
| Display a globe with a fill extrusion layer | YAML |
MapLibre examples in this group without a page here (10)
| MapLibre example | You write |
|---|---|
| Add 3D terrain from quantized mesh tiles · Reads the mesh tiles through a third-party plugin set up in page code. | YAML + JavaScript |
Add a 3D model using three.js · A three.js custom layer, added with addLayer() from mapReady() as in Add a custom style layer. | YAML + JavaScript |
| Add 3D tiles using three.js · Streams OGC 3D Tiles with a dedicated renderer and its decoders. | JavaScript |
| Add a 3D model to globe using three.js · A three.js model placed with the globe projection's own matrices. | JavaScript |
Add a 3D model with babylon.js · A babylon.js custom layer, added with addLayer() from mapReady() as in Add a custom style layer. | YAML + JavaScript |
Add a 3D model with shadow using three.js · A three.js custom layer with a shadow, added with addLayer() from mapReady(). | YAML + JavaScript |
Adding 3D models using three.js on terrain · A three.js custom layer over terrain:, added with addLayer() from mapReady(). | YAML + JavaScript |
| Add a custom layer with tiles to a globe · A tile renderer that reads MapLibre's internal projection state. | JavaScript |
Add a simple custom layer on a globe · The Add a custom style layer code on a projection: globe map. | YAML + JavaScript |
Zoom and planet size relation on globe · projection: globe is YAML; a button in a corner slot calls flyTo with the zoom adjusted for latitude. | YAML + JavaScript |
No examples in this group match.
Markers & popups
Section titled “Markers & popups”| Example | You write |
|---|---|
| Add a default marker | YAML |
| Add custom icons with markers | YAML |
| Display a popup | YAML |
| Display a popup on click | YAML |
| Display a popup on hover | YAML |
| Attach a popup to a marker instance | YAML |
MapLibre examples in this group without a page here (3)
| MapLibre example | You write |
|---|---|
Create a draggable marker · new Marker({ draggable: true }), with Marker from @maplibre-yaml/core/maplibre, added from mapReady(). | YAML + JavaScript |
Animate a marker · An animation loop moves a Marker from @maplibre-yaml/core/maplibre; markers declared in YAML can't be moved from code. | YAML + JavaScript |
Create a draggable point · Layer mousedown and mousemove handlers, added from mapReady(), call updateLayerData(); the coordinates show in a corner slot. | YAML + JavaScript |
No examples in this group match.
Internationalization
Section titled “Internationalization”| Example | You write |
|---|---|
| Change a map's language | YAML + JavaScript |
| Use locally generated ideographs | YAML |
MapLibre examples in this group without a page here (1)
| MapLibre example | You write |
|---|---|
Locale switching · config.locale sets the controls' text, and controls.fullscreen takes a position. | YAML |
No examples in this group match.
Events & user interaction
Section titled “Events & user interaction”| Example | You write |
|---|---|
| Get features under the mouse pointer | YAML + JavaScript |
| Create a hover effect | YAML |
| Center the map on a clicked symbol | YAML |
| Get coordinates of the mouse pointer | YAML + JavaScript |
| Show polygon information on click | YAML |
MapLibre examples in this group without a page here (3)
| MapLibre example | You write |
|---|---|
Animate symbol to follow the mouse · projection: globe and controls.globe are YAML; a mousemove handler calls updateLayerData(). | YAML + JavaScript |
Display performance metrics · A panel in a corner slot, updated from ml-map:load and the map's idle and render events. | YAML + JavaScript |
Select features with boxzoomend callback · boxZoomEnd is a callback MapLibre takes only when the map is created, and a document holds data, not functions. | JavaScript |
No examples in this group match.
Plugins, protocols & integrations
Section titled “Plugins, protocols & integrations”| Example | You write |
|---|---|
PMTiles source and protocol · A .pmtiles file or pmtiles:// URL, with no page JavaScript. | YAML |
| Use addProtocol to transform feature properties | YAML + JavaScript |
MapLibre examples in this group without a page here (6)
| MapLibre example | You write |
|---|---|
Geocode with Nominatim · The geocoder takes its maplibregl from @maplibre-yaml/core/maplibre and is added with addControl() from mapReady(). | YAML + JavaScript |
Create deck.gl layer using REST API · deck.gl's MapboxOverlay is a control: add it with addControl() from mapReady(). | YAML + JavaScript |
Draw geometries with Terra Draw · A plugin control added with addControl() from mapReady(). | YAML + JavaScript |
Draw polygon with mapbox-gl-draw · A plugin control added with addControl() from mapReady(); the area shows in a corner slot. | YAML + JavaScript |
Sync movement of multiple maps · Three <ml-map> elements; wait for each one's mapReady(), then hand the maps to the sync plugin. | YAML + JavaScript |
| Toggle deck.gl layer · The Create deck.gl layer code plus a show/hide button. | YAML + JavaScript |
No examples in this group match.
Cloud-native data
Section titled “Cloud-native data”Not in MapLibre’s gallery: data files read in parts, straight from a web server, with no tile server and no page JavaScript. How they work and how to host them: Large data.
| Example | You write |
|---|---|
FlatGeobuf source · A .fgb file as a GeoJSON source, with popups, a legend and fitTo. | YAML |
GeoParquet source · A .parquet file as a GeoJSON source, with classify:, popups, fitTo and reading by view. | YAML |
No examples in this group match.
Mapzen classics
Section titled “Mapzen classics”Not in MapLibre’s gallery: two looks from the Mapzen Tangram era, rebuilt in
plain style properties. Mapzen classics runs them with
experimental effects, next to their exported style.json.
| Example | You write |
|---|---|
| Crosshatch · After Tangram's crosshatch style. | YAML |
| Blueprint · A blueprint look in plain style properties. | YAML |
No examples in this group match.