mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
The drag-fixture framing looked the gizmo up in viewer.entities, which main no longer populates, so it did nothing and five drag checks stayed inconclusive. It now reads the arrow from the layer's drawn state and records the framed shaft length as a check. Tarktee and Lithuania read their two catalogs through one helper, readCatalogsTogether, so both get the shared deadline, sibling abort and the release of a response that arrives after the other feed failed. An Ontario error response has its body released, and tests pin the refused redirect and system-code log labels.
131 lines
4.2 KiB
JavaScript
131 lines
4.2 KiB
JavaScript
import { CCTV_SOURCE_FETCH_TIMEOUT_MS } from './constants.js';
|
|
import {
|
|
cameraDisplayCode,
|
|
fallbackHeadingFromId,
|
|
prioritizeSources,
|
|
} from './normalize.js';
|
|
import { readCatalogsTogether } from './catalogPair.js';
|
|
|
|
const BASE = 'https://eismoinfo.lt/eismoinfo-backend';
|
|
export const LITHUANIA_CAMERAS_URL = `${BASE}/camera-info-table`;
|
|
// Without lks=true this endpoint returns [latitude, longitude]. The camera
|
|
// table's x/y fields use LKS-94 metres and must never be treated as degrees.
|
|
export const LITHUANIA_LOCATIONS_URL = `${BASE}/layer-static-features/VKR`;
|
|
export const LITHUANIA_MAX_CATALOG_BYTES = 4 * 1024 * 1024;
|
|
const FRAME_PATH = '/eismoinfo-backend/image-provider/camera/last';
|
|
const ANCHORS = [
|
|
{ lat: 54.6872, lon: 25.2797 }, // Vilnius
|
|
{ lat: 54.8985, lon: 23.9036 }, // Kaunas
|
|
{ lat: 55.7033, lon: 21.1443 }, // Klaipeda
|
|
{ lat: 55.9349, lon: 23.3137 }, // Siauliai
|
|
{ lat: 55.7348, lon: 24.3575 }, // Panevezys
|
|
];
|
|
|
|
/** Join public catalogs by ID; register only the official still endpoint. */
|
|
export function lithuaniaCameraToSource(row, feature) {
|
|
const id = String(row?.id ?? '');
|
|
if (!/^[1-9]\d{0,8}$/.test(id) || String(feature?.id) !== id) return null;
|
|
const point = feature?.points?.[0]?.point;
|
|
if (!Array.isArray(point) || point.length !== 2) return null;
|
|
const [lat, lon] = point;
|
|
if (
|
|
!Number.isFinite(lat) ||
|
|
!Number.isFinite(lon) ||
|
|
lat < 53.8 ||
|
|
lat > 56.5 ||
|
|
lon < 20.8 ||
|
|
lon > 26.9
|
|
)
|
|
return null;
|
|
try {
|
|
const url = new URL(row.image);
|
|
if (
|
|
url.origin !== 'https://eismoinfo.lt' ||
|
|
url.username ||
|
|
url.password ||
|
|
url.pathname !== FRAME_PATH ||
|
|
url.searchParams.get('id') !== id
|
|
)
|
|
return null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
// Reconstruct so extra query parameters cannot alter the request.
|
|
const imageUrl = `https://eismoinfo.lt${FRAME_PATH}?id=${id}`;
|
|
const cameraId = `lithuania-${id}`;
|
|
const name = String(row.name || feature.name || `Lietuva ${id}`)
|
|
.trim()
|
|
.slice(0, 160);
|
|
return {
|
|
id: cameraId,
|
|
name,
|
|
city: 'Lithuania / Lietuva',
|
|
cityId: 'lithuania',
|
|
provider: 'Via Lietuva / Eismoinfo',
|
|
lat,
|
|
lon,
|
|
// No calibrated pose is published; use the app's low-confidence prior.
|
|
headingDeg: fallbackHeadingFromId(cameraId),
|
|
headingConfidence: 'low',
|
|
pitchDeg: -18,
|
|
fovDeg: 44,
|
|
rangeM: 145,
|
|
mountHeightM: 8,
|
|
feedType: 'image',
|
|
url: imageUrl,
|
|
snapshotUrl: imageUrl,
|
|
sourceKind: 'eismoinfo-public',
|
|
credit:
|
|
'Via Lietuva / eismoinfo.lt — periodically updated road-camera stills',
|
|
code: cameraDisplayCode(name.toUpperCase()),
|
|
};
|
|
}
|
|
|
|
/** Two bounded requests per shared catalog refresh, no API key required. */
|
|
export async function loadLithuaniaSources() {
|
|
try {
|
|
const [rows, layers] = (
|
|
await readCatalogsTogether(
|
|
[
|
|
{ url: LITHUANIA_CAMERAS_URL, label: 'cameras' },
|
|
{ url: LITHUANIA_LOCATIONS_URL, label: 'locations' },
|
|
],
|
|
{
|
|
accept: 'application/json',
|
|
maxBytes: LITHUANIA_MAX_CATALOG_BYTES,
|
|
timeoutMs: CCTV_SOURCE_FETCH_TIMEOUT_MS,
|
|
},
|
|
)
|
|
).map((text) => JSON.parse(text));
|
|
if (!Array.isArray(rows) || !Array.isArray(layers)) return [];
|
|
const features = layers.find((layer) => layer?.layer === 'VKR')?.features;
|
|
if (!Array.isArray(features)) return [];
|
|
const locations = new Map(
|
|
features.filter(Boolean).map((feature) => [String(feature.id), feature]),
|
|
);
|
|
const cameras = new Map();
|
|
for (const row of rows) {
|
|
const camera = lithuaniaCameraToSource(
|
|
row,
|
|
locations.get(String(row?.id)),
|
|
);
|
|
if (camera && !cameras.has(camera.id)) cameras.set(camera.id, camera);
|
|
}
|
|
const rawCap = Number(process.env.CCTV_LITHUANIA_MAX_SOURCES || 400);
|
|
const cap = Number.isFinite(rawCap)
|
|
? Math.max(1, Math.min(1000, Math.floor(rawCap)))
|
|
: 400;
|
|
const sources = prioritizeSources([...cameras.values()], cap, ANCHORS);
|
|
console.log(
|
|
`[CCTV] Loaded Lithuania camera sources: ${cameras.size} (using ${sources.length})`,
|
|
);
|
|
return sources;
|
|
} catch (error) {
|
|
console.warn(
|
|
'[CCTV] Lithuania camera download error:',
|
|
error?.message || error,
|
|
);
|
|
return [];
|
|
}
|
|
}
|