Skip to content

Commit 009b40a

Browse files
authored
ImageOverlay: Respect abort signals (#1625)
* Respect abort signals * Add comment
1 parent 51ba5b7 commit 009b40a

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/three/plugins/images/ImageOverlayPlugin.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,15 @@ export class ImageOverlay {
14281428

14291429
}
14301430

1431-
return this.downloadQueue.add( { priority: - performance.now() }, () => fetch( url, options ) );
1431+
const item = { priority: - performance.now() };
1432+
const promise = this.downloadQueue.add( item, () => fetch( url, options ) );
1433+
if ( options.signal ) {
1434+
1435+
options.signal.addEventListener( 'abort', () => this.downloadQueue.remove( item ), { once: true } );
1436+
1437+
}
1438+
1439+
return promise;
14321440

14331441
}
14341442

@@ -2102,7 +2110,16 @@ export class CesiumIonOverlay extends TiledImageOverlay {
21022110

21032111
}
21042112

2105-
return this.downloadQueue.add( { priority: - performance.now() }, () => this.auth.fetch( url, options ) );
2113+
// TODO: we should provide a better way to sort these
2114+
const item = { priority: - performance.now() };
2115+
const promise = this.downloadQueue.add( item, () => this.auth.fetch( url, options ) );
2116+
if ( options.signal ) {
2117+
2118+
options.signal.addEventListener( 'abort', () => this.downloadQueue.remove( item ), { once: true } );
2119+
2120+
}
2121+
2122+
return promise;
21062123

21072124
}
21082125

@@ -2176,7 +2193,15 @@ export class GoogleMapsOverlay extends TiledImageOverlay {
21762193

21772194
}
21782195

2179-
return this.downloadQueue.add( { priority: - performance.now() }, () => this.auth.fetch( url, options ) );
2196+
const item = { priority: - performance.now() };
2197+
const promise = this.downloadQueue.add( item, () => this.auth.fetch( url, options ) );
2198+
if ( options.signal ) {
2199+
2200+
options.signal.addEventListener( 'abort', () => this.downloadQueue.remove( item ), { once: true } );
2201+
2202+
}
2203+
2204+
return promise;
21802205

21812206
}
21822207

src/three/plugins/images/sources/MVTImageSource.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class MVTImageSource extends RegionImageSource {
182182

183183
}
184184

185-
async fetchItem( [ minX, minY, maxX, maxY, level ], _signal ) {
185+
async fetchItem( [ minX, minY, maxX, maxY, level ], signal ) {
186186

187187
const { resolution, _contentCache } = this;
188188
const canvas = document.createElement( 'canvas' );
@@ -200,6 +200,12 @@ export class MVTImageSource extends RegionImageSource {
200200

201201
await Promise.all( promises );
202202

203+
if ( signal && signal.aborted ) {
204+
205+
return null;
206+
207+
}
208+
203209
this._drawToCanvas( canvas, regionBounds, level );
204210

205211
const tex = new CanvasTexture( canvas );

src/three/plugins/images/sources/RegionImageSource.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export class TiledRegionImageSource extends RegionImageSource {
7373
// lock tiles for the requested level
7474
await this._markImages( range, level, false );
7575

76-
//
76+
if ( signal && signal.aborted ) {
77+
78+
return null;
79+
80+
}
7781

7882
// Fast path: if the range maps to exactly one tile with matching bounds, use its
7983
// texture directly without compositing into an intermediate canvas to save memory.

0 commit comments

Comments
 (0)