Files
gods-eye-view/src/layers/alpr/model.js
T
Sameh Khamis f6ed35a887 Compute ALPR bearings and wedge corners without Cesium
The ALPR model's great-circle destination and the direction wedge's
corners now come from src/geo: the same numbers, the corners plain ECEF
rather than Cesium objects, which the overlay projects as before. Both
files leave the Cesium allow-list.
2026-11-06 20:39:41 -08:00

47 lines
1.7 KiB
JavaScript

import { toDegrees, toRadians } from '../../geo/index.js';
import { EARTH_MEAN_RADIUS_M } from './policy.js';
export * from './records.js';
/**
* Great-circle destination point — used only to draw the short
* facing-direction line when a node carries `camera:direction`/`direction`.
* @param {number} latDeg @param {number} lonDeg
* @param {number} bearingDeg Compass bearing, degrees clockwise from north.
* @param {number} distanceM
* @returns {{latitude:number, longitude:number}}
*/
export function destinationPointDeg(latDeg, lonDeg, bearingDeg, distanceM) {
const angularDistance = distanceM / EARTH_MEAN_RADIUS_M;
const bearing = toRadians(bearingDeg);
const lat1 = toRadians(latDeg);
const lon1 = toRadians(lonDeg);
const lat2 = Math.asin(
Math.sin(lat1) * Math.cos(angularDistance) +
Math.cos(lat1) * Math.sin(angularDistance) * Math.cos(bearing),
);
const lon2 =
lon1 +
Math.atan2(
Math.sin(bearing) * Math.sin(angularDistance) * Math.cos(lat1),
Math.cos(angularDistance) - Math.sin(lat1) * Math.sin(lat2),
);
return {
latitude: toDegrees(lat2),
longitude: toDegrees(lon2),
};
}
/**
* The on-map credit for the renderer's credits port, from plain text and an
* HTTPS URL only; the port escapes it as it shows it.
* @returns {{text: string, href: string, inline: true}|null}
*/
export function alprCredit(attribution) {
if (!attribution?.text || !attribution?.href) return null;
const href = new URL(attribution.href);
if (href.protocol !== 'https:' || href.username || href.password) {
throw new TypeError('Camera attribution requires a public HTTPS link');
}
return { text: `ALPR: ${attribution.text}`, href: href.href, inline: true };
}