Skip to content

Commit

Permalink
Sort tiles to load before triggering fetch (#723)
Browse files Browse the repository at this point in the history
* Remove check if a tile has renderable content before loading root sibling tiles

* Add queued tiles callback
  • Loading branch information
gkjohnson authored Aug 27, 2024
1 parent 6bd0172 commit cd73310
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/base/TilesRendererBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class TilesRendererBase {
this.rootURL = url;
this.fetchOptions = {};
this.plugins = [];
this.queuedTiles = [];

this._preprocessURL = null;

Expand Down Expand Up @@ -146,6 +147,7 @@ export class TilesRendererBase {

}

// Plugins
registerPlugin( plugin ) {

if ( plugin[ PLUGIN_REGISTERED ] === true ) {
Expand Down Expand Up @@ -183,6 +185,12 @@ export class TilesRendererBase {

}

queueTileForDownload( tile ) {

this.queuedTiles.push( tile );

}

// Public API
update() {

Expand Down Expand Up @@ -212,6 +220,20 @@ export class TilesRendererBase {
markVisibleTiles( root, this );
toggleTiles( root, this );

// TODO: This will only sort for one tile set. We may want to store this queue on the
// LRUCache so multiple tile sets can use it at once
// start the downloads of the tiles as needed
const queuedTiles = this.queuedTiles;
queuedTiles.sort( lruCache.unloadPriorityCallback );
for ( let i = 0, l = queuedTiles.length; i < l && ! lruCache.isFull(); i ++ ) {

this.requestTileContents( queuedTiles[ i ] );

}

queuedTiles.length = 0;

// start the downloads
lruCache.scheduleUnload();

}
Expand Down
6 changes: 3 additions & 3 deletions src/base/traverseFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function recursivelyLoadNextRenderableTiles( tile, renderer ) {

} else {

renderer.requestTileContents( tile );
renderer.queueTileForDownload( tile );

}

Expand Down Expand Up @@ -306,7 +306,7 @@ export function markVisibleTiles( tile, renderer ) {

} else if ( ! lruCache.isFull() && tile.__hasContent ) {

renderer.requestTileContents( tile );
renderer.queueTileForDownload( tile );

}

Expand All @@ -329,7 +329,7 @@ export function markVisibleTiles( tile, renderer ) {
const includeTile = meetsSSE || tile.refine === 'ADD';
if ( includeTile && ! loadedContent && ! lruCache.isFull() && hasContent ) {

renderer.requestTileContents( tile );
renderer.queueTileForDownload( tile );

}

Expand Down

0 comments on commit cd73310

Please sign in to comment.