feat(search): finish the keyless fallback at every geocode call site

The keyless fallback landed on the LOCATION search box only. Two other places
forward-geocode a name and neither had it: the annotation resolver returned
null, so an annotation silently failed to anchor, and the Radio layer THREW,
which surfaced as a failed voice turn rather than as a station it could not
place. src/keylessGeocoder.test.mjs now COUNTS the call sites instead of
checking them file by file, so a second seam added to a file that already has
a fallback fails the suite too.

The annotation path carries the feature's own name out of Photon. Footprint
scoring matches OSM on that canonical name rather than on the user's words, so
incidental locality tokens cannot win: "the monument near the Texas Capitol,
Austin" scored on the raw utterance picks a downtown building that shares only
"Texas", "Capitol" and "Austin".

Photon's country is deliberately NOT re-exported. It comes back in the
feature's own language — "Việt Nam", "日本", "Россия" — and
normalizeRadioCountryInput fails CLOSED on a name it cannot map, so forwarding
it would filter the station list to nothing for exactly the places the lookup
had just resolved. The composed label still names the country. A keyless
lookup must not apply a filter the keyed one never applies.

A not-found is now remembered only when every source consulted returned a
verdict. Photon not replying is a network blip, not "no such place": memoizing
it kept the query answering not-found for the rest of the session on a network
that had since recovered — the same conflation the Overpass disk cache had to
be repaired for. geocodeMissIsDefinitive states the rule once and both entry
points use it, and the adapter's own memo follows it as well.

Reverse geocoding stays out of scope: the street-label reader consumes
Google's ranked address_components, and Photon's /reverse cannot reproduce
that shape.
This commit is contained in:
daikaginza committed 2026-09-05 09:46:04 +07:00
1 parent acac1e4842
commit e21c174f76
8 files changed
+681 -43

No files matched your search

+31 -12
View File
@@ -17,6 +17,7 @@ import militaryAwarenessLayer, {
import { initCameraVerbs, moveCamera, flyRoute, interruptCameraMotion, adjustOrbitRange } from '../cameraVerbs.js';
import { cachedGroundFloor, warmGroundFloor } from '../data/groundFloor.js';
import { isPickedWorldPosition } from '../data/scenePick.js';
import { geocodeKeyless } from '../keylessGeocoder.js';
import { resolveRegionRingForQuery } from '../annotations/annotationResolver.js';
import { normalizeRadioCountryInput } from '../data/radioCountry.js';
import { TR3B_CLASS } from '../data/tr3bRegistry.js';
@@ -1265,25 +1266,43 @@ async function resolveRadioLocation(args = {}, coordinates = radioCoordinatePair
if (known) return known;
if (!query) return null;
const apiKey = window.__GOOGLE_MAPS_API_KEY__ || import.meta.env.GOOGLE_MAPS_API_KEY;
if (!apiKey) throw new Error('No Google Maps API key available for Radio location search');
const controller = new AbortController();
const cancelFromTurn = () => controller.abort();
if (options.signal?.aborted) throw radioAbortError();
options.signal?.addEventListener('abort', cancelFromTurn, { once: true });
const timer = setTimeout(() => controller.abort(), 6000);
try {
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(query)}&key=${apiKey}`;
const response = await fetch(url, { signal: controller.signal });
const body = await response.json();
if (apiKey) {
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(query)}&key=${apiKey}`;
const response = await fetch(url, { signal: controller.signal });
const body = await response.json();
if (!radioActionIsCurrent(options)) throw radioAbortError();
const result = body.status === 'OK' ? body.results?.[0] : null;
if (result?.geometry?.location) {
return {
lat: result.geometry.location.lat,
lon: result.geometry.location.lng,
label: result.formatted_address || query,
country: '',
};
}
}
// Same fallback rule as the LOCATION search box: reached with no key, and
// also when a key exists but Google returned nothing. A missing key used to
// throw here, which surfaced as a failed voice turn rather than as a radio
// station that could not be placed.
// Unbiased, matching the Google call above: a radio location is named
// outright ("radio near Hanoi"), not relative to what the camera shows.
const keyless = await geocodeKeyless(query);
if (!radioActionIsCurrent(options)) throw radioAbortError();
const result = body.status === 'OK' ? body.results?.[0] : null;
if (!result?.geometry?.location) return null;
return {
lat: result.geometry.location.lat,
lon: result.geometry.location.lng,
label: result.formatted_address || query,
country: '',
};
if (!keyless) return null;
// `country` stays empty, exactly as the Google branch above leaves it. Photon
// does report a country, but in the feature's own language ("Việt Nam",
// "日本"), and `normalizeRadioCountryInput` fails CLOSED on a name it cannot
// map — so forwarding it would turn "radio near Ha Long" into an empty
// station list rather than the nearest station. A keyless lookup must not
// apply a filter the keyed one never applies.
return { lat: keyless.lat, lon: keyless.lng, label: keyless.label || query, country: '' };
} finally {
clearTimeout(timer);
options.signal?.removeEventListener('abort', cancelFromTurn);