Files
gods-eye-view/src/voice/layerActionOwnership.js
T
manjunath22466 b234d7b427 feat(voice): add reusable geometry actions
- turn named places and mapped landmarks into reusable bounded areas
- count loaded records inside resolved, drawn and annotated geometry
- find recent imagery for an area, the view or the pointer snapshot
- keep osm place search behind an operator-configured overpass endpoint
- preserve cancellation, ownership and follow-up memory across every action
- cover geometry, provider lifecycle, cache isolation and voice routing
2026-10-03 10:23:38 +05:30

56 lines
1.6 KiB
JavaScript

/**
* Observe an explicit request to turn a layer off while a feature action is
* pending. The visibility-request stream is synchronous, so an OFF owns the
* action even before the layer's queued lifecycle work settles.
*
* @module voice/layerActionOwnership
*/
const EXPLICIT_OFF_ORIGINS = new Set(['user', 'voice', 'tool']);
export function watchExplicitLayerOff(dataManager, layerId, { onOff } = {}) {
let requested = false;
const observe = (change) => {
if (
change?.layerId === layerId &&
change.enabled === false &&
EXPLICIT_OFF_ORIGINS.has(change.origin)
) {
requested = true;
onOff?.(change);
}
};
const stopRequest =
dataManager?.subscribeVisibilityRequests?.(observe) || (() => {});
// Lightweight managers sometimes expose only the settled change stream.
const stopSettled = dataManager?.subscribe?.(observe) || (() => {});
return {
requested: () => requested,
stop() {
stopRequest();
stopSettled();
},
};
}
export function displacedLayerResult(dataManager, layerId, action, error) {
const state = dataManager?.getLayerLifecycleState?.(layerId);
return {
ok: false,
action,
code: 'DISPLACED',
cancelled: true,
layerId,
requestedEnabled: false,
error,
enabled:
typeof state?.enabled === 'boolean'
? state.enabled
: Boolean(dataManager?.isEnabled?.(layerId)),
...(state?.lifecycleState ? { lifecycleState: state.lifecycleState } : {}),
...(typeof state?.uncertain === 'boolean'
? { lifecycleUncertain: state.uncertain }
: {}),
};
}