Skip to content

Commit dc8d203

Browse files
authored
Track the number of tiles loading since loading had finished previously (#920)
* Track the number of tiles loading since loading had finished previously * Update names * Add "loadPercent" * loadPercent -> loadProgress
1 parent 4ffa13b commit dc8d203

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,6 @@ If true then the `raycast` functions of the loaded tile objects are overriden to
392392
393393
If you would like to manage raycasting against tiles yourself this behavior can be disabled if needed by setting `optizeRaycast` to false.
394394
395-
### .preprocessURL
396-
397-
```js
398-
preprocessURL = null : ( uri : string | URL ) => string | URL;
399-
```
400-
401-
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.
402-
403395
### .lruCache
404396
405397
```js
@@ -446,6 +438,14 @@ manager : LoadingManager
446438
447439
The manager used when loading tile geometry.
448440
441+
### .loadProgress
442+
443+
```js
444+
readOnly loadProgress : Number
445+
```
446+
447+
Returns the total load progress between `[0, 1]`. Progress is measured since the last set of loading tiles completed.
448+
449449
### .constructor
450450
451451
```js

src/base/TilesRendererBase.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,12 @@ export class TilesRendererBase {
8787

8888
}
8989

90-
set loadSiblings( v ) {
90+
get loadProgress() {
9191

92-
console.warn( 'TilesRenderer: "loadSiblings" option has been removed.' );
93-
94-
}
95-
96-
set stopAtEmptyTiles( v ) {
97-
98-
console.warn( 'TilesRenderer: "stopAtEmptyTiles" option has been removed.' );
92+
const stats = this.stats;
93+
const loading = stats.downloading + stats.parsing;
94+
const total = stats.inCacheSinceLoad;
95+
return total === 0 ? 1.0 : 1.0 - loading / total;
9996

10097
}
10198

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

112110
const lruCache = new LRUCache();
113111
lruCache.unloadPriorityCallback = lruPriorityCallback;
@@ -125,6 +123,7 @@ export class TilesRendererBase {
125123
this.downloadQueue = downloadQueue;
126124
this.parseQueue = parseQueue;
127125
this.stats = {
126+
inCacheSinceLoad: 0,
128127
inCache: 0,
129128
parsing: 0,
130129
downloading: 0,
@@ -642,6 +641,13 @@ export class TilesRendererBase {
642641

643642
// Decrement stats
644643
stats.inCache --;
644+
if ( this.cachedSinceLoadComplete.has( tile ) ) {
645+
646+
this.cachedSinceLoadComplete.delete( tile );
647+
stats.inCacheSinceLoad --;
648+
649+
}
650+
645651
if ( t.__loadingState === LOADING ) {
646652

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

667673
}
668674

675+
this.cachedSinceLoadComplete.add( tile );
676+
stats.inCacheSinceLoad ++;
669677
stats.inCache ++;
670678
stats.downloading ++;
671679
tile.__loadingState = LOADING;
@@ -809,6 +817,16 @@ export class TilesRendererBase {
809817

810818
}
811819

820+
} )
821+
.finally( () => {
822+
823+
if ( stats.parsing === 0 && stats.downloading === 0 ) {
824+
825+
this.cachedSinceLoadComplete.clear();
826+
stats.inCacheSinceLoad = 0;
827+
828+
}
829+
812830
} );
813831

814832
}

0 commit comments

Comments
 (0)