mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge branch 'main' into upstream/route-outage-unavailable
This commit is contained in:
commit
a29611ca17
422 files changed
+53860
-1931
No files matched your search
@@ -94,7 +94,8 @@ export const getActiveFires = defineTool({
|
||||
name: 'get_active_fires',
|
||||
title: 'Active fires',
|
||||
description:
|
||||
'Satellite fire detections from NASA FIRMS in the last 24 hours within an ' +
|
||||
'Satellite fire detections from NASA FIRMS in the last 24 hours (or the 24 ' +
|
||||
'hours to window_end, when the source names one) within an ' +
|
||||
'area, most intense (fire radiative power) first. Optionally limited to a ' +
|
||||
'minimum fire radiative power in megawatts and a confidence level — the ' +
|
||||
"same filter as the Active Fires layer's intensity controls.",
|
||||
@@ -171,7 +172,10 @@ export const getActiveFires = defineTool({
|
||||
summary:
|
||||
`${countNoun(fires.length, 'fire detection')}` +
|
||||
(filterNotes.length ? ` (${filterNotes.join(', ')})` : '') +
|
||||
` in ${area.label} in the last 24 hours` +
|
||||
` in ${area.label} ` +
|
||||
(Number.isFinite(snapshot.at)
|
||||
? `in the 24 hours to ${isoTime(snapshot.at)}`
|
||||
: 'in the last 24 hours') +
|
||||
(notes.length ? ` (${notes.join('; ')}).` : '.'),
|
||||
data: {
|
||||
view: suggestView(services, { area, layers: ['local-firms'] }),
|
||||
@@ -182,6 +186,7 @@ export const getActiveFires = defineTool({
|
||||
stale,
|
||||
missing_sources: missing,
|
||||
fetched_at: isoTime(snapshot.fetchedAt),
|
||||
window_end: Number.isFinite(snapshot.at) ? isoTime(snapshot.at) : null,
|
||||
...result,
|
||||
rows: result.rows.map((fire) => ({
|
||||
lat: fire.lat,
|
||||
|
||||
@@ -46,29 +46,80 @@ test('fire acquisition timestamps preserve valid leap days and UTC times', async
|
||||
});
|
||||
|
||||
const WEEK = [
|
||||
{ lat: 24.1, lon: 121.1, frp: 864, confidence: 'l', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 24.2, lon: 121.2, frp: 120, confidence: 'h', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 24.3, lon: 121.3, frp: 20, confidence: 'n', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 24.4, lon: 121.4, frp: 2, confidence: 'h', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 30, lon: 100, frp: 500, confidence: 'h', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{
|
||||
lat: 24.1,
|
||||
lon: 121.1,
|
||||
frp: 864,
|
||||
confidence: 'l',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 24.2,
|
||||
lon: 121.2,
|
||||
frp: 120,
|
||||
confidence: 'h',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 24.3,
|
||||
lon: 121.3,
|
||||
frp: 20,
|
||||
confidence: 'n',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 24.4,
|
||||
lon: 121.4,
|
||||
frp: 2,
|
||||
confidence: 'h',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 30,
|
||||
lon: 100,
|
||||
frp: 500,
|
||||
confidence: 'h',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
];
|
||||
const TAIWAN = { area: { bbox: [120, 23, 122, 25] } };
|
||||
|
||||
test('get_active_fires shows every detection by default and reports the filter it used', async () => {
|
||||
const result = await catalogWith(WEEK).call('get_active_fires', TAIWAN);
|
||||
assert.deepEqual(result.data.rows.map((row) => row.frp_mw), [864, 120, 20, 2]);
|
||||
assert.deepEqual(
|
||||
result.data.rows.map((row) => row.frp_mw),
|
||||
[864, 120, 20, 2],
|
||||
);
|
||||
assert.deepEqual(result.data.filter, { min_frp_mw: 0, confidence: 'all' });
|
||||
assert.match(result.summary, /^4 fire detections in /);
|
||||
});
|
||||
|
||||
test('get_active_fires applies the same minimum-FRP and confidence filter as the layer', async () => {
|
||||
const catalog = catalogWith(WEEK);
|
||||
const strong = await catalog.call('get_active_fires', { ...TAIWAN, min_frp_mw: 20 });
|
||||
assert.deepEqual(strong.data.rows.map((row) => row.frp_mw), [864, 120, 20]);
|
||||
const strong = await catalog.call('get_active_fires', {
|
||||
...TAIWAN,
|
||||
min_frp_mw: 20,
|
||||
});
|
||||
assert.deepEqual(
|
||||
strong.data.rows.map((row) => row.frp_mw),
|
||||
[864, 120, 20],
|
||||
);
|
||||
assert.match(strong.summary, /^3 fire detections \(≥ 20 MW\) in /);
|
||||
|
||||
const nominal = await catalog.call('get_active_fires', { ...TAIWAN, confidence: 'nominal' });
|
||||
assert.deepEqual(nominal.data.rows.map((row) => row.frp_mw), [120, 20, 2], 'the 864 MW low-confidence fire drops');
|
||||
const nominal = await catalog.call('get_active_fires', {
|
||||
...TAIWAN,
|
||||
confidence: 'nominal',
|
||||
});
|
||||
assert.deepEqual(
|
||||
nominal.data.rows.map((row) => row.frp_mw),
|
||||
[120, 20, 2],
|
||||
'the 864 MW low-confidence fire drops',
|
||||
);
|
||||
assert.match(nominal.summary, /\(nominal or high confidence\)/);
|
||||
|
||||
const both = await catalog.call('get_active_fires', {
|
||||
@@ -76,7 +127,27 @@ test('get_active_fires applies the same minimum-FRP and confidence filter as the
|
||||
min_frp_mw: 19.6,
|
||||
confidence: 'high',
|
||||
});
|
||||
assert.deepEqual(both.data.rows.map((row) => row.frp_mw), [120]);
|
||||
assert.deepEqual(
|
||||
both.data.rows.map((row) => row.frp_mw),
|
||||
[120],
|
||||
);
|
||||
assert.deepEqual(both.data.filter, { min_frp_mw: 20, confidence: 'high' });
|
||||
assert.match(both.summary, /\(≥ 20 MW, high confidence\)/);
|
||||
});
|
||||
|
||||
test('get_active_fires names the end of a snapshot that ends at a set time', async () => {
|
||||
const at = Date.UTC(2026, 9, 1, 3);
|
||||
const catalog = composeCatalog({
|
||||
tools: [getActiveFires],
|
||||
services: { fires: { getSnapshot: async () => ({ fires: WEEK, at }) } },
|
||||
});
|
||||
const result = await catalog.call('get_active_fires', TAIWAN);
|
||||
assert.match(
|
||||
result.summary,
|
||||
/in the 24 hours to 2026-10-01T03:00:00\.000Z\.$/,
|
||||
);
|
||||
assert.equal(result.data.window_end, '2026-10-01T03:00:00.000Z');
|
||||
const now = await catalogWith(WEEK).call('get_active_fires', TAIWAN);
|
||||
assert.match(now.summary, /in the last 24 hours\.$/);
|
||||
assert.equal(now.data.window_end, null);
|
||||
});
|
||||
@@ -28,6 +28,14 @@ const MMSI_SCHEMA = Object.freeze({
|
||||
pattern: '^\\d{5,10}$',
|
||||
description: 'Maritime Mobile Service Identity, such as "366999712".',
|
||||
});
|
||||
const VESSEL_ID_SCHEMA = Object.freeze({
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
maxLength: 128,
|
||||
description:
|
||||
'The vessel id a vessel search returned. Vessels can share an MMSI; ' +
|
||||
'the id names one of them.',
|
||||
});
|
||||
const MAX_TRACK_POINTS = 200;
|
||||
const ALL_VESSELS = 1_000_000;
|
||||
|
||||
@@ -47,10 +55,13 @@ const vesselDestination = (value) => {
|
||||
return destination && /\p{L}/u.test(destination) ? destination : null;
|
||||
};
|
||||
|
||||
// `id` is the vessel's key; `mmsi` is its MMSI when known (vessels can share
|
||||
// one), else null.
|
||||
function vesselRow(record, from) {
|
||||
const point = { lat: record.latitude, lon: record.longitude };
|
||||
return {
|
||||
mmsi: record.id,
|
||||
id: record.id,
|
||||
mmsi: text(record.mmsi),
|
||||
name: text(record.name),
|
||||
imo: text(record.imo),
|
||||
type: vesselType(record.type),
|
||||
@@ -194,7 +205,7 @@ export const findVessel = defineTool({
|
||||
const [key] = given;
|
||||
const wanted = args[key].trim().toUpperCase();
|
||||
const matches = {
|
||||
mmsi: (record) => record.id === wanted,
|
||||
mmsi: (record) => String(record.mmsi ?? '') === wanted,
|
||||
imo: (record) => String(record.imo).replace(/^IMO/i, '') === wanted,
|
||||
name: (record) => String(record.name).toUpperCase().includes(wanted),
|
||||
}[key];
|
||||
@@ -227,25 +238,40 @@ export const getVesselTrack = defineTool({
|
||||
name: 'get_vessel_track',
|
||||
title: 'Vessel track',
|
||||
description:
|
||||
'Recent positions of one ship by MMSI, oldest first. Long tracks are ' +
|
||||
`evenly thinned to at most ${MAX_TRACK_POINTS} points.`,
|
||||
'Recent positions of one ship by its vessel id or MMSI, oldest first. ' +
|
||||
`Long tracks are evenly thinned to at most ${MAX_TRACK_POINTS} points.`,
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: { mmsi: MMSI_SCHEMA },
|
||||
required: ['mmsi'],
|
||||
properties: { id: VESSEL_ID_SCHEMA, mmsi: MMSI_SCHEMA },
|
||||
additionalProperties: false,
|
||||
},
|
||||
requires: ['vessels'],
|
||||
async run(args, { services, signal }) {
|
||||
const track = await services.vessels.getTrack(args.mmsi, { signal });
|
||||
const given = ['id', 'mmsi'].filter((key) => args[key] != null);
|
||||
if (given.length !== 1)
|
||||
throw new ToolError(
|
||||
'invalid_arguments',
|
||||
'Give exactly one of id or mmsi',
|
||||
);
|
||||
const [key] = given;
|
||||
const wanted = String(args[key]).trim();
|
||||
// A track is asked for by the source's reference for the vessel, which
|
||||
// for an id is the reported vessel's; an MMSI is passed as it is.
|
||||
let reference = wanted;
|
||||
if (key === 'id') {
|
||||
const snapshot = await readVessels(services, signal);
|
||||
const record = snapshot.records.find((item) => item.id === wanted);
|
||||
reference = record?.reference ?? wanted;
|
||||
}
|
||||
const track = await services.vessels.getTrack(reference, { signal });
|
||||
const points = track.records
|
||||
.filter((point) => Number.isFinite(point.observedAtMs))
|
||||
.sort((a, b) => a.observedAtMs - b.observedAtMs);
|
||||
const kept = thinEvenly(points, MAX_TRACK_POINTS);
|
||||
return {
|
||||
summary: points.length
|
||||
? `${countNoun(points.length, 'position')} for ${args.mmsi} from ${isoTime(points[0].observedAtMs)} to ${isoTime(points.at(-1).observedAtMs)}.`
|
||||
: `No recent track is available for ${args.mmsi}.`,
|
||||
? `${countNoun(points.length, 'position')} for ${wanted} from ${isoTime(points[0].observedAtMs)} to ${isoTime(points.at(-1).observedAtMs)}.`
|
||||
: `No recent track is available for ${wanted}.`,
|
||||
data: {
|
||||
view: kept.length
|
||||
? suggestView(services, {
|
||||
@@ -254,7 +280,7 @@ export const getVesselTrack = defineTool({
|
||||
altitudeM: 20_000,
|
||||
})
|
||||
: null,
|
||||
mmsi: args.mmsi,
|
||||
...(key === 'id' ? { id: wanted } : { mmsi: wanted }),
|
||||
total: points.length,
|
||||
returned: kept.length,
|
||||
thinned: kept.length < points.length,
|
||||
|
||||
@@ -5,8 +5,10 @@ import { LiveSourceError } from '../../sources/live/contract.js';
|
||||
import { createVesselSource } from '../../sources/live/standalone.js';
|
||||
import { AISSTREAM_CACHE_MAX } from '../../../server/providers/vessels/ais-store.js';
|
||||
|
||||
// An AIS source's vessel: keyed by its MMSI, which it also reports.
|
||||
const vessel = (id, latitude, longitude, extra = {}) => ({
|
||||
id,
|
||||
mmsi: id,
|
||||
reference: id,
|
||||
latitude,
|
||||
longitude,
|
||||
@@ -79,6 +81,7 @@ test('vessels in an area are nearest first and filterable by type', async () =>
|
||||
['366999712', '538001234'],
|
||||
);
|
||||
assert.deepEqual(all.data.rows[0], {
|
||||
id: '366999712',
|
||||
mmsi: '366999712',
|
||||
name: 'GOLDEN BEAR',
|
||||
imo: '9123456',
|
||||
@@ -164,6 +167,53 @@ test('vessel tracks are ordered and drop untimed positions', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('vessels sharing an MMSI are found as two, each by its own id', async () => {
|
||||
const shared = [
|
||||
vessel('hull-a', 37.81, -122.41, { mmsi: '366999712', name: 'A' }),
|
||||
vessel('hull-b', 37.79, -122.42, {
|
||||
mmsi: '366999712',
|
||||
name: 'B',
|
||||
reference: 'track:hull-b',
|
||||
}),
|
||||
vessel('hull-c', 37.8, -122.4, { mmsi: undefined, name: 'C' }),
|
||||
];
|
||||
const tracks = [];
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: {
|
||||
vessels: {
|
||||
getSnapshot: async () => ({ records: shared, freshness: 'current' }),
|
||||
getTrack: async (reference) => {
|
||||
tracks.push(reference);
|
||||
return { records: [] };
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const found = await catalog.call('find_vessel', { mmsi: '366999712' });
|
||||
assert.deepEqual(
|
||||
found.data.rows.map((row) => [row.id, row.mmsi]),
|
||||
[
|
||||
['hull-a', '366999712'],
|
||||
['hull-b', '366999712'],
|
||||
],
|
||||
);
|
||||
const area = await catalog.call('vessels_in_area', { area: bay });
|
||||
assert.deepEqual(
|
||||
area.data.rows.find((row) => row.id === 'hull-c').mmsi,
|
||||
null,
|
||||
'a vessel with no MMSI says so',
|
||||
);
|
||||
const track = await catalog.call('get_vessel_track', { id: 'hull-b' });
|
||||
assert.deepEqual(tracks, ['track:hull-b'], "asked by the vessel's reference");
|
||||
assert.equal(track.data.id, 'hull-b');
|
||||
assert.equal(track.summary, 'No recent track is available for hull-b.');
|
||||
await assert.rejects(
|
||||
catalog.call('get_vessel_track', { id: 'hull-b', mmsi: '366999712' }),
|
||||
/exactly one/,
|
||||
);
|
||||
});
|
||||
|
||||
test('a missing AIS key surfaces as an unavailable feed', async () => {
|
||||
const keyless = {
|
||||
getSnapshot: async () => {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/** Links that open God's Eye View at a view. */
|
||||
|
||||
import { VIEW_PROPERTIES, createView, viewUrl } from '../../view/index.js';
|
||||
import {
|
||||
VIEW_PROPERTIES,
|
||||
createView,
|
||||
groundedLookAt,
|
||||
viewUrl,
|
||||
} from '../../view/index.js';
|
||||
import { defineTool, ToolError } from '../catalog.js';
|
||||
import { GLOBE_PANEL_URI } from '../globePanel.js';
|
||||
import { AREA_SCHEMA, resolveArea } from '../area.js';
|
||||
@@ -47,10 +52,31 @@ export async function resolveViewArguments(args, { services, signal, tools }) {
|
||||
? { ...args.camera }
|
||||
: { ...base.camera, ...args.camera };
|
||||
let label = null;
|
||||
// Street-level photos open at the area's centre unless a point is given;
|
||||
// a new area or camera position moves a passed-through view's photos with
|
||||
// it.
|
||||
const moved =
|
||||
Boolean(args.area) ||
|
||||
args.camera?.lat !== undefined ||
|
||||
args.camera?.lon !== undefined;
|
||||
let streetLevel =
|
||||
args.street_level && typeof args.street_level === 'object'
|
||||
? { ...args.street_level }
|
||||
: base.street_level && typeof base.street_level === 'object'
|
||||
? moved
|
||||
? { provider: base.street_level.provider }
|
||||
: { ...base.street_level }
|
||||
: null;
|
||||
if (args.area) {
|
||||
const area = await resolveArea(args.area, { services, signal });
|
||||
label = area.label;
|
||||
const framed = cameraForArea(area);
|
||||
if (
|
||||
streetLevel &&
|
||||
streetLevel.lat === undefined &&
|
||||
streetLevel.lon === undefined
|
||||
)
|
||||
streetLevel = { ...streetLevel, lat: framed.lat, lon: framed.lon };
|
||||
// A tilted view of an area looks at its center from behind, unless the
|
||||
// caller placed the camera itself.
|
||||
camera =
|
||||
@@ -75,6 +101,15 @@ export async function resolveViewArguments(args, { services, signal, tools }) {
|
||||
camera = { altitude_m: FOLLOW_ALTITUDE_M, ...camera, ...position };
|
||||
label = `${follow.kind === 'military_aircraft' ? 'military aircraft' : 'aircraft'} ${follow.id}`;
|
||||
}
|
||||
// Photos for a camera with no point open where it looks, from its ground.
|
||||
if (
|
||||
streetLevel &&
|
||||
streetLevel.lat === undefined &&
|
||||
streetLevel.lon === undefined
|
||||
) {
|
||||
const point = await groundedLookAt(camera, services?.terrain, signal);
|
||||
if (point) streetLevel = { ...streetLevel, ...point };
|
||||
}
|
||||
let view;
|
||||
try {
|
||||
view = createView({
|
||||
@@ -84,6 +119,7 @@ export async function resolveViewArguments(args, { services, signal, tools }) {
|
||||
map: args.map ?? base.map ?? null,
|
||||
follow,
|
||||
annotations: args.annotations ?? base.annotations ?? [],
|
||||
street_level: streetLevel,
|
||||
});
|
||||
} catch (error) {
|
||||
// A view passed through can hold anything; report it as bad arguments.
|
||||
@@ -113,7 +149,9 @@ export const showInGodsEyeView = defineTool({
|
||||
'it. Pass the view another answer returned, or describe one: an area ' +
|
||||
'framed from above or a camera position, with chosen data layers, visual ' +
|
||||
'style and map, optionally following an aircraft (or riding in its ' +
|
||||
'cockpit view) or a satellite, and with marks drawn on the map.',
|
||||
'cockpit view) or a satellite, with marks drawn on the map, or opening ' +
|
||||
'street-level photos (Google Street View, Mapillary, KartaView or ' +
|
||||
'Panoramax) at a place.',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: VIEW_ARGUMENTS,
|
||||
@@ -131,7 +169,13 @@ export const showInGodsEyeView = defineTool({
|
||||
const url = viewUrl(base, view);
|
||||
return {
|
||||
summary: `Open ${label} in God's Eye View: ${url}`,
|
||||
data: { url, view },
|
||||
// A panel opens a billed photo only for a result it receives fresh;
|
||||
// hosts hand a panel its result again whenever they mount it.
|
||||
data: {
|
||||
url,
|
||||
view,
|
||||
...(view.street_level ? { issued_at: Date.now() } : {}),
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -113,3 +113,189 @@ test('links carry a camera, style, map and an entity to follow', async () => {
|
||||
/Give a view, an area, or a camera with lat and lon/,
|
||||
);
|
||||
});
|
||||
|
||||
test('links can open street-level photos at the area, on the map the source needs', async () => {
|
||||
const { viewFromParams } = await import('../../view/index.js');
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: { app: { baseUrl: 'http://localhost:4173/' } },
|
||||
});
|
||||
const result = await catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 38.5799, lon: -121.4937, radius_km: 1 },
|
||||
street_level: { provider: 'google' },
|
||||
});
|
||||
const { view } = result.data;
|
||||
assert.equal(view.map, 'photoreal');
|
||||
assert.deepEqual(view.layers, ['street-level']);
|
||||
assert.deepEqual(view.street_level, {
|
||||
provider: 'google',
|
||||
lat: 38.5799,
|
||||
lon: -121.4937,
|
||||
});
|
||||
const params = new URLSearchParams(new URL(result.data.url).hash.slice(1));
|
||||
assert.equal(params.get('sl'), 'google,38.57990,-121.49370');
|
||||
assert.equal(params.get('map'), 'photoreal');
|
||||
assert.deepEqual(viewFromParams(params), view);
|
||||
// The panel opens a billed photo only for a result it gets fresh.
|
||||
assert.ok(Math.abs(Date.now() - result.data.issued_at) < 60_000);
|
||||
|
||||
const point = await catalog.call('show_in_gods_eye_view', {
|
||||
view,
|
||||
street_level: { provider: 'mapillary', lat: 38.58, lon: -121.49 },
|
||||
});
|
||||
assert.deepEqual(point.data.view.street_level, {
|
||||
provider: 'mapillary',
|
||||
lat: 38.58,
|
||||
lon: -121.49,
|
||||
});
|
||||
await assert.rejects(
|
||||
catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 0, lon: 0, radius_km: 1 },
|
||||
map: 'osm',
|
||||
street_level: { provider: 'google' },
|
||||
}),
|
||||
/photoreal/,
|
||||
);
|
||||
});
|
||||
|
||||
test('a new area or camera position moves a passed-through view’s photos, and a tilted area still opens them at its centre', async () => {
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: { app: { baseUrl: 'http://localhost:4173/' } },
|
||||
});
|
||||
const first = await catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 38.5799, lon: -121.4937, radius_km: 1 },
|
||||
street_level: { provider: 'google' },
|
||||
});
|
||||
const second = await catalog.call('show_in_gods_eye_view', {
|
||||
view: first.data.view,
|
||||
area: { lat: 42.3314, lon: -83.0458, radius_km: 1 },
|
||||
});
|
||||
assert.deepEqual(second.data.view.street_level, {
|
||||
provider: 'google',
|
||||
lat: 42.3314,
|
||||
lon: -83.0458,
|
||||
});
|
||||
// A new camera position moves them too; turning the camera keeps them.
|
||||
const moved = await catalog.call('show_in_gods_eye_view', {
|
||||
view: first.data.view,
|
||||
camera: { lat: 40.758, lon: -73.9855, altitude_m: 800, pitch_deg: -90 },
|
||||
});
|
||||
assert.deepEqual(moved.data.view.street_level, {
|
||||
provider: 'google',
|
||||
lat: 40.758,
|
||||
lon: -73.9855,
|
||||
});
|
||||
const turned = await catalog.call('show_in_gods_eye_view', {
|
||||
view: first.data.view,
|
||||
camera: { heading_deg: 90 },
|
||||
});
|
||||
assert.deepEqual(turned.data.view.street_level, first.data.view.street_level);
|
||||
const tilted = await catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 48.8584, lon: 2.2945, radius_km: 1 },
|
||||
camera: { pitch_deg: -30 },
|
||||
street_level: { provider: 'mapillary' },
|
||||
});
|
||||
assert.notEqual(
|
||||
tilted.data.view.camera.lat,
|
||||
48.8584,
|
||||
'the camera sits behind the target',
|
||||
);
|
||||
assert.deepEqual(tilted.data.view.street_level, {
|
||||
provider: 'mapillary',
|
||||
lat: 48.8584,
|
||||
lon: 2.2945,
|
||||
});
|
||||
// A wide area frames the camera tens of km up, past where a camera's
|
||||
// look-at point is trusted: the photos still open at the area's centre.
|
||||
const wide = await catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 48.8584, lon: 2.2945, radius_km: 15 },
|
||||
camera: { pitch_deg: -30 },
|
||||
street_level: { provider: 'mapillary' },
|
||||
});
|
||||
assert.ok(wide.data.view.camera.altitude_m > 20_000);
|
||||
assert.deepEqual(wide.data.view.street_level, {
|
||||
provider: 'mapillary',
|
||||
lat: 48.8584,
|
||||
lon: 2.2945,
|
||||
});
|
||||
await assert.rejects(
|
||||
catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 0, lon: 0, radius_km: 1 },
|
||||
follow: { kind: 'aircraft', id: 'AE1234' },
|
||||
street_level: {},
|
||||
}),
|
||||
/cannot both follow/,
|
||||
);
|
||||
});
|
||||
|
||||
test('a camera with no photo point opens photos where it looks, measured from its ground', async () => {
|
||||
const { lookAtPoint } = await import('../../view/index.js');
|
||||
const asked = [];
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: {
|
||||
app: { baseUrl: 'http://localhost:4173/' },
|
||||
terrain: {
|
||||
getHeights: async (points) => {
|
||||
asked.push(points);
|
||||
return [{ ellipsoid: 1590 }];
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
// Denver: 1,909 m above the ellipsoid is about 320 m above its streets.
|
||||
const camera = {
|
||||
lat: 39.7392,
|
||||
lon: -104.9903,
|
||||
altitude_m: 1909,
|
||||
pitch_deg: -30,
|
||||
heading_deg: 0,
|
||||
};
|
||||
const result = await catalog.call('show_in_gods_eye_view', {
|
||||
camera,
|
||||
street_level: { provider: 'mapillary' },
|
||||
});
|
||||
assert.deepEqual(asked, [[{ lat: 39.7392, lon: -104.9903 }]]);
|
||||
const grounded = lookAtPoint({ ...camera, altitude_m: 319 });
|
||||
const { street_level: street } = result.data.view;
|
||||
assert.ok(Math.abs(street.lat - grounded.lat) < 1e-5, 'about 550 m ahead');
|
||||
assert.ok(
|
||||
street.lat - camera.lat < 0.006,
|
||||
'not the 3.3 km a sea-level guess gives',
|
||||
);
|
||||
// No terrain answer: the view's own estimate, as before.
|
||||
const offline = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: {
|
||||
app: { baseUrl: 'http://localhost:4173/' },
|
||||
terrain: {
|
||||
getHeights: async () => {
|
||||
throw new Error('offline');
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const fallback = await offline.call('show_in_gods_eye_view', {
|
||||
camera,
|
||||
street_level: { provider: 'mapillary' },
|
||||
});
|
||||
const guess = lookAtPoint(camera);
|
||||
assert.ok(Math.abs(fallback.data.view.street_level.lat - guess.lat) < 1e-5);
|
||||
});
|
||||
|
||||
test('a view passed through alone keeps its street-level photos', async () => {
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: { app: { baseUrl: 'http://localhost:4173/' } },
|
||||
});
|
||||
const first = await catalog.call('show_in_gods_eye_view', {
|
||||
area: { lat: 38.5799, lon: -121.4937, radius_km: 1 },
|
||||
street_level: { provider: 'mapillary' },
|
||||
});
|
||||
const again = await catalog.call('show_in_gods_eye_view', {
|
||||
view: first.data.view,
|
||||
});
|
||||
assert.deepEqual(again.data.view.street_level, first.data.view.street_level);
|
||||
assert.deepEqual(again.data.view, first.data.view);
|
||||
});
|
||||
Reference in new issue
Block a user