From f0eb1e9c2de0d56cf53ec733c854198adb0e724e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Guimmara?= Date: Thu, 12 Dec 2024 09:54:21 +0100 Subject: [PATCH] TilesRenderer.d.ts: add types for events --- src/three/TilesRenderer.d.ts | 72 +++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/src/three/TilesRenderer.d.ts b/src/three/TilesRenderer.d.ts index 1d8fff7af..38ede1477 100644 --- a/src/three/TilesRenderer.d.ts +++ b/src/three/TilesRenderer.d.ts @@ -1,10 +1,25 @@ -import { Box3, Camera, Vector2, Matrix4, WebGLRenderer, Object3D, LoadingManager, Sphere } from 'three'; +import { Box3, Camera, Vector2, Matrix4, WebGLRenderer, Object3D, LoadingManager, Sphere, EventListener, EventDispatcher, BaseEvent } from 'three'; import { Tile } from '../base/Tile'; import { TilesRendererBase } from '../base/TilesRendererBase'; import { TilesGroup } from './TilesGroup'; import { Ellipsoid } from './math/Ellipsoid'; -export class TilesRenderer extends TilesRendererBase { +export interface TilesRendererEventMap { + 'add-camera': { camera: Camera }; + 'delete-camera': { camera: Camera }; + 'camera-resolution-change': {}; + 'load-tile-set': { tileSet: object, url: string }; + 'tiles-load-start': {}; + 'tiles-load-end': {}; + 'load-content': {}; + 'load-model': { scene: Object3D; tile: Tile }; + 'dispose-model': { scene: Object3D; tile: Tile }; + 'tile-visibility-change': { scene: Object3D; tile: Tile; visible: boolean }; + 'update-before': {}; + 'update-after': {}; +} + +export class TilesRenderer extends TilesRendererBase implements EventDispatcher { ellipsoid: Ellipsoid; autoDisableRendererCulling : boolean; @@ -28,9 +43,54 @@ export class TilesRenderer extends TilesRendererBase { forEachLoadedModel( callback : ( scene : Object3D, tile : Tile ) => void ) : void; - addEventListener( type: string, cb: ( e : object ) => void ); - hasEventListener( type: string, cb: ( e : object ) => void ); - removeEventListener( type: string, cb: ( e : object ) => void ); - dispatchEvent( e : object ); + /** + * Adds a listener to an event type. + * @param type The type of event to listen to. + * @param listener The function that gets called when the event is fired. + */ + addEventListener>( + type: T, + listener: EventListener + ): void; + addEventListener( + type: T, + listener: EventListener<{}, T, this> + ): void; + + /** + * Checks if listener is added to an event type. + * @param type The type of event to listen to. + * @param listener The function that gets called when the event is fired. + */ + hasEventListener>( + type: T, + listener: EventListener + ): boolean; + hasEventListener( + type: T, + listener: EventListener<{}, T, this> + ): boolean; + + /** + * Removes a listener from an event type. + * @param type The type of the listener that gets removed. + * @param listener The listener function that gets removed. + */ + removeEventListener>( + type: T, + listener: EventListener + ): void; + removeEventListener( + type: T, + listener: EventListener<{}, T, this> + ): void; + + /** + * Fire an event type. + * @param event The event that gets fired. + */ + dispatchEvent>( + event: BaseEvent & TilesRendererEventMap[T] + ): void; }