Skip to content

GeoLeaf Events API

Module: @geoleaf/coreGeoLeaf.Events

GeoLeaf dispatches native DOM events (CustomEvent) on document. They are typed through GeoLeafEventMap.

INFO

Casing — GeoLeaf.Events and GeoLeaf.events. Both are mounted and equivalent (GeoLeaf.Events === GeoLeaf.events). Events is the canonical form: it is the one used throughout this reference and the one carried by the exported facade. events is a historical alias, kept for the long term and not deprecated — same contract as Baselayers / BaseLayers.

WARNING

Before v3.0.0, only events existed at runtime while the type definitions declared Events: GeoLeaf.Events.on(...) compiled and then threw a TypeError. Code that worked around this by writing events keeps working unchanged.

Integrators subscribe only — dispatching is internal to GeoLeaf.


Public API

GeoLeaf.Events.on(event, handler)

ts
GeoLeaf.Events.on("geoleaf:poi:click", (e) => {
    console.log("POI clicked:", e.detail.poiId);
});

Registers a listener for event. Called on every dispatch until off().

GeoLeaf.Events.off(event, handler)

ts
GeoLeaf.Events.off("geoleaf:poi:click", myHandler);

Removes a previously registered listener. The same function reference must be passed.

GeoLeaf.Events.once(event, handler)

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

Listener fired once, then removed automatically.


Full event reference

Event nameDispatched whenKey payload fields
geoleaf:app:readyApp fully initialisedversion, timestamp
geoleaf:map:readyMapLibre map created
geoleaf:profile:loadedJSON profile fully loadedprofileId, data
geoleaf:basemap:changeBasemap changedkey, previousKey
geoleaf:theme:appliedTheme applied (layers loaded)themeName, layerCount
geoleaf:poi:clickPOI marker clickedpoiId, layerId, source
geoleaf:poi:panel:openSide panel opened on a POIpoiId, poiName
geoleaf:poi:panel:closeSide panel closedpoiId
geoleaf:layer:toggleLayer shown or hiddenlayerId, visible, source
geoleaf:filter:applyFilter applied to featureslayerIds, geometryType?, activeCount
geoleaf:filter:resetFilter reset (everything visible)layerIds
geoleaf:map:moveMap panned (MapLibre moveend)center.lat, center.lng, zoom
geoleaf:map:zoomZoom changed (MapLibre zoomend)zoom, oldZoom, center
geoleaf:plugin:loadedPlugin registered synchronouslyname, version
geoleaf:plugin:lazy-loadedLazy plugin loaded asynchronouslyname
geoleaf:plugin:failedLazy plugin failed to loadname, error
geoleaf:popup:actionPopup action button clickedactionId, layerId, featureId, properties, lngLat?

geoleaf:popup:action

Dispatched on document on every click of a popup action button (renderer type: "action" in popup.fields[], rendered by @geoleaf-plugins/feature-info). This is the only channel for reacting to a popup action — loosely coupled listeners (analytics, host integration, backend).

Payload (e.detail):

FieldTypeDescription
actionIdstringOpaque action identifier (token ^[A-Za-z0-9:_-]{1,64}$), as defined in the configuration.
layerIdstringIdentifier of the layer/source of the clicked feature.
featureIdstringIdentifier of the feature (GeoJSON feature or POI).
propertiesobjectSubset of the feature properties, bounded by payloadFields (default: id, name, title, label).
lngLatobject?[lng, lat] coordinates of the popup anchor point (optional).

The payload is serialisable (JSON only): no DOM reference and no function.

ts
GeoLeaf.Events.on("geoleaf:popup:action", (e) => {
    const { actionId, layerId, featureId } = e.detail;
    if (actionId === "odoo:open-form") {
        _paq.push(["trackEvent", "Popup", "Action", actionId]);
    }
});

Integration examples

Analytics — Matomo

ts
GeoLeaf.Events.on("geoleaf:poi:click", (e) => {
    _paq.push(["trackEvent", "Map", "POI Click", e.detail.poiId]);
});
GeoLeaf.Events.on("geoleaf:filter:apply", (e) => {
    _paq.push(["trackEvent", "Map", "Filter Apply", e.detail.activeCount.toString()]);
});

Analytics — Google Analytics 4

ts
GeoLeaf.Events.on("geoleaf:map:move", (e) => {
    gtag("event", "map_pan", { lat: e.detail.center.lat, lng: e.detail.center.lng });
});
GeoLeaf.Events.on("geoleaf:layer:toggle", (e) => {
    gtag("event", "layer_toggle", { layer_id: e.detail.layerId, visible: e.detail.visible });
});

Removing listeners

ts
const handlePoiClick = (e) => {
    /* ... */
};
GeoLeaf.Events.on("geoleaf:poi:click", handlePoiClick);

// Later:
GeoLeaf.Events.off("geoleaf:poi:click", handlePoiClick);

Security notes

  • Payloads contain primitives only (string, number, boolean). No DOM references.
  • The error carried by plugin:failed is truncated to 200 characters to avoid leaking stack traces.
  • SSR-safe: calls are silent when document is undefined.

Released under the MIT License.