mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
refactor: separate map feature queries and source records
This commit is contained in:
1 parent
a8125ad917
commit
bf1d50f29b
28 files changed
+1128
-675
No files matched your search
@@ -1,5 +1,3 @@
|
||||
import { normalizeMilitaryInstallations } from '../../data/militaryInstallationData.js';
|
||||
|
||||
export function createIngestion({
|
||||
state: layerState,
|
||||
services,
|
||||
@@ -58,19 +56,15 @@ export function createIngestion({
|
||||
// A SATURATED snapped tile was truncated upstream, so features from the
|
||||
// snap's extra ring may have crowded out sites actually on screen. Re-ask
|
||||
// for the exact viewport (separately keyed and cached) before rendering.
|
||||
let saturated = parts.model.installationResponseSaturated(payload);
|
||||
let saturated = payload.saturated === true;
|
||||
if (saturated) {
|
||||
payload = await fetchInstallations(true);
|
||||
saturated = parts.model.installationResponseSaturated(payload);
|
||||
saturated = payload.saturated === true;
|
||||
}
|
||||
const normalized = normalizeMilitaryInstallations(
|
||||
payload,
|
||||
payload.retrievedAt || new Date().toISOString(),
|
||||
);
|
||||
// The proxy answers a bbox at least as large as the viewport; keep only what
|
||||
// was actually asked for so nothing off-screen reaches the map or the
|
||||
// "current viewport only" context claim.
|
||||
const records = normalized.records.filter((record) =>
|
||||
const records = payload.records.filter((record) =>
|
||||
parts.model.installationWithinViewport(record, box),
|
||||
);
|
||||
let placesError = null;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { installationResponseSaturated } from './source.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
EARTH_MEAN_RADIUS_M,
|
||||
@@ -137,23 +138,6 @@ export function createModel({ state: layerState, services, parts, source }) {
|
||||
return record.osmType !== 'node';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a response was truncated at the upstream element cap.
|
||||
*
|
||||
* The proxy states this outright, but a `saturated`-less payload is NOT
|
||||
* evidence of a complete answer: entries cached before the saturation guard
|
||||
* shipped predate the field and live for 30 days. Fall back to deriving it from
|
||||
* the element count against the cap the payload itself reports.
|
||||
* @param {{saturated?: boolean, elements?: Array, elementCap?: number}} payload
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
function installationResponseSaturated(payload) {
|
||||
if (typeof payload?.saturated === 'boolean') return payload.saturated;
|
||||
const cap = Number(payload?.elementCap);
|
||||
if (!Number.isFinite(cap) || cap <= 0) return false;
|
||||
return Array.isArray(payload?.elements) && payload.elements.length >= cap;
|
||||
}
|
||||
return {
|
||||
approximateSurfaceDistanceM,
|
||||
colorFor,
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
import { normalizeMilitaryInstallations } from '../../data/militaryInstallationData.js';
|
||||
|
||||
/** Preserve legacy cache admission even when the explicit saturation flag is absent. */
|
||||
export function installationResponseSaturated(payload) {
|
||||
if (typeof payload?.saturated === 'boolean') return payload.saturated;
|
||||
const cap = Number(payload?.elementCap);
|
||||
if (!Number.isFinite(cap) || cap <= 0) return false;
|
||||
return Array.isArray(payload?.elements) && payload.elements.length >= cap;
|
||||
}
|
||||
|
||||
/** Read mapped installations and explicit nearby-place searches through fixed endpoints. */
|
||||
export function createInstallationSource({
|
||||
fetchImpl = (...args) => globalThis.fetch(...args),
|
||||
@@ -43,7 +53,14 @@ export function createInstallationSource({
|
||||
);
|
||||
if (!Array.isArray(body?.elements))
|
||||
throw new Error('Malformed installation snapshot');
|
||||
return body;
|
||||
return {
|
||||
...normalizeMilitaryInstallations(
|
||||
body,
|
||||
body.retrievedAt || new Date().toISOString(),
|
||||
),
|
||||
status: body.status,
|
||||
saturated: installationResponseSaturated(body),
|
||||
};
|
||||
},
|
||||
async searchNearby({ latitude, longitude, radiusM }, { signal } = {}) {
|
||||
if (
|
||||
|
||||
@@ -57,3 +57,30 @@ test('installation response parsing respects cancellation before any follow-on s
|
||||
{ name: 'AbortError' },
|
||||
);
|
||||
});
|
||||
|
||||
test('mapped-site sources normalize records and derive saturation from legacy cache metadata', async () => {
|
||||
const source = createInstallationSource({
|
||||
fetchImpl: async () =>
|
||||
Response.json({
|
||||
elements: [
|
||||
{
|
||||
type: 'node',
|
||||
id: 1,
|
||||
lat: 30.2,
|
||||
lon: -97.7,
|
||||
tags: { military: 'airfield', name: 'Fixture Field' },
|
||||
},
|
||||
],
|
||||
elementCap: 1,
|
||||
status: 'stale',
|
||||
retrievedAt: '2026-01-01T00:00:00Z',
|
||||
}),
|
||||
});
|
||||
const payload = await source.getMappedSites(box);
|
||||
assert.equal(payload.records[0].name, 'Fixture Field');
|
||||
assert.equal(payload.records[0].latitude, 30.2);
|
||||
assert.equal(payload.records[0].retrievedAt, '2026-01-01T00:00:00Z');
|
||||
assert.equal(payload.saturated, true);
|
||||
assert.equal(payload.status, 'stale');
|
||||
assert.equal('elements' in payload, false);
|
||||
});
|
||||
Reference in new issue
Block a user