GeoLeaf Core API - v3.19.0
    Preparing search index...

    Variable EventsConst

    Events: {
        on<K extends (keyof GeoLeafEventMap) | (keyof GeoLeafRawEventMap)>(
            event: K,
            handler: GeoLeafEventHandler<K>,
        ): () => void;
        off<K extends (keyof GeoLeafEventMap) | (keyof GeoLeafRawEventMap)>(
            event: K,
            handler: GeoLeafEventHandler<K>,
        ): void;
        once<K extends (keyof GeoLeafEventMap) | (keyof GeoLeafRawEventMap)>(
            event: K,
            handler: GeoLeafEventHandler<K>,
        ): () => void;
    } = ...

    Public GeoLeaf Events API. Exposed as GeoLeaf.Events (canonical) and GeoLeaf.events (legacy alias).

    Type Declaration

    • on: function
      • Registers a listener for a GeoLeaf event. The listener is called every time the event fires until it is removed — by the function this call returns, or by off() with the same handler.

        Type Parameters

        • K extends (keyof GeoLeafEventMap) | (keyof GeoLeafRawEventMap)

        Parameters

        • event: K

          Event name (see module docs for full reference).

        • handler: GeoLeafEventHandler<K>

          Callback receiving the CustomEvent with typed detail.

        Returns () => void

        A function that removes this listener. It is off(event, handler) bound to this subscription: calling it twice is harmless, and since the DOM registers one listener per handler reference, it also removes an identical earlier on(). Without a document (SSR), nothing is registered and the function does nothing.

        import { Events } from "@geoleaf/core";

        // An anonymous handler can only be removed through the returned function.
        const unsubscribe = Events.on("geoleaf:layer:toggle", (e) => {
        console.log(e.detail.layerId, e.detail.visible);
        });

        // On teardown:
        unsubscribe();
    • off: function
      • Removes a previously registered listener. The exact same handler reference must be passed.

        Type Parameters

        • K extends (keyof GeoLeafEventMap) | (keyof GeoLeafRawEventMap)

        Parameters

        • event: K

          Event name.

        • handler: GeoLeafEventHandler<K>

          The handler reference originally passed to on().

        Returns void

        // With off(), the handler must be NAMED — an anonymous one is removed through the
        // function on() returns.
        const handlePoiPanel = (e) => {
        console.log(e.detail.poiId);
        };
        GeoLeaf.Events.on("geoleaf:poi:panel:open", handlePoiPanel);

        // Plus tard :
        GeoLeaf.Events.off("geoleaf:poi:panel:open", handlePoiPanel);
    • once: function
      • Registers a listener that fires once then automatically removes itself. Uses the native {once: true} option — no wrapper function needed.

        Type Parameters

        • K extends (keyof GeoLeafEventMap) | (keyof GeoLeafRawEventMap)

        Parameters

        Returns () => void

        A function that cancels the listener if it has not fired yet — the teardown of a component unmounted before the event arrives. Calling it after the listener fired is harmless. Without a document (SSR), the function does nothing.

        GeoLeaf.Events.once("geoleaf:app:ready", () => {
        console.log("App prête !");
        });