mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL

Home Page:https://docs.mapbox.com/mapbox-gl-js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

mikejamesthompson opened this issue · comments

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.