Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(analyst): restore exact region matches and remove search rescue

manjunathb0e0945360df
diff --cc changelog.d/1235-location-resolution.md
index 9d67783c0,000000000..85cb62cae
mode 100644,000000..100644
--- a/changelog.d/1235-location-resolution.md
+++ b/changelog.d/1235-location-resolution.md
@@@ -1,1 -1,0 +1,1 @@@
- - Preserve successful place-search matches, require an unambiguous containing natural region for recovery, and retain analyst boundary provenance through follow-ups (manjunath22466, #1235).
++- Require a geocoded containment anchor for ambiguous analyst region names, preserve boundary provenance and cancellation safety, and retain exact-name precedence for natural outlines (manjunath22466, #1235).
diff --cc docs/CURRENT-STATE.md
index 613cf640c,55b7a63ab..391b4b3d6
--- a/docs/CURRENT-STATE.md
+++ b/docs/CURRENT-STATE.md
@@@ -1,13 -1,5 +1,15 @@@
# God's Eye View Current State
- Location search preserves successful geocoder results, including contemporary
- places that share a Natural Earth name. After geocoding and nearby-place recovery
- miss, a natural region can resolve from the current view only when exactly one
- matching region contains it. Annotation outlines use the same containment rule
- for view-based recovery. Analyst queries retain their offline unique-name lookup;
- duplicate names use a geocoded anchor, and follow-ups retain boundary provenance.
- Cancelled region lookups preserve the previous analyst cohort and boundary source.
++Analyst region queries retain the existing offline lookup for unique Natural
++Earth names without geocoding: Gold Coast and Ivory Coast still name the West
++African natural regions. Duplicate names require a geocoded containment anchor.
++When multiple entries for the same name contain that anchor, the lookup now stays
++unresolved instead of selecting the largest entry. Natural outlines try exact
++names before aliases and broader suffix variants. Follow-ups retain boundary provenance, and
++cancelled lookups preserve the previous analyst cohort and boundary source.
++Navigation keeps main's existing successful-geocode precedence; this change adds
++no search or view-based annotation recovery.
+
Shared distance checks use `src/geoDistance.js` with `{ lat, lon }` points and
the IUGG mean spherical Earth radius, 6371.0088 km. `greatCircleKm` is
canonical; `greatCircleMeters` is its exact metre conversion. Missing,
diff --cc src/annotations/adminOutline.test.mjs
index d3d1cc4b9,29761a2e3..2028fe711
--- a/src/annotations/adminOutline.test.mjs
+++ b/src/annotations/adminOutline.test.mjs
@@@ -120,123 -120,6 +120,93 @@@ test('Georgia resolves from camera geog
assert.deepEqual(geocodes, []);
});
- test('the Alps under the view resolve before an unrelated remote geocode', async () => {
- const { resolve, lookups, geocodes } = harness({
- lat: -27.96,
- lng: 152.2,
- label: 'The Alps, Queensland',
- name: 'The Alps',
- types: ['locality', 'political'],
- });
- const resolved = await resolve('the Alps', viewerAt(46.5, 10, 248_000));
- assert.equal(resolved?.source, 'bundled');
- assert.equal(resolved.naturalRegion, 'Alps');
- assert.equal(resolved.synthesized, false);
- assert.equal(resolved.footprintKind, 'area');
- assert.ok(resolved.ring.length >= 8);
- assert.deepEqual(resolved.ring[0], resolved.ring.at(-1));
- assert.equal(resolved.resolveOutline, undefined);
- assert.deepEqual(geocodes, []);
- assert.deepEqual(lookups, []);
- });
-
+test('Gold Coast in Australia cannot acquire its West African namesake outline', async () => {
+ for (const types of [['locality', 'political'], ['natural_feature']]) {
+ const { resolve, geocodes } = harness({
+ lat: -28.0167,
+ lng: 153.4,
+ label: 'Gold Coast, Australia',
+ name: 'Gold Coast',
+ types,
+ });
+ const resolved = await resolve('Gold Coast', viewerAt(-28.0167, 153.4));
+ assert.equal(resolved?.source, 'geocode');
+ assert.equal(resolved.lat, -28.0167);
+ assert.equal(resolved.lon, 153.4);
+ assert.equal(resolved.naturalRegion, undefined);
+ const outline = await resolved.resolveOutline();
+ assert.equal(outline?.naturalRegion, undefined);
+ assert.deepEqual(geocodes, ['Gold Coast']);
+ }
+});
+
- test('unique natural names without a containing view still need a geocoded anchor', async () => {
- for (const viewer of [AUSTIN, {}]) {
++test('natural annotation outlines require a geocoded anchor', async () => {
++ for (const viewer of [AUSTIN, {}, viewerAt(46.5, 10, 248_000)]) {
+ const miss = harness();
+ assert.equal(await miss.resolve('the Alps', viewer), null);
+ assert.ok(miss.geocodes.includes('the Alps'));
+ }
+ const anchored = harness({
+ lat: 46.5,
+ lng: 10,
+ label: 'Alps',
+ name: 'Alps',
+ types: ['natural_feature'],
+ });
+ const resolved = await anchored.resolve('the Alps', {});
+ assert.equal(resolved.source, 'geocode');
+ const outline = await resolved.resolveOutline();
+ assert.equal(outline.naturalRegion, 'Alps');
+ assert.ok(outline.ring.length >= 8);
+});
+
+test('overlapping natural candidates continue through geocoding without choosing a ring', async () => {
+ const { resolve, geocodes } = harness({
+ lat: 45.6336,
+ lng: -74.86493,
+ label: 'Canadian Shield',
+ name: 'Canadian Shield',
+ types: ['natural_feature'],
+ });
+ const resolved = await resolve(
+ 'Canadian Shield',
+ viewerAt(45.6336, -74.86493),
+ );
+ assert.equal(resolved?.source, 'geocode');
+ assert.equal((await resolved.resolveOutline())?.naturalRegion, undefined);
+ assert.deepEqual(geocodes, ['Canadian Shield']);
+});
+
- test('natural view recovery preserves point, explicit-coordinate, entity and around intent', async () => {
++test('geocoded natural outlines respect district and around intent', async () => {
+ for (const extra of [
- { footprint: false },
- { latitude: 46.5, longitude: 10 },
- { entityKind: 'building' },
- { entityKind: 'compound' },
+ { entityKind: 'district' },
- { entityKind: 'street' },
- { entityKind: 'point_feature' },
+ { intent: 'around_the_thing' },
+ ]) {
+ const { resolve, geocodes } = harness({
+ lat: 46.5,
+ lng: 10,
+ label: 'Alps',
+ name: 'Alps',
+ types:
+ extra.entityKind === 'district' ? ['locality'] : ['natural_feature'],
+ });
+ const resolved = await resolve('the Alps', viewerAt(46.5, 10), extra);
- assert.notEqual(resolved?.source, 'bundled');
- assert.equal(resolved?.naturalRegion, undefined);
- if (extra.entityKind === 'district')
- assert.ok(geocodes.includes('the Alps'));
- if (extra.intent === 'around_the_thing' || extra.entityKind === 'district')
- assert.equal((await resolved.resolveOutline())?.naturalRegion, undefined);
++ assert.ok(geocodes.includes('the Alps'));
++ assert.equal((await resolved.resolveOutline())?.naturalRegion, undefined);
+ }
+});
+
- test('cancellation while a natural view lookup is pending cannot publish its outline', async () => {
++test('cancellation while a bundled admin lookup is pending cannot publish an annotation', async () => {
+ const controller = new AbortController();
+ const { resolve, geocodes } = harness();
+ const pending = resolve('the Alps', viewerAt(46.5, 10), {
+ signal: controller.signal,
+ });
+ controller.abort();
+ await assert.rejects(pending, { name: 'AbortError' });
+ assert.deepEqual(geocodes, []);
+});
+
test('country asks and geocoded country scopes use the bundled outline', async () => {
const direct = harness();
for (const name of ['Switzerland', 'Iran', 'France', 'Japan']) {
diff --cc src/data/naturalEarthRegions.js
index a060d2260,c40e180ac..512391311
--- a/src/data/naturalEarthRegions.js
+++ b/src/data/naturalEarthRegions.js
@@@ -273,8 -270,9 +273,10 @@@ export function pointInRing(ring, lat,
/**
* Resolve a natural-region OUTLINE ring for the annotation resolver's first
* rung. Stricter than `findNaturalRegion`: walks ALL entries sharing the
- * matched name (duplicate names included) and returns a ring only when exactly
- * one indexed entry CONTAINS the anchor. Containment is the disambiguator and the
- * matched name (duplicate names included — the US and Spanish "Sierra
- * Nevada" both exist upstream) and returns the single ring that CONTAINS the
- * geocoded anchor. Containment is simultaneously the disambiguator and the
++ * matched name (duplicate names included), trying exact names, aliases and
++ * broader suffix variants in that order. Returns a ring only when exactly one
++ * entry under the matched name CONTAINS the anchor. Containment is the
++ * disambiguator and the
* wrong-place guard: when no ring contains the anchor this returns null and
* the resolver's normal ladder continues unchanged.
*
@@@ -293,28 -291,25 +295,28 @@@ export async function lookupNaturalRegi
ALIASES[norm],
...suffixVariants(ALIASES[norm] || norm),
];
-- const seen = new Set();
- const containingEntries = new Map();
-- for (const key of candidates) {
-- if (!key || seen.has(key)) continue;
-- seen.add(key);
++ for (const key of new Set(candidates.filter(Boolean))) {
++ const containing = [];
for (const entry of index.get(key) || []) {
- if (containingEntries.has(entry)) continue;
- for (const ring of entry.polygons) {
- if (pointInRing(ring, lat, lon)) {
- return {
- name: entry.name,
- kind: entry.kind,
- featurecla: entry.featurecla,
- ring,
- areaKm2: entry.areaKm2,
- };
- }
- }
+ const ring = entry.polygons.find((candidate) =>
+ pointInRing(candidate, lat, lon),
+ );
- if (ring) containingEntries.set(entry, ring);
++ if (ring) containing.push({ entry, ring });
}
++ // Specific names win over aliases and broader rewrites. Ambiguity belongs
++ // to this name, not the union of every lower-priority candidate name.
++ if (containing.length > 1) return null;
++ if (containing.length === 0) continue;
++ const [{ entry, ring }] = containing;
++ return {
++ name: entry.name,
++ kind: entry.kind,
++ featurecla: entry.featurecla,
++ ring,
++ areaKm2: entry.areaKm2,
++ };
}
- if (containingEntries.size !== 1) return null;
- const [[entry, ring]] = containingEntries;
- return {
- name: entry.name,
- kind: entry.kind,
- featurecla: entry.featurecla,
- ring,
- areaKm2: entry.areaKm2,
- };
+ return null;
}
/** Resolve the smallest containing bundled physical region without a network geocoder. */
diff --cc src/data/naturalEarthRegions.test.mjs
index 9d58fa6e0,5dd78adea..92109a034
--- a/src/data/naturalEarthRegions.test.mjs
+++ b/src/data/naturalEarthRegions.test.mjs
@@@ -130,12 -122,12 +130,16 @@@ test('listRegions() enumerates both kin
});
// ── lookupNaturalRegionOutline (resolver first-rung contract) ──────
--test('outline lookup: Alps ring via containment anchor', async () => {
++test('outline lookup: containing exact names win over broader suffix variants', async () => {
const r = await lookupNaturalRegionOutline('the Alps', 46.5, 10.0);
assert.ok(r, 'Alps must resolve with an inside anchor');
assert.equal(r.name, 'Alps');
assert.ok(r.ring.length >= 8, 'range-scale ring');
assert.ok(r.areaKm2 > 100000 && r.areaKm2 < 400000, `sane Alps area, got ${r.areaKm2}`);
++ const range = await lookupNaturalRegionOutline('Alaska Range', 63.14, -148.71);
++ assert.equal(range?.name, 'Alaska Range');
++ assert.ok(pointInRing(range.ring, 63.14, -148.71));
++ assert.equal((await lookupNaturalRegionOutline('Alaska', 63.14, -148.71))?.name, 'Alaska');
});
test('outline lookup: duplicate names disambiguate by anchor containment', async () => {
diff --cc src/locations.test.mjs
index 65384a158,c225488a3..8d2a9503c
--- a/src/locations.test.mjs
+++ b/src/locations.test.mjs
@@@ -152,208 -152,6 +152,124 @@@ test('regionFramingPlan: E-W elongated
assert.equal(plan.headingDeg, 90);
});
- // Synthetic service responses exercise collisions with the physical-region
- // pack. These are authored fixtures, not captured geocoder responses.
- for (const [query, label, lat, lng, type, bounds] of [
- ['Gold Coast', 'Gold Coast, Queensland, Australia', -28, 153.4, 'locality', [-28.2, 153.2, -27.8, 153.6]],
- ['Santa Cruz', 'Santa Cruz, California, USA', 37, -122, 'locality', [36.9, -122.1, 37.1, -121.9]],
- ['Isabela', 'Isabela, Philippines', 17, 122, 'administrative_area_level_1', [16.5, 121.5, 17.5, 122.5]],
- ['India', 'India', 22, 79, 'country', [7, 67, 37, 91]],
- ['Korea', 'South Korea', 36, 128, 'country', [33, 126, 39, 130]],
- ]) {
- test(`search keeps the geocoded ${label} over its Natural Earth namesake`, async () => {
- const viewer = stubViewer();
- const geocodes = [];
- const result = await searchAndFlyTo(viewer, query, {
- placeSearch: {
- async geocode(request) {
- geocodes.push(request);
- return { place: { lat, lng, label, types: [type, 'political'], viewport: boxOf(...bounds) } };
- },
++// Compatibility guard for inherited geocode authority, not a newly fixed bug.
++test('search retains main geocode authority for Gold Coast, Australia', async () => {
++ const viewer = stubViewer();
++ const result = await runSearch(viewer, {}, {
++ query: 'Gold Coast',
++ result: {
++ formatted_address: 'Gold Coast, Queensland, Australia',
++ types: ['locality', 'political'],
++ geometry: {
++ location: { lat: -28, lng: 153.4 },
++ viewport: boxOf(-28.2, 153.2, -27.8, 153.6),
+ },
- recoverNearView: async () => null,
- });
- assert.deepEqual(geocodes, [query]);
- assert.equal(result.label, label);
- assert.equal(result.navigationMode, type === 'locality' ? 'city-overview' : 'region-overview');
- assert.equal(viewer.flights.length, 1);
- const flown = flownRectangleDegrees(viewer);
- assert.ok(Math.abs((flown.south + flown.north) / 2 - lat) < 0.000001, `${query}: latitude remains geocoded`);
- assert.ok(Math.abs((flown.west + flown.east) / 2 - lng) < 0.000001, `${query}: longitude remains geocoded`);
- assert.ok(flown.south <= bounds[0] && flown.north >= bounds[2], 'frames the geocoded north-south extent');
- assert.ok(flown.west <= bounds[1] && flown.east >= bounds[3], 'frames the geocoded east-west extent');
- assert.ok(flown.widthDeg < (bounds[3] - bounds[1]) * 1.6, 'keeps the geocoded place scale');
++ },
+ });
- }
++ assert.equal(result.label, 'Gold Coast, Queensland, Australia');
++ assert.equal(result.navigationMode, 'city-overview');
++ assert.equal(viewer.flights.length, 1);
++ const flown = flownRectangleDegrees(viewer);
++ assert.ok(Math.abs((flown.south + flown.north) / 2 + 28) < 0.000001);
++ assert.ok(Math.abs((flown.west + flown.east) / 2 - 153.4) < 0.000001);
++});
+
+function alpsViewer() {
+ const viewer = stubViewer();
+ Object.assign(viewer.camera.positionCartographic, {
+ latitude: Cesium.Math.toRadians(46.5),
+ longitude: Cesium.Math.toRadians(10),
+ height: 248_000,
+ });
+ return viewer;
+}
+
- for (const answered of [true, false]) {
- test(`search recovers contained Alps only after geocoder ${answered ? 'miss' : 'unavailability'} and nearby recovery miss`, async () => {
- const viewer = alpsViewer();
- const order = [];
- const result = await searchAndFlyTo(viewer, 'the Alps', {
- placeSearch: { async geocode() { order.push('geocode'); return { place: null, answered }; } },
- recoverNearView: async () => { order.push('nearby'); return null; },
- });
- assert.deepEqual(order, ['geocode', 'nearby']);
- assert.equal(result?.label, 'Alps');
- assert.equal(result?.navigationMode, 'natural-region-swath');
- assert.equal(viewer.flights.length, 1);
- const target = Cesium.Cartographic.fromCartesian(viewer.flights[0].sphere.center);
- assert.ok(Cesium.Math.toDegrees(target.latitude) > 43 && Cesium.Math.toDegrees(target.latitude) < 49);
- assert.ok(Cesium.Math.toDegrees(target.longitude) > 5 && Cesium.Math.toDegrees(target.longitude) < 17);
- });
- }
-
- test('a successful nearby recovery keeps precedence over a contained natural region', async () => {
++test('a successful nearby recovery resolves after a geocoder miss', async () => {
+ const viewer = alpsViewer();
+ const result = await searchAndFlyTo(viewer, 'the Alps', {
+ placeSearch: { async geocode() { return { place: null, answered: true }; } },
+ recoverNearView: async () => ({
+ lat: 46.6,
+ lon: 10.1,
+ label: 'The Alps local landmark',
+ types: ['locality', 'political'],
+ viewport: { low: { latitude: 46.5, longitude: 10 }, high: { latitude: 46.7, longitude: 10.2 } },
+ }),
+ });
+ assert.equal(result.label, 'The Alps local landmark');
+ assert.equal(result.navigationMode, 'city-overview');
+ assert.equal(viewer.flights.length, 1);
+});
+
- test('missing searches never choose a natural namesake outside the view or without a view anchor', async () => {
- const withoutAnchor = alpsViewer();
- delete withoutAnchor.camera.positionCartographic;
- for (const [query, viewer] of [['the Alps', stubViewer()], ['not a real location', alpsViewer()], ['the Alps', withoutAnchor]]) {
- const result = await searchAndFlyTo(viewer, query, {
- placeSearch: { async geocode() { return { place: null, answered: true }; } },
++test('a geocoder miss returns null even over a namesake region', async () => {
++ for (const answered of [true, false]) {
++ const viewer = alpsViewer();
++ const result = await searchAndFlyTo(viewer, 'the Alps', {
++ placeSearch: { async geocode() { return { place: null, answered }; } },
+ recoverNearView: async () => null,
+ });
- assert.equal(result, null, query);
- assert.equal(viewer.flights.length, 0, query);
++ assert.equal(result, null);
++ assert.equal(viewer.flights.length, 0);
+ }
+});
+
- test('a duplicate natural name can recover when exactly one candidate contains the view', async () => {
- const viewer = stubViewer();
- Object.assign(viewer.camera.positionCartographic, {
- latitude: Cesium.Math.toRadians(5),
- longitude: Cesium.Math.toRadians(-73),
- });
- const result = await searchAndFlyTo(viewer, 'Cordillera Oriental', {
- placeSearch: { async geocode() { return { place: null, answered: true }; } },
- recoverNearView: async () => null,
- });
- assert.equal(result?.label, 'Cordillera Oriental');
- assert.equal(result?.navigationMode, 'natural-region-swath');
- assert.equal(viewer.flights.length, 1);
- const target = Cesium.Cartographic.fromCartesian(viewer.flights[0].sphere.center);
- assert.ok(Cesium.Math.toDegrees(target.latitude) > 0, 'frames the northern candidate');
- });
-
- test('an overlapping natural name stays unresolved after geocoder and nearby recovery miss', async () => {
- const viewer = stubViewer();
- Object.assign(viewer.camera.positionCartographic, {
- latitude: Cesium.Math.toRadians(45.6336),
- longitude: Cesium.Math.toRadians(-74.86493),
- });
- const result = await searchAndFlyTo(viewer, 'Canadian Shield', {
- placeSearch: { async geocode() { return { place: null, answered: true }; } },
- recoverNearView: async () => null,
- });
- assert.equal(result, null);
- assert.equal(viewer.flights.length, 0);
- });
-
- test('a geocoder rejection propagates without natural-region recovery or a flight', async () => {
++test('a geocoder rejection propagates without nearby recovery or a flight', async () => {
+ const viewer = alpsViewer();
+ const failure = new Error('geocoder failed');
+ let recoveries = 0;
+ await assert.rejects(searchAndFlyTo(viewer, 'the Alps', {
+ placeSearch: { async geocode() { throw failure; } },
+ recoverNearView: async () => { recoveries += 1; return null; },
+ }), (error) => error === failure);
+ assert.equal(recoveries, 0);
+ assert.equal(viewer.flights.length, 0);
+});
+
- test('search cancellation before or during geocoding cannot issue a fallback flight', async () => {
++test('search cancellation before or during geocoding cannot issue a flight', async () => {
+ for (const preAborted of [true, false]) {
+ const viewer = alpsViewer();
+ const controller = new AbortController();
+ if (preAborted) controller.abort();
+ let geocodes = 0;
+ let recoveries = 0;
+ await assert.rejects(searchAndFlyTo(viewer, 'the Alps', {
+ signal: controller.signal,
+ placeSearch: {
+ async geocode(_query, { signal }) {
+ geocodes += 1;
+ assert.equal(signal, controller.signal);
+ controller.abort();
+ return { place: null, answered: true };
+ },
+ },
+ recoverNearView: async () => { recoveries += 1; return null; },
+ }), { name: 'AbortError' });
+ assert.equal(geocodes, preAborted ? 0 : 1);
+ assert.equal(recoveries, 0);
+ assert.equal(viewer.flights.length, 0);
+ }
+});
+
- test('cancellation while the bundled fallback is resolving cannot issue a flight', async () => {
++test('cancellation during nearby recovery cannot issue a flight', async () => {
+ const viewer = alpsViewer();
- const carto = viewer.camera.positionCartographic;
+ const controller = new AbortController();
- let recoveryFinished = false;
- let fallbackRead = false;
+ let authorityChecks = 0;
- Object.defineProperty(viewer.camera, 'positionCartographic', {
- get() {
- if (recoveryFinished && !fallbackRead) {
- fallbackRead = true;
- // The fallback reads the view after nearby recovery, then awaits the
- // bundled lookup. Abort in that async gap, even when the pack is warm.
- queueMicrotask(() => controller.abort());
- }
- return carto;
- },
- });
+ await assert.rejects(searchAndFlyTo(viewer, 'the Alps', {
+ signal: controller.signal,
+ placeSearch: { async geocode() { return { place: null, answered: true }; } },
- recoverNearView: async () => { recoveryFinished = true; return null; },
++ recoverNearView: async () => {
++ controller.abort();
++ return {
++ lat: 46.6, lon: 10.1, label: 'Alpine landmark',
++ types: ['locality'],
++ };
++ },
+ beforeFly: () => { authorityChecks += 1; return true; },
+ }), { name: 'AbortError' });
- assert.equal(fallbackRead, true, 'reached the bundled recovery');
+ assert.equal(authorityChecks, 0);
+ assert.equal(viewer.flights.length, 0);
+});
+
- test('a final authority veto blocks a contained natural-region recovery flight', async () => {
- const viewer = alpsViewer();
- const order = [];
- const result = await searchAndFlyTo(viewer, 'the Alps', {
- placeSearch: { async geocode() { order.push('geocode'); return { place: null, answered: true }; } },
- recoverNearView: async () => { order.push('nearby'); return null; },
- beforeFly: () => { order.push('veto'); return false; },
- });
- assert.deepEqual(order, ['geocode', 'nearby', 'veto']);
- assert.equal(result, CANCELLED_SEARCH);
- assert.equal(viewer.flights.length, 0);
- });
-
test('regionFramingPlan: park- and lake-scale viewports keep full framing', () => {
// Zilker Park (~3 km).
assert.equal(regionFramingPlan({