@@ -4781,29 +4781,34 @@ function createZarrLayerAddHandler(): ZarrLayerEventHandler {
47814781 } ;
47824782}
47834783
4784- // Names handed to addPMTilesLayerFromUrl, keyed by archive URL. The control's own `addLayer(url)`
4784+ // Names handed to addPMTilesLayerFromUrl, queued per archive URL. The control's own `addLayer(url)`
47854785// takes no name, so a caller that has a better one than the file name (a STAC item and its asset,
4786- // say) leaves it here for the `layeradd` that follows.
4787- const pendingPMTilesNames = new Map < string , string > ( ) ;
4786+ // say) leaves it here for the `layeradd` that follows. A queue rather than a single entry because
4787+ // two adds of the same archive would otherwise take each other's name.
4788+ const pendingPMTilesNames = new Map < string , { name : string } [ ] > ( ) ;
47884789
47894790/**
47904791 * @internal Exported only so the programmatic-name handoff can be unit-tested. Returns a disposer,
47914792 * so an add that never reaches `layeradd` (a broken archive) leaves nothing behind.
47924793 */
47934794export function setPendingPMTilesName ( url : string , name : string ) : ( ) => void {
4794- pendingPMTilesNames . set ( url , name ) ;
4795+ const queue = pendingPMTilesNames . get ( url ) ?? [ ] ;
4796+ const pending = { name } ;
4797+ queue . push ( pending ) ;
4798+ pendingPMTilesNames . set ( url , queue ) ;
47954799 return ( ) => {
4796- pendingPMTilesNames . delete ( url ) ;
4800+ const index = queue . indexOf ( pending ) ;
4801+ if ( index >= 0 ) queue . splice ( index , 1 ) ;
4802+ if ( queue . length === 0 ) pendingPMTilesNames . delete ( url ) ;
47974803 } ;
47984804}
47994805
48004806/** @internal Exported only so the programmatic-name handoff can be unit-tested. */
48014807export function resolvePMTilesLayerName ( layerInfo : PMTilesLayerInfo , id : string ) : string {
4802- const pending = pendingPMTilesNames . get ( layerInfo . url ) ;
4803- if ( pending !== undefined ) {
4804- pendingPMTilesNames . delete ( layerInfo . url ) ;
4805- return pending ;
4806- }
4808+ const queue = pendingPMTilesNames . get ( layerInfo . url ) ;
4809+ const pending = queue ?. shift ( ) ;
4810+ if ( queue ?. length === 0 ) pendingPMTilesNames . delete ( layerInfo . url ) ;
4811+ if ( pending ) return pending . name ;
48074812 return layerInfo . name || layerNameFromUrl ( layerInfo . url , id ) ;
48084813}
48094814
0 commit comments