Skip to main content

Query registered event listeners

MapLibre-shaped map.listens(type):boolean synchronously checks for at least one listener owned by the current facade or its parent event chain. It neither submits a map command nor subscribes. Regular on,once callbacks,once Promise waits and delegated layer listeners count. Valid custom names return false when no listener exists; names must contain 1–128 characters or fail with INVALID_ARGUMENT.

const handler=event=>console.log(event.type);
const subscription=map.on('move',handler);
console.log(map.listens('move')); // true
subscription.unsubscribe();
console.log(map.listens('move')); // false
const next=map.once('move');
console.log(map.listens('move')); // true
map.setCenter([116.4,39.9]);
await map.sqs.flush();
await next;
console.log(map.listens('move')); // false

Once removes its listener before invoking a callback. Promise completion,off and unsubscribe are reflected synchronously. Duplicate on retains existing deduplication; registered delegates count even when their layers are unavailable or invisible. Querying performs no feature hit test. Script stop and map destruction clear owned listeners.

Facades have independent tables. Common scripts and retained native QuickJS query their own facade and explicit parent chain. Direct SDK queries count listeners attached to that MapView and its explicit parent chain,including forwarding observers installed by a script host,without aggregating another script's private table. The old GIS facade counts its own old events. Legacy one-shot native event APIs remain unavailable. SDK queries read realm-owned state without a Worker round trip.

Theidentical twelve-check script andcomplete HTML cover actual move delivery,once callback/Promise completion,cleanup,invalid arguments and layer delegates; the page adds ten direct SDK/destruction checks. Run within the complete matching SDK directory. Custom events, fire and parent chains are now implemented; see Evented and its shared 24-check script. Applications still build their own layer/tool UI.

Syntax followsMapLibre Evented.listens; SqsMap now supports listener queries and forwarding through explicit parent chains.