@loaders.gl/tiles 3.4.0-alpha.4 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/constants.d.ts +6 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +0 -1
  4. package/dist/dist.min.js +171 -151
  5. package/dist/es5/constants.js.map +1 -1
  6. package/dist/es5/tileset/helpers/3d-tiles-options.js.map +1 -1
  7. package/dist/es5/tileset/tile-3d.js +41 -71
  8. package/dist/es5/tileset/tile-3d.js.map +1 -1
  9. package/dist/es5/tileset/tileset-3d.js +68 -102
  10. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  11. package/dist/es5/tileset/tileset-cache.js +4 -7
  12. package/dist/es5/tileset/tileset-cache.js.map +1 -1
  13. package/dist/es5/tileset/tileset-traverser.js +12 -22
  14. package/dist/es5/tileset/tileset-traverser.js.map +1 -1
  15. package/dist/esm/constants.js.map +1 -1
  16. package/dist/esm/tileset/helpers/3d-tiles-options.js.map +1 -1
  17. package/dist/esm/tileset/tile-3d.js +39 -71
  18. package/dist/esm/tileset/tile-3d.js.map +1 -1
  19. package/dist/esm/tileset/tileset-3d.js +64 -94
  20. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  21. package/dist/esm/tileset/tileset-cache.js +4 -7
  22. package/dist/esm/tileset/tileset-cache.js.map +1 -1
  23. package/dist/esm/tileset/tileset-traverser.js +9 -19
  24. package/dist/esm/tileset/tileset-traverser.js.map +1 -1
  25. package/dist/tileset/helpers/3d-tiles-options.d.ts +3 -2
  26. package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -1
  27. package/dist/tileset/tile-3d.d.ts +36 -21
  28. package/dist/tileset/tile-3d.d.ts.map +1 -1
  29. package/dist/tileset/tile-3d.js +58 -43
  30. package/dist/tileset/tileset-3d.d.ts +90 -43
  31. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  32. package/dist/tileset/tileset-3d.js +108 -127
  33. package/dist/tileset/tileset-cache.d.ts +5 -4
  34. package/dist/tileset/tileset-cache.d.ts.map +1 -1
  35. package/dist/tileset/tileset-cache.js +4 -10
  36. package/dist/tileset/tileset-traverser.d.ts +32 -21
  37. package/dist/tileset/tileset-traverser.d.ts.map +1 -1
  38. package/dist/tileset/tileset-traverser.js +23 -35
  39. package/package.json +4 -4
  40. package/src/constants.ts +18 -0
  41. package/src/tileset/helpers/3d-tiles-options.ts +3 -1
  42. package/src/tileset/tile-3d.ts +70 -109
  43. package/src/tileset/tileset-3d.ts +178 -216
  44. package/src/tileset/tileset-cache.ts +20 -15
  45. package/src/tileset/tileset-traverser.ts +52 -68
@@ -4,40 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Tileset3D = void 0;
5
5
  // This file is derived from the Cesium code base under Apache 2 license
6
6
  // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
7
- /*
8
-
9
- The Tileset loading and rendering flow is as below,
10
- A rendered (i.e. deck.gl `Tile3DLayer`) triggers `tileset.update()` after a `tileset` is loaded
11
- `tileset` starts traversing the tile tree and update `requestTiles` (tiles of which content need
12
- to be fetched) and `selectedTiles` (tiles ready for rendering under the current viewport).
13
- `Tile3DLayer` will update rendering based on `selectedTiles`.
14
- `Tile3DLayer` also listens to `onTileLoad` callback and trigger another round of `update and then traversal`
15
- when new tiles are loaded.
16
-
17
- As I3S tileset have stored `tileHeader` file (metadata) and tile content files (geometry, texture, ...) separately.
18
- During each traversal, it issues `tilHeader` requests if that `tileHeader` is not yet fetched,
19
- after the tile header is fulfilled, it will resume the traversal starting from the tile just fetched (not root).
20
-
21
- Tile3DLayer
22
- |
23
- await load(tileset)
24
- |
25
- tileset.update()
26
- | async load tileHeader
27
- tileset.traverse() -------------------------- Queued
28
- | resume traversal after fetched |
29
- |----------------------------------------|
30
- |
31
- | async load tile content
32
- tilset.requestedTiles ----------------------------- RequestScheduler
33
- |
34
- tilset.selectedTiles (ready for rendering) |
35
- | Listen to |
36
- Tile3DLayer ----------- onTileLoad ----------------------|
37
- | | notify new tile is available
38
- updateLayers |
39
- tileset.update // trigger another round of update
40
- */
41
7
  const core_1 = require("@math.gl/core");
