@@ -150,6 +150,7 @@ export class ImageOverlayPlugin {
150150 this . usedTextures = new Set ( ) ;
151151 this . meshParams = new WeakMap ( ) ;
152152 this . pendingTiles = new Map ( ) ;
153+ this . processedTiles = new Set ( ) ;
153154 this . processQueue = null ;
154155 this . _onUpdateAfter = null ;
155156 this . _onTileDownloadStart = null ;
@@ -284,9 +285,15 @@ export class ImageOverlayPlugin {
284285
285286 } ;
286287
287- this . _onTileDownloadStart = ( { tile } ) => {
288+ this . _onTileDownloadStart = ( { tile, url } ) => {
288289
289- this . _initTileOverlayInfo ( tile ) ;
290+ // TODO: it would be better if there were either a separate event or flag indicating that a tile is an external
291+ // tileset or not. We won't want to run "init" on tiles that have geometry.
292+ if ( ! / \. j s o n $ / . test ( url ) ) {
293+
294+ this . _initTileOverlayInfo ( tile ) ;
295+
296+ }
290297
291298 } ;
292299
@@ -303,7 +310,9 @@ export class ImageOverlayPlugin {
303310
304311 disposeTile ( tile ) {
305312
306- const { overlayInfo, tileControllers, processQueue, pendingTiles } = this ;
313+ const { overlayInfo, tileControllers, processQueue, pendingTiles, processedTiles } = this ;
314+
315+ processedTiles . delete ( tile ) ;
307316
308317 // Cancel any ongoing tasks. If a tile is cancelled while downloading
309318 // this will not have been created, yet.
@@ -401,25 +410,30 @@ export class ImageOverlayPlugin {
401410
402411 async _processTileModel ( scene , tile , initialization = false ) {
403412
404- this . tileControllers . set ( tile , new AbortController ( ) ) ;
413+ const { tileControllers, processedTiles, pendingTiles } = this ;
414+
415+ tileControllers . set ( tile , new AbortController ( ) ) ;
405416
406417 if ( ! initialization ) {
407418
408419 // we save all these pending tiles so that they can be correctly initialized if an
409420 // overlay is added in the time between when this function starts and after the async
410421 // await call. Otherwise the tile could be missed. But if we're initializing the plugin
411422 // then we don't need to do this because the tiles are already included in the traversal.
412- this . pendingTiles . set ( tile , scene ) ;
423+ pendingTiles . set ( tile , scene ) ;
413424
414425 }
415426
427+ // track which tiles we have been processed and remove them in "disposeTile"
428+ processedTiles . add ( tile ) ;
429+
416430 this . _wrapMaterials ( scene ) ;
417431 this . _initTileOverlayInfo ( tile ) ;
418432 await this . _initTileSceneOverlayInfo ( scene , tile ) ;
419433 this . expandVirtualChildren ( scene , tile ) ;
420434 this . _updateLayers ( tile ) ;
421435
422- this . pendingTiles . delete ( tile ) ;
436+ pendingTiles . delete ( tile ) ;
423437
424438 }
425439
@@ -887,13 +901,23 @@ export class ImageOverlayPlugin {
887901
888902 deleteOverlay ( overlay ) {
889903
890- const { overlays, overlayInfo, processQueue } = this ;
904+ const { overlays, overlayInfo, processQueue, processedTiles } = this ;
891905 const index = overlays . indexOf ( overlay ) ;
892906 if ( index !== - 1 ) {
893907
894908 // delete tile info explicitly instead of blindly dispose of the full overlay
895909 const { tileInfo, controller } = overlayInfo . get ( overlay ) ;
896- tileInfo . forEach ( ( { meshInfo, range, meshRange, level, target, meshRangeMarked, rangeMarked } , tile ) => {
910+ processedTiles . forEach ( tile => {
911+
912+ const {
913+ meshInfo,
914+ range,
915+ meshRange,
916+ level,
917+ target,
918+ meshRangeMarked,
919+ rangeMarked,
920+ } = tileInfo . get ( tile ) ;
897921
898922 // release the ranges
899923 if ( meshRange !== null && meshRangeMarked ) {
0 commit comments