The Re:Earth Visualizer Plugin API provides a consistent pattern for handling events across different components. Events allow your plugin to respond to user interactions and system changes in real-time.
Common Event Methods
Section titled “Common Event Methods”All event-enabled components in the Re:Earth Visualizer share the same pattern for subscribing to and unsubscribing from events.
The on method allows you to register an event listener that will be called when the specified event occurs.
Syntax
Section titled “Syntax”on<T extends keyof EventType>( type: T, callback: (...args: EventType[T]) => void, options?: { once?: boolean }): voidParameters
Section titled “Parameters”- type: The event type to listen for
- callback: Function to execute when the event occurs
- options (optional): Configuration options
- once: When set to
true, the listener will be automatically removed after being invoked once
- once: When set to
Example
Section titled “Example”// Basic event listenerreearth.popup.on("close", () => { console.log("Popup was closed");});
// Event listener that only triggers oncereearth.layers.on( "select", (layerId, featureId) => { console.log("Layer selected (this will only trigger once):", layerId, featureId); }, { once: true });The off method allows you to remove a previously registered event listener.
Syntax
Section titled “Syntax”off<T extends keyof EventType>( type: T, callback: (...args: EventType[T]) => void): voidParameters
Section titled “Parameters”- type: The event type to unregister
- callback: The function that was previously registered with
on
Example
Section titled “Example”// Define the callback functionconst handleClose = () => { console.log("Popup was closed");};
// Register the event listenerreearth.popup.on("close", handleClose);
// Later, when you want to stop listeningreearth.popup.off("close", handleClose);Event Types
Section titled “Event Types”Each component in the Re:Earth Visualizer has its own set of event types. Refer to the individual component documentation for specific event details.