mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
- 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
56 lines
1.6 KiB
JavaScript
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 }
|
|
: {}),
|
|
};
|
|
}
|