diff --git a/plugin-designs/pplr-data-maps/src/utils/pplrData.js b/plugin-designs/pplr-data-maps/src/utils/pplrData.js index d8502ee6e..93ca5116c 100644 --- a/plugin-designs/pplr-data-maps/src/utils/pplrData.js +++ b/plugin-designs/pplr-data-maps/src/utils/pplrData.js @@ -63,6 +63,29 @@ export function ensureGeocoder(provider = 'mapbox') { // `new mapboxgl.Popup` throws on the first pin click. Now the library's engineFor (one copy). export { engineFor as glFor } from '@map/composables/useMapProvider.js' +// Resolves once every GeoJSON source on the map has LOADED and a frame has RENDERED after that, +// or after `timeoutMs` (a safety net, never a hang). The views flipped `dataReady` (which hides the +// LoadingGlobe) right after addSource(); the engine then still tiles tens of thousands of points in +// its worker, so the globe disappeared and the map sat EMPTY. Measured on the DX-life gallery: 0 +// dots for 20 s, then 19,376 features from 30 s. Not 'idle': an animating map may never go idle. +export function whenGeojsonDrawn(map, timeoutMs = 45000) { + return new Promise((resolve) => { + if (!map) return resolve(false) + let done = false + const finish = (drawn) => { if (done) return; done = true; clearTimeout(timer); map.off('sourcedata', check); resolve(drawn) } + const timer = setTimeout(() => finish(false), timeoutMs) + const check = () => { + try { + const srcs = (map.getStyle() || {}).sources || {} + const ids = Object.keys(srcs).filter((k) => srcs[k].type === 'geojson') + if (ids.every((id) => map.isSourceLoaded(id))) { map.once('render', () => finish(true)); map.triggerRepaint() } + } catch (_) { /* style mid-swap: wait for the next sourcedata */ } + } + map.on('sourcedata', check) + check() + }) +} + // Verification handle (the gospel-resources __grState contract): what the ACTIVE view's map // actually did, so a check can assert "loaded" rather than inferring it from missing requests. // window.__pplrMap() -> { engine, loaded, styleLayers, pplrLayers } diff --git a/plugin-designs/pplr-data-maps/src/views/pplr-coverage.vue b/plugin-designs/pplr-data-maps/src/views/pplr-coverage.vue index 7ace113fc..e6f6287ed 100644 --- a/plugin-designs/pplr-data-maps/src/views/pplr-coverage.vue +++ b/plugin-designs/pplr-data-maps/src/views/pplr-coverage.vue @@ -1,5 +1,5 @@