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.
map.on( 'sourcedata' , function (e) { if (e.isSourceLoaded) { … } })
Key points
- dataType is 'source' for source changes and 'style' for style changes.
- isSourceLoaded true means the named source has no pending tiles.
- The idle event fires once rendering and network requests settle.
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
- The data event fires repeatedly per frame, so debounce expensive handlers.
- Querying features before isSourceLoaded can miss tiles still in flight.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). MapDataEvent. https://www.jingweizhi.com/en/maplibre/api/map-data-event.html (accessed 2026-11-03).