ThreeView Events
This page describes all events available on a ThreeView instance.
Methods
Section titled “Methods”Registers event listeners for various view events.
on<K extends keyof ViewEvents>(event: K, handler: ViewEvents[K]): voidRemoves an event listener.
off<K extends keyof ViewEvents>(event: K, handler: ViewEvents[K]): voidExample:
const resizeHandler = (width, height) => { console.log(`Resized to ${width}x${height}`);};
// Register event listenerview.on("resize", resizeHandler);
// Later, remove the listenerview.off("resize", resizeHandler);Advanced Example
Section titled “Advanced Example”// Create named handlers for easy cleanupconst handlers = { handleClick: (event) => { console.log("Clicked:", event); }, handleResize: (width, height) => { console.log(`Resized: ${width}x${height}`); }, handlePick: (info) => { if (info) { console.log("Picked:", info.properties); } },};
// Register multiple listenersview.on("click", handlers.handleClick);view.on("resize", handlers.handleResize);view.on("pick", handlers.handlePick);
// Later, cleanup all listenersview.off("click", handlers.handleClick);view.off("resize", handlers.handleResize);view.off("pick", handlers.handlePick);Event Types
Section titled “Event Types”resize
Section titled “resize”Description:
Fires when the window is resized. Receives width and height in pixels.
Handler Type:
(width: number, height: number) => voidParameters:
width: Width after resize (pixels)height: Height after resize (pixels)
Example:
view.on("resize", (width, height) => { console.log(`Window resized: ${width}x${height}`);});Description:
Fires when a feature is picked (selected). Receives the picked feature information, or null if nothing is selected.
Handler Type:
(info: PickedFeature | null) => voidParameters:
info: Picked feature information, ornull
type PickedFeature = { batchId: number; // Batch ID properties: Record<string, unknown> | undefined; // Feature properties layerId: string | undefined; // Layer ID};Example:
view.on("pick", (info) => { if (info) { console.log("Selected feature:", info.properties); console.log("Layer ID:", info.layerId); console.log("Batch ID:", info.batchId); } else { console.log("No feature selected"); }});Description:
Fires when a layer-related event occurs.
Handler Type:
<K extends keyof LayerEvent>( k: K, layerId: string, ...args: Parameters<LayerEvent[K]>) => voidExample:
view.on("layer", (eventType, layerId, ...args) => { console.log(`Layer ${layerId} event: ${eventType}`, args);});preUpdate
Section titled “preUpdate”Description:
Fires before the update process. Receives a DOMHighResTimeStamp as a timestamp.
Handler Type:
(time: number) => voidParameters:
time:DOMHighResTimeStamp(high-precision timestamp in milliseconds)
Example:
view.on("preUpdate", (time) => { // Custom logic before update console.log(`Before update: ${time}ms`);});postUpdate
Section titled “postUpdate”Description:
Fires after the update process when state changes have occurred. Receives a DOMHighResTimeStamp as a timestamp.
Handler Type:
(time: number) => voidParameters:
time:DOMHighResTimeStamp(high-precision timestamp in milliseconds)
Example:
view.on("postUpdate", (time) => { // Custom logic after update console.log(`After update: ${time}ms`);});preRender
Section titled “preRender”Description:
Fires before rendering. When animation: true, fires every frame. Receives a DOMHighResTimeStamp as a timestamp.
Handler Type:
(time: number) => voidParameters:
time:DOMHighResTimeStamp(high-precision timestamp in milliseconds)
Example:
view.on("preRender", (time) => { // Custom logic before rendering console.log(`Before render: ${time}ms`);});postRender
Section titled “postRender”Description:
Fires after rendering. When animation: true, fires every frame. Receives a DOMHighResTimeStamp as a timestamp.
Handler Type:
(time: number) => voidParameters:
time:DOMHighResTimeStamp(high-precision timestamp in milliseconds)
Example:
view.on("postRender", (time) => { // Custom logic after rendering console.log(`After render: ${time}ms`);});mousedown
Section titled “mousedown”Description:
Fires when a mouse button is pressed on the map. Receives a MapMouseEvent containing map coordinates.
Handler Type:
(event: MapMouseEvent) => voidParameters:
event: Mouse event (containing map coordinates)
Example:
view.on("mousedown", (event) => { console.log(`Mouse down position: ${event.clientX}, ${event.clientY}`); console.log( `Map coordinates (ECEF): ${event.map.x}, ${event.map.y}, ${event.map.z}` );});mouseenter
Section titled “mouseenter”Description:
Fires when the mouse enters the canvas area. Receives a MapMouseEvent containing map coordinates.
Handler Type:
(event: MapMouseEvent) => voidParameters:
event: Mouse event (containing map coordinates)
Example:
view.on("mouseenter", (event) => { console.log("Mouse entered the map"); console.log(`Map coordinates: ${event.map.x}, ${event.map.y}, ${event.map.z}`);});mouseleave
Section titled “mouseleave”Description:
Fires when the mouse leaves the canvas area. Receives a MapMouseEvent containing map coordinates.
Handler Type:
(event: MapMouseEvent) => voidParameters:
event: Mouse event (containing map coordinates)
Example:
view.on("mouseleave", (event) => { console.log("Mouse left the map");});mousemove
Section titled “mousemove”Description:
Fires when the mouse moves on the map. Receives a MapMouseEvent containing map coordinates.
Handler Type:
(event: MapMouseEvent) => voidParameters:
event: Mouse event (containing map coordinates)
Example:
view.on("mousemove", (event) => { console.log(`Mouse position: ${event.clientX}, ${event.clientY}`); console.log( `Map coordinates (ECEF): ${event.map.x}, ${event.map.y}, ${event.map.z}` );});mouseup
Section titled “mouseup”Description:
Fires when a mouse button is released on the map. Receives a MapMouseEvent containing map coordinates.
Handler Type:
(event: MapMouseEvent) => voidParameters:
event: Mouse event (containing map coordinates)
Example:
view.on("mouseup", (event) => { console.log(`Mouse up position: ${event.clientX}, ${event.clientY}`); console.log(`Map coordinates: ${event.map.x}, ${event.map.y}, ${event.map.z}`);});Description:
Fires when data and tile processing becomes idle — that is, when no updates such as tile loading or data processing have occurred for at least idleThreshold milliseconds. Continuous animations and effects do not count as activity, so this event fires even while they are running. It fires at most once per idle period and resets when processing activity resumes.
Handler Type:
() => voidExample:
view.on("idle", () => { console.log("Data and tile processing is idle");});Description:
Fires when the map is clicked. Receives a MapMouseEvent containing map coordinates.
Handler Type:
(event: MapMouseEvent) => voidParameters:
event: Mouse event (containing map coordinates)
Example:
view.on("click", (event) => { console.log(`Click position: ${event.clientX}, ${event.clientY}`); console.log( `Map coordinates (ECEF): ${event.map.x}, ${event.map.y}, ${event.map.z}` );});