Skip to content

Commit

Permalink
Track the number of tiles loading since loading had finished previous…
Browse files Browse the repository at this point in the history
…ly (#920)

* Track the number of tiles loading since loading had finished previously

* Update names

* Add "loadPercent"

* loadPercent -> loadProgress
  • Loading branch information
gkjohnson authored Jan 13, 2025
1 parent 4ffa13b commit dc8d203
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,6 @@ If true then the `raycast` functions of the loaded tile objects are overriden to
If you would like to manage raycasting against tiles yourself this behavior can be disabled if needed by setting `optizeRaycast` to false.
### .preprocessURL
```js
preprocessURL = null : ( uri : string | URL ) => string | URL;
```
Function to preprocess the url for each individual tile geometry or child tile set to be loaded. If null then the url is used directly.
### .lruCache
```js
Expand Down Expand Up @@ -446,6 +438,14 @@ manager : LoadingManager
The manager used when loading tile geometry.
### .loadProgress
```js
readOnly loadProgress : Number
```
Returns the total load progress between `[0, 1]`. Progress is measured since the last set of loading tiles completed.
### .constructor
```js
Expand Down
34 changes: 26 additions & 8 deletions src/base/TilesRendererBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ export class TilesRendererBase {

}

set loadSiblings( v ) {
get loadProgress() {

console.warn( 'TilesRenderer: "loadSiblings" option has been removed.' );

}

set stopAtEmptyTiles( v ) {

console.warn( 'TilesRenderer: "stopAtEmptyTiles" option has been removed.' );
const stats = this.stats;
const loading = stats.downloading + stats.parsing;
const total = stats.inCacheSinceLoad;
return total === 0 ? 1.0 : 1.0 - loading / total;

}

Expand All @@ -108,6 +105,7 @@ export class TilesRendererBase {
this.fetchOptions = {};
this.plugins = [];
this.queuedTiles = [];
this.cachedSinceLoadComplete = new Set();

const lruCache = new LRUCache();
lruCache.unloadPriorityCallback = lruPriorityCallback;
Expand All @@ -125,6 +123,7 @@ export class TilesRendererBase {
this.downloadQueue = downloadQueue;
this.parseQueue = parseQueue;
this.stats = {
inCacheSinceLoad: 0,
inCache: 0,
parsing: 0,
downloading: 0,
Expand Down Expand Up @@ -642,6 +641,13 @@ export class TilesRendererBase {

// Decrement stats
stats.inCache --;
if ( this.cachedSinceLoadComplete.has( tile ) ) {

this.cachedSinceLoadComplete.delete( tile );
stats.inCacheSinceLoad --;

}

if ( t.__loadingState === LOADING ) {

stats.downloading --;
Expand All @@ -666,6 +672,8 @@ export class TilesRendererBase {

}

this.cachedSinceLoadComplete.add( tile );
stats.inCacheSinceLoad ++;
stats.inCache ++;
stats.downloading ++;
tile.__loadingState = LOADING;
Expand Down Expand Up @@ -809,6 +817,16 @@ export class TilesRendererBase {

}

} )
.finally( () => {

if ( stats.parsing === 0 && stats.downloading === 0 ) {

this.cachedSinceLoadComplete.clear();
stats.inCacheSinceLoad = 0;

}

} );

}
Expand Down

0 comments on commit dc8d203

Please sign in to comment.