Atlaslog
Atlaslog / MapLibre GL JS / Tutorial / GeoJSON sources
MapLibre GL JS · Tutorial

GeoJSON sources

Quick answer

This tutorial covers adding GeoJSON through addSource with either an inline object or a URL, choosing a layer type per geometry, and refreshing data with setData instead of rebuilding layers. It also explains client-side clustering via cluster, clusterRadius and clusterMaxZoom, feature-state highlighting with promoteId or generateId, and click queries on layers. You will be able to load business data and update it in place.

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
Key points
Example
/* 内联对象 */
map.addSource('stations', {
  type: 'geojson',
  data: {
    type: 'FeatureCollection',
    features: [
      { type: 'Feature', properties: { name: 'A' },
        geometry: { type: 'Point', coordinates: [116.39, 39.90] } }
    ]
  }
});

/* 远程文件 */
map.addSource('zones', {
  type: 'geojson',
  data: '/data/zones.geojson'
});
map.addLayer({
  id: 'station-dots',
  type: 'circle',
  source: 'stations',
  paint: {
    'circle-radius': ['interpolate', ['linear'], ['zoom'], 3, 3, 7, 8],
    'circle-color': '#1f5fd0',
    'circle-stroke-color': '#fff',
    'circle-stroke-width': 1.5
  }
});
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). GeoJSON sources. https://www.jingweizhi.com/en/maplibre/tutorials/geojson-source.html (accessed 2026-11-03).