mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.11k stars 2.21k forks source link

Change in `MapDataEvent.isSourceLoaded` behaviour in >= v3.0.0 #13185

Closed mikejamesthompson closed 1 month ago

mikejamesthompson commented 4 months ago

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.

Jamie5 commented 1 month ago

Is this addressed by 3.6 via https://github.com/mapbox/mapbox-gl-js/commit/5e8ca3275fa6875aa2a58c38b78112fa63e756de ? (I think we ran into the same issue as you so might try upgrading to 3.6 to see if it helps)

mikejamesthompson commented 1 month ago

Is this addressed by 3.6 via 5e8ca32 ? (I think we ran into the same issue as you so might try upgrading to 3.6 to see if it helps)

Thanks for this.

I've added 3.6.0 to that demo application and that confirms that the issue has been fixed: https://mb-sourcedata.surge.sh