Atlaslog
Atlaslog / MapLibre GL JS / Tutorial / Styles and layers
MapLibre GL JS · Tutorial

Styles and layers

Quick answer

This tutorial walks through a style JSON built from version, sources, layers, glyphs and sprite, then explains the split between paint and layout properties, layer stacking with beforeId, and runtime edits via setPaintProperty, setLayoutProperty, removeLayer and setStyle. It covers source-layer names on vector tiles, filter expressions, and the diff option in v4. You will be able to assemble and modify a working style.

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
Key points
Example
{
  "version": 8,
  "sources": {
    "base": {
      "type": "vector",
      "url": "https://example.com/tiles.json"
    }
  },
  "layers": [
    { "id": "bg", "type": "background", "paint": { "background-color": "#eef3f7" } },
    {
      "id": "land",
      "type": "fill",
      "source": "base",
      "source-layer": "countries",
      "paint": { "fill-color": "#f7f4ec" }
    }
  ],
  "glyphs": "https://example.com/font/{fontstack}/{range}.pbf"
}
map.addLayer({
  id: 'route-line',
  type: 'line',
  source: 'route',
  layout: {
    'line-cap': 'round',
    'line-join': 'round'
  },
  paint: {
    'line-color': '#1f5fd0',
    'line-width': ['interpolate', ['linear'], ['zoom'], 3, 1.5, 8, 5],
    'line-dasharray': [2, 2]
  }
});
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Styles and layers. https://www.jingweizhi.com/en/maplibre/tutorials/style-layers.html (accessed 2026-11-03).