Repository: NASA-AMMOS/3DTilesRendererJS
Pull request #1139 (2025-05-21 08:03:02)

Fix event typing inconsistencies
Hi, heres what i came up with to fix the event typing inconsistencies mentioned in #1137.




Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e2a0d5..5d8733c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,10 +12,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 - Moved "optionalDependencies" to "peerDependencies" with an optional flag to avoid quirks with the optional dependencies field.
 - Make QuantizedMeshPlugin more robust to missing fields in layer.json.
 - TileFlatteningPlugin: Fixed disposal throwing an error.
+- Change `load-error` event field from `uri` to `url` as documented.
+- Fixed type definitions for some events.
 
 ### Added
 - Ability to resolve to any file in "./src".
-- QuantizedMesh: Add support for ttributions.
+- QuantizedMesh: Add support for attributions.
 
 ## [0.4.9] - 2025.05.07
 ### Fixed
diff --git a/README.md b/README.md
index f085d9e..bc172ad 100644
--- a/README.md
+++ b/README.md
@@ -316,17 +316,17 @@ _extends `THREE.EventDispatcher` & [TilesRendererBase](https://github.com/NASA-A
 
 // Fired when the content of a model is loaded. Fired along side the
 // above two events.
-{ type: 'load-content', tileSet: Object, url: String }
+{ type: 'load-content' }
 
 // Fired when a tile model is disposed.
 { type: 'dispose-model', scene: THREE.Group, tile: Object }
 
 // Fired when the tile set hierarchy is ready for "update to be called
 // again due to new content having loaded or asynchronous processing finished.
-{ type: 'needs-update', tileSet: Object, url: String }
+{ type: 'needs-update' }
 
 // Fired when a tiles visibility changes.
-{ type: 'tile-visibility-change', scene: THREE.Group, tile: Object }
+{ type: 'tile-visibility-change', scene: THREE.Group, tile: Object, visible: boolean }
 
 // Fired when tiles start loading.
 { type: 'tiles-load-start' }
@@ -336,6 +336,15 @@ _extends `THREE.EventDispatcher` & [TilesRendererBase](https://github.com/NASA-A
 
 // Fired when a tile content or the root tile set fails to load.
 { type: 'load-error', tile: Object | null, error: Error, url: string | URL }
+
+// Fired when a camera is added to be accounted for when traversing the tile set.
+{ type: 'add-camera', camera: Camera }
+
+// Fired when a camera is removed from being accounted for when traversing the tile set.
+{ type: 'delete-camera', camera: Camera }
+
+// Fired when the resolution being rendered to is changed for any tracked camera.
+{ type: 'camera-resolution-change' }
 ```
 
 ### .fetchOptions
diff --git a/src/base/TilesRendererBase.js b/src/base/TilesRendererBase.js
index 7c0b916..42ed53b 100644
--- a/src/base/TilesRendererBase.js
+++ b/src/base/TilesRendererBase.js
@@ -310,6 +310,7 @@ export class TilesRendererBase {
 						type: 'load-error',
 						tile: null,
 						error,
+						url: this.rootURL,
 					} );
 
 				} );
@@ -932,7 +933,7 @@ export class TilesRendererBase {
 						type: 'load-error',
 						tile,
 						error,
-						uri,
+						url: uri,
 					} );
 
 				} else {
diff --git a/src/plugins/three/GoogleCloudAuthPlugin.js b/src/plugins/three/GoogleCloudAuthPlugin.js
index c73be28..41d4af4 100644
--- a/src/plugins/three/GoogleCloudAuthPlugin.js
+++ b/src/plugins/three/GoogleCloudAuthPlugin.js
@@ -201,7 +201,7 @@ export class GoogleCloudAuthPlugin {
 						type: 'load-error',
 						tile: null,
 						error,
-						rootURL,
+						url: rootURL,
 					} );
 
 				} );
diff --git a/src/three/TilesRenderer.d.ts b/src/three/TilesRenderer.d.ts
index 460d534..dfd4b88 100644
--- a/src/three/TilesRenderer.d.ts
+++ b/src/three/TilesRenderer.d.ts
@@ -17,6 +17,8 @@ export interface TilesRendererEventMap {
 	'tile-visibility-change': { scene: Object3D; tile: Tile; visible: boolean };
 	'update-before': {};
 	'update-after': {};
+	'needs-update': {};
+	'load-error': { tile: Tile | null, error: Error, url: string | URL };
 }
 
 export class TilesRenderer<TEventMap extends TilesRendererEventMap = TilesRendererEventMap> extends TilesRendererBase implements EventDispatcher<TEventMap> {


Test patch:
diff --git a/test/types/TilesRenderer.test.ts b/test/types/TilesRenderer.test.ts
index 3c745a3..63e5699 100644
--- a/test/types/TilesRenderer.test.ts
+++ b/test/types/TilesRenderer.test.ts
@@ -9,6 +9,7 @@ function loadTileset( event: { tileSet: object, url: string } ) { }
 function loadModel( event: { scene: Object3D; tile: Tile } ) { }
 function disposeModel( event: { scene: Object3D; tile: Tile; } ) { }
 function tileVisibilityChange( event: { scene: Object3D; tile: Tile; visible: boolean } ) { }
+function loadError( event: { tile: Tile | null, error: Error, url: string | URL } ) { }
 
 function whatever( event: unknown ) { }
 
@@ -30,6 +31,8 @@ function typecheck( renderer: TilesRenderer ) {
 	renderer.addEventListener( 'tile-visibility-change', tileVisibilityChange );
 	renderer.addEventListener( 'update-before', emptyEvent );
 	renderer.addEventListener( 'update-after', emptyEvent );
+	renderer.addEventListener( 'needs-update', emptyEvent );
+	renderer.addEventListener( 'load-error', loadError );
 
 	// Check that we are still able to call an event type that is not
 	// known by the TilesRenderer itself.