mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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
This commit is contained in:
1 parent
01979bba1e
commit
b234d7b427
84 files changed
+14262
-1681
No files matched your search
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Browser client for `/api/osm/features`: one curated preset inside a box,
|
||||
* as a count or as features. The server writes and bounds the Overpass
|
||||
* query and answers only when an operator configured Overpass; this only
|
||||
* names the preset, box, mode and limit.
|
||||
* @module sources/osmFeatures
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {{fetchImpl?: typeof fetch, endpoint?: string}} [options]
|
||||
* @returns {(request: {preset: string, bbox: number[], mode?: 'count'|'features', limit?: number}, options?: {signal?: AbortSignal}) => Promise<object>}
|
||||
*/
|
||||
export function createOsmFeatureSource({
|
||||
fetchImpl = (...args) => globalThis.fetch(...args),
|
||||
endpoint = '/api/osm/features',
|
||||
} = {}) {
|
||||
return async function searchOsmFeatures(
|
||||
{ preset, bbox, mode = 'features', limit },
|
||||
{ signal } = {},
|
||||
) {
|
||||
const params = new URLSearchParams({
|
||||
preset,
|
||||
bbox: bbox.map((v) => Number(v).toFixed(5)).join(','),
|
||||
mode,
|
||||
});
|
||||
if (Number.isFinite(limit)) params.set('limit', String(limit));
|
||||
let response;
|
||||
try {
|
||||
response = await fetchImpl(`${endpoint}?${params}`, { signal });
|
||||
} catch (error) {
|
||||
if (signal?.aborted) throw error;
|
||||
return {
|
||||
ok: false,
|
||||
status: 0,
|
||||
error: 'OpenStreetMap search is unreachable.',
|
||||
};
|
||||
}
|
||||
let body = null;
|
||||
try {
|
||||
body = await response.json();
|
||||
} catch {
|
||||
body = null;
|
||||
}
|
||||
if (!response.ok)
|
||||
return {
|
||||
ok: false,
|
||||
status: response.status,
|
||||
code: body?.code || null,
|
||||
error:
|
||||
body?.error || `OpenStreetMap search failed (${response.status}).`,
|
||||
};
|
||||
return { ok: true, ...body };
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user