Atlaslog
Atlaslog / MapLibre GL JS / API reference / MapDataEvent
MapLibre GL JS · API reference

MapDataEvent

Quick answer

MapDataEvent is the event object delivered for data, sourcedata and styledata on a Map. Its dataType says whether style or source data changed, and isSourceLoaded marks a source that finished loading tiles. Listen for it to know when the map is safe to query, export or fit bounds against.

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
map.on( 'sourcedata' , function (e) { if (e.isSourceLoaded) { … } })
Key points
Example
var pending = {};

map.on('sourcedata', function (e) {
  if (e.dataType !== 'source') return;

  var id = e.sourceId;
  if (e.sourceDataType === 'metadata') {
    pending[id] = true;
  }

  if (e.isSourceLoaded) {
    delete pending[id];
    document.getElementById('loading').textContent =
      Object.keys(pending).length === 0 ? '底图就绪' : '仍在加载 ' + Object.keys(pending).join('、');
  }
});

map.on('styledata', function () {
  /* 样式变化时图层可能被重置,重新同步图例 */
  refreshLegend();
});

map.on('idle', function () {
  document.getElementById('loading').hidden = true;
});
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). MapDataEvent. https://www.jingweizhi.com/en/maplibre/api/map-data-event.html (accessed 2026-11-03).