Skip to content

Commit

Permalink
TilesRenderer.d.ts: add types for events
Browse files Browse the repository at this point in the history
  • Loading branch information
sguimmara committed Dec 16, 2024
1 parent e279ec8 commit b386c4c
Showing 1 changed file with 66 additions and 6 deletions.
72 changes: 66 additions & 6 deletions src/three/TilesRenderer.d.ts
Original file line number Diff line number Diff line change
@@ -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<TEventMap extends TilesRendererEventMap = TilesRendererEventMap> extends TilesRendererBase implements EventDispatcher<TEventMap> {

ellipsoid: Ellipsoid;
autoDisableRendererCulling : boolean;
Expand All @@ -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<T extends Extract<keyof TEventMap, string>>(
type: T,
listener: EventListener<TEventMap[T], T, this>
): void;
addEventListener<T extends string>(
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<T extends Extract<keyof TEventMap, string>>(
type: T,
listener: EventListener<TEventMap[T], T, this>
): boolean;
hasEventListener<T extends string>(
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<T extends Extract<keyof TEventMap, string>>(
type: T,
listener: EventListener<TEventMap[T], T, this>
): void;
removeEventListener<T extends string>(
type: T,
listener: EventListener<{}, T, this>
): void;

/**
* Fire an event type.
* @param event The event that gets fired.
*/
dispatchEvent<T extends Extract<keyof TEventMap, string>>(
event: BaseEvent<T> & TEventMap[T]
): void;

}

0 comments on commit b386c4c

Please sign in to comment.