42
8
  const geospatial_1 = require("@math.gl/geospatial");
43
9
  const stats_1 = require("@probe.gl/stats");
@@ -55,39 +21,18 @@ const i3s_tileset_traverser_1 = require("./format-i3s/i3s-tileset-traverser");
55
21
  const DEFAULT_PROPS = {
56
22
  description: '',
57
23
  ellipsoid: geospatial_1.Ellipsoid.WGS84,
58
- // A 4x4 transformation matrix this transforms the entire tileset.
59
24
  modelMatrix: new core_1.Matrix4(),
60
- // Set to false to disable network request throttling
61
25
  throttleRequests: true,
62
- // Number of simultaneous requsts, if throttleRequests is true
63
26
  maxRequests: 64,
64
27
  maximumMemoryUsage: 32,
65
- /** Maximum number limit of tiles selected for show. 0 means no limit */
66
28
  maximumTilesSelected: 0,
67
- /** Delay time before the tileset traversal. It prevents traversal requests spam.*/
68
29
  debounceTime: 0,
69
- /**
70
- * Callback. Indicates this a tile's content was loaded
71
- * @param tile {TileHeader}
72
- */
73
30
  onTileLoad: () => { },
74
- /**
75
- * Callback. Indicates this a tile's content was unloaded
76
- * @param tile {TileHeader}
77
- */
78
31
  onTileUnload: () => { },
79
32
  onTileError: () => { },
80
- /**
81
- * Callback. Allows post-process selectedTiles right after traversal.
82
- * @param selectedTiles {TileHeader[]}
83
- * @returns TileHeader[] - output array of tiles to return to deck.gl
84
- */
85
33
  onTraversalComplete: (selectedTiles) => selectedTiles,
86
- // Optional async tile content loader
87
34
  contentLoader: undefined,
88
- // View distance scale modifier
89
35
  viewDistanceScale: 1.0,
90
- // The maximum screen space error used to drive level of detail refinement.
91
36
  maximumScreenSpaceError: 8,
92
37
  loadTiles: true,
93
38
  updateTransforms: true,
@@ -108,6 +53,39 @@ const TILES_UNLOADED = 'Tiles Unloaded';
108
53
  const TILES_LOAD_FAILED = 'Failed Tile Loads';
109
54
  const POINTS_COUNT = 'Points/Vertices';
110
55
  const TILES_GPU_MEMORY = 'Tile Memory Use';
56
+ /**
57
+ * The Tileset loading and rendering flow is as below,
58
+ * A rendered (i.e. deck.gl `Tile3DLayer`) triggers `tileset.update()` after a `tileset` is loaded
59
+ * `tileset` starts traversing the tile tree and update `requestTiles` (tiles of which content need
60
+ * to be fetched) and `selectedTiles` (tiles ready for rendering under the current viewport).
61
+ * `Tile3DLayer` will update rendering based on `selectedTiles`.
62
+ * `Tile3DLayer` also listens to `onTileLoad` callback and trigger another round of `update and then traversal`
63
+ * when new tiles are loaded.
64
+
65
+ * As I3S tileset have stored `tileHeader` file (metadata) and tile content files (geometry, texture, ...) separately.
66
+ * During each traversal, it issues `tilHeader` requests if that `tileHeader` is not yet fetched,
67
+ * after the tile header is fulfilled, it will resume the traversal starting from the tile just fetched (not root).
68
+
69
+ * Tile3DLayer
70
+ * |
71
+ * await load(tileset)
72
+ * |
73
+ * tileset.update()
74
+ * | async load tileHeader
75
+ * tileset.traverse() -------------------------- Queued
76
+ * | resume traversal after fetched |
77
+ * |----------------------------------------|
78
+ * |
79
+ * | async load tile content
80
+ * tilset.requestedTiles ----------------------------- RequestScheduler
81
+ * |
82
+ * tilset.selectedTiles (ready for rendering) |
83
+ * | Listen to |
84
+ * Tile3DLayer ----------- onTileLoad ----------------------|
85
+ * | | notify new tile is available
86
+ * updateLayers |
87
+ * tileset.update // trigger another round of update
88
+ */
111
89
  class Tileset3D {
112
90
  /**
113
91
  * Create a new Tileset3D
@@ -115,75 +93,80 @@ class Tileset3D {
115
93
  * @param props
116
94
  */
117
95
  // eslint-disable-next-line max-statements
118
- constructor(json, options) {
96
+ constructor(tileset, options) {
97
+ this.root = null;
98
+ this.roots = {};
99
+ /** @todo any->unknown */
100
+ this.asset = {};
101
+ // Metadata for the entire tileset
102
+ this.description = '';
103
+ this.extras = null;
104
+ this.attributions = {};
105
+ this.credits = {};
119
106
  /** flags that contain information about data types in nested tiles */
120
107
  this.contentFormats = { draco: false, meshopt: false, dds: false, ktx2: false };
108
+ // view props
109
+ this.cartographicCenter = null;
110
+ this.cartesianCenter = null;
111
+ this.zoom = 1;
112
+ this.boundingVolume = null;
113
+ /** Updated based on the camera position and direction */
114
+ this.dynamicScreenSpaceErrorComputedDensity = 0.0;
115
+ // METRICS
116
+ /**
117
+ * The maximum amount of GPU memory (in MB) that may be used to cache tiles
118
+ * Tiles not in view are unloaded to enforce private
119
+ */
120
+ this.maximumMemoryUsage = 32;
121
+ /** The total amount of GPU memory in bytes used by the tileset. */
122
+ this.gpuMemoryUsageInBytes = 0;
123
+ /** Update tracker. increase in each update cycle. */
124
+ this._frameNumber = 0;
125
+ this._queryParams = {};
126
+ this._extensionsUsed = [];
127
+ this._tiles = {};
128
+ /** counter for tracking tiles requests */
129
+ this._pendingCount = 0;
130
+ /** Hold traversal results */
131
+ this.selectedTiles = [];
132
+ // TRAVERSAL
133
+ this.traverseCounter = 0;
134
+ this.geometricError = 0;
135
+ this.lastUpdatedVieports = null;
136
+ this._requestedTiles = [];
137
+ this._emptyTiles = [];
138
+ this.frameStateData = {};
139
+ this._cache = new tileset_cache_1.TilesetCache();
140
+ // Promise tracking
121
141
  this.updatePromise = null;
122
- (0, loader_utils_1.assert)(json);
123
142
  // PUBLIC MEMBERS
124
143
  this.options = { ...DEFAULT_PROPS, ...options };
125
144
  // raw data
126
- this.tileset = json;
127
- this.loader = json.loader;
145
+ this.tileset = tileset;
146
+ this.loader = tileset.loader;
128
147
  // could be 3d tiles, i3s
129
- this.type = json.type;
148
+ this.type = tileset.type;
130
149
  // The url to a tileset JSON file.
131
- this.url = json.url;
132
- this.basePath = json.basePath || loader_utils_1.path.dirname(this.url);
150
+ this.url = tileset.url;
151
+ this.basePath = tileset.basePath || loader_utils_1.path.dirname(this.url);
133
152
  this.modelMatrix = this.options.modelMatrix;
134
153
  this.ellipsoid = this.options.ellipsoid;
135
154
  // Geometric error when the tree is not rendered at all
136
- this.lodMetricType = json.lodMetricType;
137
- this.lodMetricValue = json.lodMetricValue;
138
- this.refine = json.root.refine;
155
+ this.lodMetricType = tileset.lodMetricType;
156
+ this.lodMetricValue = tileset.lodMetricValue;
157
+ this.refine = tileset.root.refine;
139
158
  this.loadOptions = this.options.loadOptions || {};
140
- this.root = null;
141
- this.roots = {};
142
- // view props
143
- this.cartographicCenter = null;
144
- this.cartesianCenter = null;
145
- this.zoom = 1;
146
- this.boundingVolume = null;
147
159
  // TRAVERSAL
148
- this.traverseCounter = 0;
149
- this.geometricError = 0;
150
160
  this._traverser = this._initializeTraverser();
151
- this._cache = new tileset_cache_1.TilesetCache();
152
161
  this._requestScheduler = new loader_utils_1.RequestScheduler({
153
162
  throttleRequests: this.options.throttleRequests,
154
163
  maxRequests: this.options.maxRequests
155
164
  });
156
- // update tracker
157
- // increase in each update cycle
158
- this._frameNumber = 0;
159
- // counter for tracking tiles requests
160
- this._pendingCount = 0;
161
- // HOLD TRAVERSAL RESULTS
162
- this._tiles = {};
163
- this.selectedTiles = [];
164
- this._emptyTiles = [];
165
- this._requestedTiles = [];
166
- this.frameStateData = {};
167
- this.lastUpdatedVieports = null;
168
- this._queryParams = {};
169
- this._queryParamsString = '';
170
165
  // METRICS
171
- // The maximum amount of GPU memory (in MB) that may be used to cache tiles.
172
- // Tiles not in view are unloaded to enforce this.
173
- this.maximumMemoryUsage = this.options.maximumMemoryUsage || 32;
174
166
  // The total amount of GPU memory in bytes used by the tileset.
175
- this.gpuMemoryUsageInBytes = 0;
176
167
  this.stats = new stats_1.Stats({ id: this.url });
177
168
  this._initializeStats();
178
- // EXTRACTED FROM TILESET
179
- this._extensionsUsed = undefined;
180
- this.dynamicScreenSpaceErrorComputedDensity = 0.0; // Updated based on the camera position and direction
181
- // Metadata for the entire tileset
182
- this.extras = null;
183
- this.asset = {};
184
- this.credits = {};
185
- this.description = this.options.description || '';
186
- this.tilesetInitializationPromise = this._initializeTileSet(json);
169
+ this.tilesetInitializationPromise = this._initializeTileSet(tileset);
187
170
  }
188
171
  /** Release resources */
189
172
  destroy() {
@@ -201,10 +184,8 @@ class Tileset3D {
201
184
  return this._frameNumber;
202
185
  }
203
186
  get queryParams() {
204
- if (!this._queryParamsString) {
205
- this._queryParamsString = getQueryParamString(this._queryParams);
206
- }
207
- return this._queryParamsString;
187
+ const search = new URLSearchParams(this._queryParams).toString();
188
+ return search ? `?${search}` : '';
208
189
  }
209
190
  setProps(props) {
210
191
  this.options = { ...this.options, ...props };
@@ -222,11 +203,11 @@ class Tileset3D {
222
203
  if (isDataUrl) {
223
204
  return tilePath;
224
205
  }
225
- return `${tilePath}${this.queryParams}`;
206
+ return `${tilePath}${tilePath.includes('?') ? '&' : '?'}${this.queryParams}`;
226
207
  }
227
208
  // TODO CESIUM specific
228
209
  hasExtension(extensionName) {
229
- return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1);
210
+ return Boolean(this._extensionsUsed.indexOf(extensionName) > -1);
230
211
  }
231
212
  /**
232
213
  * Update visible tiles relying on a list of viewports
@@ -468,7 +449,6 @@ class Tileset3D {
468
449
  */
469
450
  calculateViewPropsTiles3D() {
470
451
  const root = this.root;
471
- (0, loader_utils_1.assert)(root);
472
452
  const { center } = root.boundingVolume;
473
453
  // TODO - handle all cases
474
454
  if (!center) {
@@ -522,6 +502,15 @@ class Tileset3D {
522
502
  const children = tile.header.children || [];
523
503
  for (const childHeader of children) {
524
504
  const childTile = new tile_3d_1.Tile3D(this, childHeader, tile);
505
+ // Special handling for Google
506
+ // A session key must be used for all tile requests
507
+ if (childTile.contentUrl?.includes('?session=')) {
508
+ const url = new URL(childTile.contentUrl);
509
+ const session = url.searchParams.get('session');
510
+ if (session) {
511
+ this._queryParams.session = session;
512
+ }
513
+ }
525
514
  tile.children.push(childTile);
526
515
  childTile.depth = tile.depth + 1;
527
516
  stack.push(childTile);
@@ -558,7 +547,7 @@ class Tileset3D {
558
547
  loaded = await tile.loadContent();
559
548
  }
560
549
  catch (error) {
561
- this._onTileLoadError(tile, error);
550
+ this._onTileLoadError(tile, error instanceof Error ? error : new Error('load failed'));
562
551
  }
563
552
  finally {
564
553
  this._onEndTileLoading();
@@ -638,11 +627,11 @@ class Tileset3D {
638
627
  this.stats.get(TILES_LOADED).incrementCount();
639
628
  this.stats.get(TILES_IN_MEMORY).incrementCount();
640
629
  // Good enough? Just use the raw binary ArrayBuffer's byte length.
641
- this.gpuMemoryUsageInBytes += tile.content.byteLength || 0;
630
+ this.gpuMemoryUsageInBytes += tile.gpuMemoryUsageInBytes || 0;
642
631
  this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
643
632
  }
644
633
  _unloadTile(tile) {
645
- this.gpuMemoryUsageInBytes -= (tile.content && tile.content.byteLength) || 0;
634
+ this.gpuMemoryUsageInBytes -= tile.gpuMemoryUsageInBytes || 0;
646
635
  this.stats.get(TILES_IN_MEMORY).decrementCount();
647
636
  this.stats.get(TILES_UNLOADED).incrementCount();
648
637
  this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
@@ -686,6 +675,11 @@ class Tileset3D {
686
675
  tile.destroy();
687
676
  }
688
677
  _initializeTiles3DTileset(tilesetJson) {
678
+ if (tilesetJson.queryString) {
679
+ const searchParams = new URLSearchParams(tilesetJson.queryString);
680
+ const queryParams = Object.fromEntries(searchParams.entries());
681
+ this._queryParams = { ...this._queryParams, ...queryParams };
682
+ }
689
683
  this.asset = tilesetJson.asset;
690
684
  if (!this.asset) {
691
685
  throw new Error('Tileset must have an asset property.');
@@ -706,28 +700,15 @@ class Tileset3D {
706
700
  // Gets the tileset's properties dictionary object, which contains metadata about per-feature properties.
707
701
  this.properties = tilesetJson.properties;
708
702
  this.geometricError = tilesetJson.geometricError;
709
- this._extensionsUsed = tilesetJson.extensionsUsed;
703
+ this._extensionsUsed = tilesetJson.extensionsUsed || [];
710
704
  // Returns the extras property at the top of the tileset JSON (application specific metadata).
711
705
  this.extras = tilesetJson.extras;
712
706
  }
713
707
  _initializeI3STileset() {
708
+ // @ts-expect-error
714
709
  if (this.loadOptions.i3s && 'token' in this.loadOptions.i3s) {
715
710
  this._queryParams.token = this.loadOptions.i3s.token;
716
711
  }
717
712
  }
718
713
  }
719
714
  exports.Tileset3D = Tileset3D;
720
- function getQueryParamString(queryParams) {
721
- const queryParamStrings = [];
722
- for (const key of Object.keys(queryParams)) {
723
- queryParamStrings.push(`${key}=${queryParams[key]}`);
724
- }
725
- switch (queryParamStrings.length) {
726
- case 0:
727
- return '';
728
- case 1:
729
- return `?${queryParamStrings[0]}`;
730
- default:
731
- return `?${queryParamStrings.join('&')}`;
732
- }
733
- }
@@ -1,6 +1,7 @@
1
+ import type { Tileset3D } from './tileset-3d';
2
+ import type { Tile3D } from './tile-3d';
1
3
  /**
2
4
  * Stores tiles with content loaded.
3
- *
4
5
  * @private
5
6
  */
6
7
  export declare class TilesetCache {
@@ -9,9 +10,9 @@ export declare class TilesetCache {
9
10
  private _trimTiles;
10
11
  constructor();
11
12
  reset(): void;
12
- touch(tile: any): void;
13
- add(tileset: any, tile: any, addCallback: any): void;
14
- unloadTile(tileset: any, tile: any, unloadCallback?: any): void;
13
+ touch(tile: Tile3D): void;
14
+ add(tileset: Tileset3D, tile: Tile3D, addCallback?: (tileset: Tileset3D, tile: Tile3D) => void): void;
15
+ unloadTile(tileset: Tileset3D, tile: Tile3D, unloadCallback?: (tileset: Tileset3D, tile: Tile3D) => void): void;
15
16
  unloadTiles(tileset: any, unloadCallback: any): void;
16
17
  trim(): void;
17
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tileset-cache.d.ts","sourceRoot":"","sources":["../../src/tileset/tileset-cache.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAU;;IAU5B,KAAK;IAOL,KAAK,CAAC,IAAI,KAAA;IAOV,GAAG,CAAC,OAAO,KAAA,EAAE,IAAI,KAAA,EAAE,WAAW,KAAA;IAU9B,UAAU,CAAC,OAAO,KAAA,EAAE,IAAI,KAAA,EAAE,cAAc,CAAC,KAAA;IAazC,WAAW,CAAC,OAAO,KAAA,EAAE,cAAc,KAAA;IA0BnC,IAAI;CAGL"}
1
+ {"version":3,"file":"tileset-cache.d.ts","sourceRoot":"","sources":["../../src/tileset/tileset-cache.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AAGtC;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAU;;IAU5B,KAAK,IAAI,IAAI;IAOb,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOzB,GAAG,CACD,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,GACvD,IAAI;IAUP,UAAU,CACR,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,GAC1D,IAAI;IAaP,WAAW,CAAC,OAAO,KAAA,EAAE,cAAc,KAAA,GAAG,IAAI;IA0B1C,IAAI,IAAI,IAAI;CAGb"}
@@ -2,15 +2,9 @@
2
2
  // loaders.gl, MIT license
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TilesetCache = void 0;
5
- // This file is derived from the Cesium code base under Apache 2 license
6
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
7
5
  const doubly_linked_list_1 = require("../utils/doubly-linked-list");
8
- function defined(x) {
9
- return x !== undefined && x !== null;
10
- }
11
6
  /**
12
7
  * Stores tiles with content loaded.
13
- *
14
8
  * @private
15
9
  */
16
10
  class TilesetCache {
@@ -29,12 +23,12 @@ class TilesetCache {
29
23
  }
30
24
  touch(tile) {
31
25
  const node = tile._cacheNode;
32
- if (defined(node)) {
26
+ if (node) {
33
27
  this._list.splice(this._sentinel, node);
34
28
  }
35
29
  }
36
30
  add(tileset, tile, addCallback) {
37
- if (!defined(tile._cacheNode)) {
31
+ if (!tile._cacheNode) {
38
32
  tile._cacheNode = this._list.add(tile);
39
33
  if (addCallback) {
40
34
  addCallback(tileset, tile);
@@ -43,11 +37,11 @@ class TilesetCache {
43
37
  }
44
38
  unloadTile(tileset, tile, unloadCallback) {
45
39
  const node = tile._cacheNode;
46
- if (!defined(node)) {
40
+ if (!node) {
47
41
  return;
48
42
  }
49
43
  this._list.remove(node);
50
- tile._cacheNode = undefined;
44
+ tile._cacheNode = null;
51
45
  if (unloadCallback) {
52
46
  unloadCallback(tileset, tile);
53
47
  }
@@ -1,46 +1,57 @@
1
+ import type { Tile3D } from './tile-3d';
1
2
  import { ManagedArray } from '../utils/managed-array';
2
3
  import { FrameState } from './helpers/frame-state';
3
4
  export type TilesetTraverserProps = {
4
5
  loadSiblings?: boolean;
5
6
  skipLevelOfDetail?: boolean;
7
+ updateTransforms?: boolean;
6
8
  maximumScreenSpaceError?: number;
7
9
  onTraversalEnd?: (frameState: any) => any;
8
- viewportTraversersMap?: {
9
- [key: string]: any;
10
- };
10
+ viewportTraversersMap?: Record<string, any>;
11
11
  basePath?: string;
12
- updateTransforms?: boolean;
13
12
  };
14
13
  export declare const DEFAULT_PROPS: Required<TilesetTraverserProps>;
15
14
  export declare class TilesetTraverser {
16
15
  options: Required<TilesetTraverserProps>;
17
16
  root: any;
18
- requestedTiles: object;
19
- selectedTiles: object;
20
- emptyTiles: object;
17
+ selectedTiles: Record<string, Tile3D>;
18
+ requestedTiles: Record<string, Tile3D>;
19
+ emptyTiles: Record<string, Tile3D>;
21
20
  protected lastUpdate: number;
22
21
  protected readonly updateDebounceTime = 1000;
22
+ /** temporary storage to hold the traversed tiles during a traversal */
23
23
  protected _traversalStack: ManagedArray;
24
24
  protected _emptyTraversalStack: ManagedArray;
25
+ /** set in every traverse cycle */
25
26
  protected _frameNumber: number | null;
26
27
  protected traversalFinished(frameState: FrameState): boolean;
27
28
  constructor(options: TilesetTraverserProps);
28
29
  traverse(root: any, frameState: any, options: any): void;
29
30
  reset(): void;
31
+ /**
32
+ * Execute traverse
33
+ * Depth-first traversal that traverses all visible tiles and marks tiles for selection.
34
+ * If skipLevelOfDetail is off then a tile does not refine until all children are loaded.
35
+ * This is the traditional replacement refinement approach and is called the base traversal.
36
+ * Tiles that have a greater screen space error than the base screen space error are part of the base traversal,
37
+ * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree
38
+ * and rendering children and parent tiles simultaneously.
39
+ */
30
40
  executeTraversal(root: any, frameState: FrameState): void;
31
- updateChildTiles(tile: any, frameState: any): boolean;
32
- updateAndPushChildren(tile: any, frameState: any, stack: any, depth: any): boolean;
33
- updateTile(tile: any, frameState: any): void;
34
- selectTile(tile: any, frameState: any): void;
35
- loadTile(tile: any, frameState: any): void;
36
- touchTile(tile: any, frameState: any): void;
37
- canTraverse(tile: any, frameState: any, useParentMetric?: boolean, ignoreVisibility?: boolean): boolean;
38
- shouldLoadTile(tile: any): any;
39
- shouldSelectTile(tile: any): any;
40
- shouldRefine(tile: any, frameState: any, useParentMetric: any): boolean;
41
- updateTileVisibility(tile: any, frameState: any): void;
42
- compareDistanceToCamera(b: any, a: any): number;
43
- anyChildrenVisible(tile: any, frameState: any): boolean;
44
- executeEmptyTraversal(root: any, frameState: any): boolean;
41
+ updateChildTiles(tile: Tile3D, frameState: FrameState): void;
42
+ updateAndPushChildren(tile: Tile3D, frameState: FrameState, stack: any, depth: any): boolean;
43
+ updateTile(tile: Tile3D, frameState: FrameState): void;
44
+ selectTile(tile: Tile3D, frameState: FrameState): void;
45
+ loadTile(tile: Tile3D, frameState: FrameState): void;
46
+ touchTile(tile: Tile3D, frameState: FrameState): void;
47
+ canTraverse(tile: Tile3D, frameState: FrameState, useParentMetric?: boolean, ignoreVisibility?: boolean): boolean;
48
+ shouldLoadTile(tile: Tile3D): boolean;
49
+ shouldSelectTile(tile: Tile3D): boolean;
50
+ /** Decide if tile LoD (level of detail) is not sufficient under current viewport */
51
+ shouldRefine(tile: Tile3D, frameState: FrameState, useParentMetric?: boolean): boolean;
52
+ updateTileVisibility(tile: Tile3D, frameState: FrameState): void;
53
+ compareDistanceToCamera(b: Tile3D, a: Tile3D): number;
54
+ anyChildrenVisible(tile: Tile3D, frameState: FrameState): boolean;
55
+ executeEmptyTraversal(root: Tile3D, frameState: FrameState): boolean;
45
56
  }
46
57
  //# sourceMappingURL=tileset-traverser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tileset-traverser.d.ts","sourceRoot":"","sources":["../../src/tileset/tileset-traverser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,UAAU,KAAA,KAAK,GAAG,CAAC;IACrC,qBAAqB,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAYF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAQzD,CAAC;AAEF,qBAAa,gBAAgB;IAC3B,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IA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AAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAiBhE,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAIrD,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;IAajE,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;CAqCrE"}
@@ -1,17 +1,9 @@
1
1
  "use strict";
2
+ // loaders.gl, MIT license
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.TilesetTraverser = exports.DEFAULT_PROPS = void 0;
4
5
  const managed_array_1 = require("../utils/managed-array");
5
6
  const constants_1 = require("../constants");
6
- // export type Props = {
7
- // loadSiblings: boolean;
8
- // skipLevelOfDetail: boolean;
9
- // updateTransforms: boolean;
10
- // maximumScreenSpaceError: number;
11
- // onTraversalEnd: (frameState) => any;
12
- // viewportTraversersMap: {[key: string]: any};
13
- // basePath: string;
14
- // };
15
7
  exports.DEFAULT_PROPS = {
16
8
  loadSiblings: false,
17
9
  skipLevelOfDetail: false,
@@ -22,29 +14,28 @@ exports.DEFAULT_PROPS = {
22
14
  basePath: ''
23
15
  };
24
16
  class TilesetTraverser {
17
+ // RESULT
25
18
  traversalFinished(frameState) {
26
19
  return true;
27
20
  }
28
21
  // TODO nested props
29
22
  constructor(options) {
30
- this.lastUpdate = new Date().getTime();
31
- this.updateDebounceTime = 1000;
32
- this.options = { ...exports.DEFAULT_PROPS, ...options };
33
- // TRAVERSAL
34
- // temporary storage to hold the traversed tiles during a traversal
35
- this._traversalStack = new managed_array_1.ManagedArray();
36
- this._emptyTraversalStack = new managed_array_1.ManagedArray();
37
- // set in every traverse cycle
38
- this._frameNumber = null;
39
23
  // fulfill in traverse call
40
24
  this.root = null;
41
- // RESULT
42
25
  // tiles should be rendered
43
26
  this.selectedTiles = {};
44
27
  // tiles should be loaded from server
45
28
  this.requestedTiles = {};
46
29
  // tiles does not have render content
47
30
  this.emptyTiles = {};
31
+ this.lastUpdate = new Date().getTime();
32
+ this.updateDebounceTime = 1000;
33
+ /** temporary storage to hold the traversed tiles during a traversal */
34
+ this._traversalStack = new managed_array_1.ManagedArray();
35
+ this._emptyTraversalStack = new managed_array_1.ManagedArray();
36
+ /** set in every traverse cycle */
37
+ this._frameNumber = null;
38
+ this.options = { ...exports.DEFAULT_PROPS, ...options };
48
39
  }
49
40
  // tiles should be visible
50
41
  traverse(root, frameState, options) {
@@ -58,19 +49,18 @@ class TilesetTraverser {
58
49
  this.executeTraversal(root, frameState);
59
50
  }
60
51
  reset() {
61
- this.requestedTiles = {};
62
- this.selectedTiles = {};
63
- this.emptyTiles = {};
64
52
  this._traversalStack.reset();
65
53
  this._emptyTraversalStack.reset();
66
54
  }
67
- // execute traverse
68
- // Depth-first traversal that traverses all visible tiles and marks tiles for selection.
69
- // If skipLevelOfDetail is off then a tile does not refine until all children are loaded.
70
- // This is the traditional replacement refinement approach and is called the base traversal.
71
- // Tiles that have a greater screen space error than the base screen space error are part of the base traversal,
72
- // all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree
73
- // and rendering children and parent tiles simultaneously.
55
+ /**
56
+ * Execute traverse
57
+ * Depth-first traversal that traverses all visible tiles and marks tiles for selection.
58
+ * If skipLevelOfDetail is off then a tile does not refine until all children are loaded.
59
+ * This is the traditional replacement refinement approach and is called the base traversal.
60
+ * Tiles that have a greater screen space error than the base screen space error are part of the base traversal,
61
+ * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree
62
+ * and rendering children and parent tiles simultaneously.
63
+ */
74
64
  /* eslint-disable-next-line complexity, max-statements */
75
65
  executeTraversal(root, frameState) {
76
66
  // stack to store traversed tiles, only visible tiles should be added to stack
@@ -132,7 +122,6 @@ class TilesetTraverser {
132
122
  for (const child of children) {
133
123
  this.updateTile(child, frameState);
134
124
  }
135
- return true;
136
125
  }
137
126
  /* eslint-disable complexity, max-statements */
138
127
  updateAndPushChildren(tile, frameState, stack, depth) {
@@ -235,8 +224,8 @@ class TilesetTraverser {
235
224
  // and content available
236
225
  return tile.contentAvailable && !this.options.skipLevelOfDetail;
237
226
  }
238
- // Decide if tile LoD (level of detail) is not sufficient under current viewport
239
- shouldRefine(tile, frameState, useParentMetric) {
227
+ /** Decide if tile LoD (level of detail) is not sufficient under current viewport */
228
+ shouldRefine(tile, frameState, useParentMetric = false) {
240
229
  let screenSpaceError = tile._screenSpaceError;
241
230
  if (useParentMetric) {
242
231
  screenSpaceError = tile.getScreenSpaceError(frameState, true);
@@ -265,7 +254,9 @@ class TilesetTraverser {
265
254
  anyChildrenVisible(tile, frameState) {
266
255
  let anyVisible = false;
267
256
  for (const child of tile.children) {
257
+ // @ts-expect-error
268
258
  child.updateVisibility(frameState);
259
+ // @ts-expect-error
269
260
  anyVisible = anyVisible || child.isVisibleAndInRequestVolume;
270
261
  }
271
262
  return anyVisible;
@@ -304,6 +295,3 @@ class TilesetTraverser {
304
295
  }
305
296
  }
306
297
  exports.TilesetTraverser = TilesetTraverser;
307
- // TODO
308
- // enable expiration
309
- // enable optimization hint