mapbox-gl-js
mapbox-gl-js copied to clipboard
Change in `MapDataEvent.isSourceLoaded` behaviour in >= v3.0.0
mapbox-gl-js version: >= 3
browser: Chrome 124, Firefox 124
Link to Demonstration
https://mb-sourcedata.surge.sh/
Expected Behavior
We use code like the following in our application to synchronise map feature state with application state when a new GeoJSON source has been loaded:
map.on('sourcedata', async (e) => {
if (e.isSourceLoaded && e.sourceId === 'our-source-id') {
await doStuffToMap();
}
});
We rely on there being a sourcedata
event fired where isSourceLoaded
is true and the features are available within the source in order to update the map feature state.
Actual Behavior
When migrating to version 3, we found that this approach no longer works: isSourceLoaded
never returns true for a sourcedata
event that isn't of type metadata
.
The link above is to a tiny application that logs these events for different versions of Mapbox and shows the different value of isSourceLoaded
returned for v2.15.0 when compared to v3.0.0
and v3.3.0
.