maps, routing, i18n: settle what the checks found

- The lead is Photon's own row first; a row of its name inside the lead
  only stands in where Photon's row went as the same place. Rows without a
  line below the name are never folded as reading the same.
- A miss of Photon where it is the geocoder no longer asks it a second time
  on the way to an empty answer.
- The transport words of the identity match use a Unicode word boundary
  (straße, estación) and match 駅 anywhere.
- Opening an OSM place reads the coordinate it was placed at explicitly.
- The ferry spans of a Valhalla leg move to valhallaFerries.ts, and a day
  cut into pieces is asked with one options object.
- "Limit" on the allowance tiles is "Daily limit", which no locale left
  as an English copy.
- Tests follow the new behaviour: no Nominatim behind Photon, zoom 13,
  and the expectations of the merge and edit-distance cases.
This commit is contained in:
Maurice
2026-10-30 16:36:22 +01:00
parent b98e530ffc
commit 1e5314d847
19 changed files with 111 additions and 88 deletions
+9 -2
View File
@@ -145,7 +145,8 @@ const recordView = (r: Record<string, unknown>): RowView => ({
* Then Photon's lead (`pickLead`) goes first, and rows of its name inside it
* go: "Berlin" no longer opens on a business filed as Berlin above the city.
* Rows that read the same twice, two branches of a chain with the same town
* below them, are one row: nobody can tell them apart in the list.
* below them, are one row: nobody can tell them apart in the list. A row
* without a line below its name is never folded that way.
*/
export function mergeRanked<T>(
first: T[],
@@ -163,12 +164,18 @@ export function mergeRanked<T>(
return !first.some((i) => (id !== null && view(i).id === id) || samePlace(asPlace(i), asPlace(o)));
});
const merged = interleave(first, extra, Number.POSITIVE_INFINITY);
const top = lead && leadsHere(lead, bias) ? merged.find((row) => standsFor(view(row), lead)) : undefined;
// Photon's own row first; a row of its name inside it only where that row went as the same place.
const top =
lead && leadsHere(lead, bias)
? (merged.find((row) => view(row).id === lead.placeId) ?? merged.find((row) => standsFor(view(row), lead)))
: undefined;
const ordered = top && lead ? [top, ...merged.filter((row) => row !== top && !standsFor(view(row), lead))] : merged;
const shown = new Set<string>();
return ordered
.filter((row) => {
const v = view(row);
// Without a line below the name two rows of one name are told apart by nothing but where they are.
if (!v.line.trim()) return true;
const reads = `${foldName(v.name)}\n${foldName(v.line)}`;
if (shown.has(reads)) return false;
shown.add(reads);
+7 -8
View File
@@ -405,14 +405,13 @@ export class MapsService {
}),
this.osm
.searchPhoton(query, lang, locationBias)
// Nominatim only for an installation Photon does not answer.
.then(
async (photon) =>
photon ?? {
records: await this.osm.searchNominatim(query, lang, 'interactive', locationBias),
lead: null,
},
)
// Nominatim only for an installation without Photon; where Photon is
// the geocoder its miss is an empty half, not a question for another.
.then(async (photon) => {
if (photon) return photon;
if (this.osm.photonIsGeocoder()) return { records: [] as Record<string, unknown>[], lead: null };
return { records: await this.osm.searchNominatim(query, lang, 'interactive', locationBias), lead: null };
})
.catch((err: unknown) => {
console.warn('OpenStreetMap search failed, index only:', (err as Error).message);
return { records: [] as Record<string, unknown>[], lead: null };
+12 -6
View File
@@ -205,7 +205,7 @@ const IDENTITY_TIMEOUT_MS = 2500;
// asked for one ("Hauptbahnhof", "Tor station").
const TRANSPORT_KEYS = new Set(['railway', 'public_transport', 'highway']);
const TRANSPORT_WORDS =
/(station|bahnhof|hbf|bhf|halt|haltestelle|stop|street|straße|strasse|road|weg|gare|estación|stazione|駅)/iu;
/(?:^|[^\p{L}])(?:station|bahnhof|hbf|bhf|halt|haltestelle|stop|street|straße|strasse|road|weg|gare|estación|stazione)(?:$|[^\p{L}])|駅/iu;
// How far a reverse lookup that found nothing next to the point looks again.
const WIDE_REVERSE_KM = 50;
@@ -544,6 +544,11 @@ export class OsmClient {
* next Nominatim slot each time, so somebody typing in the place search waits
* behind the whole import.
*/
/** Whether Photon is this installation's geocoder, so a miss of it is not handed to Nominatim. */
photonIsGeocoder(): boolean {
return this.photon.inUse();
}
async searchNominatim(
query: string,
lang?: string,
@@ -930,9 +935,10 @@ export class OsmClient {
placeId: string,
lang?: string,
): Promise<Record<string, unknown> | null> {
const at = element.center ?? (element.lat !== undefined && element.lon !== undefined ? element : null);
if (!at) return null;
const near = await this.photon.reverse(at.lat, at.lon, lang, undefined, { limit: 10, radius: 0.3 });
const lat = element.center?.lat ?? element.lat;
const lng = element.center?.lon ?? element.lon;
if (lat === undefined || lng === undefined) return null;
const near = await this.photon.reverse(lat, lng, lang, undefined, { limit: 10, radius: 0.3 });
const self = near?.find((f) => asNominatimHit(f)?.osm_type === osmType && String(f.properties.osm_id) === osmId);
const base = lang ? toApiLang(lang).split('-')[0] : '';
const extra = self ? (asNominatimHit(self)?.extratags ?? {}) : {};
@@ -940,8 +946,8 @@ export class OsmClient {
...buildOsmDetails({ ...extra, ...(element.tags ?? {}) }, osmType, osmId),
name: (base && element.tags?.[`name:${base}`]) || self?.properties.name || element.tags?.name || '',
address: self ? photonDisplayName(self.properties) : near?.[0] ? photonDisplayName(near[0].properties) : '',
lat: at.lat,
lng: at.lon,
lat,
lng,
osm_id: placeId,
};
}
@@ -334,7 +334,7 @@ export function nameLike(query: string, name: string): boolean {
/**
* Edits between two strings, a swap of neighbours counting as one: the
* optimal string alignment distance. "Paramraibo" is two from "Paramaribo".
* optimal string alignment distance. "Paramraibo" is one from "Paramaribo".
*/
export function editDistance(a: string, b: string): number {
if (Math.abs(a.length - b.length) > 2) return 3;