Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(server): put a Photon house number before its street as Nominatim does

Mauricef76b8d5d9cf0
diff --git a/server/src/nest/maps/providers/photon.mapping.ts b/server/src/nest/maps/providers/photon.mapping.ts
index c32c2296d..36ba49a7a 100644
--- a/server/src/nest/maps/providers/photon.mapping.ts
+++ b/server/src/nest/maps/providers/photon.mapping.ts
@@ -89,13 +89,23 @@ export function photonLang(lang: string | undefined): string {
/**
* The address line Nominatim calls `display_name`: the place's own name first,
- * then street, quarter, town, county, region, postcode and country. A part
- * that repeats one before it is left out, so Berlin reads "Berlin, Germany"
- * rather than naming the city state twice.
+ * then house number and street as parts of their own ("12, Main Street", the
+ * way Nominatim writes them), quarter, town, county, region, postcode and
+ * country. A part that repeats one before it is left out, so Berlin reads
+ * "Berlin, Germany" rather than naming the city state twice.
*/
export function photonDisplayName(p: PhotonProperties): string {
- const street = [p.street, p.housenumber].filter(Boolean).join(' ');
- const parts = [p.name, street, p.district ?? p.locality, p.city, p.county, p.state, p.postcode, p.country];
+ const parts = [
+ p.name,
+ p.housenumber,
+ p.street,
+ p.district ?? p.locality,
+ p.city,
+ p.county,
+ p.state,
+ p.postcode,
+ p.country,
+ ];
const seen = new Set<string>();
for (const part of parts) {
const value = part?.trim();
diff --git a/server/tests/unit/nest/photon.mapping.test.ts b/server/tests/unit/nest/photon.mapping.test.ts
index dd44060da..6d9e27bed 100644
--- a/server/tests/unit/nest/photon.mapping.test.ts
+++ b/server/tests/unit/nest/photon.mapping.test.ts
@@ -1,5 +1,5 @@
/**
- * PHOTON-MAP-001..012: Photon's answers read into the shape Nominatim gives,
+ * PHOTON-MAP-001..013: Photon's answers read into the shape Nominatim gives,
* and the language Photon is asked in.
*/
import {
@@ -44,12 +44,17 @@ describe('photonLang', () => {
});
describe('photonDisplayName', () => {
- it('PHOTON-MAP-005: names the place, then the street, quarter, town, region, postcode and country', () => {
+ it('PHOTON-MAP-005: names the place, then house number and street as Nominatim does, quarter, town, region, postcode and country', () => {
expect(photonDisplayName(feature({ housenumber: '1' }).properties)).toBe(
- 'Brandenburger Tor, Pariser Platz 1, Mitte, Berlin, 10117, Deutschland',
+ 'Brandenburger Tor, 1, Pariser Platz, Mitte, Berlin, 10117, Deutschland',
);
});
+ it('PHOTON-MAP-013: writes an address without a name the way Nominatim writes a house', () => {
+ const house = feature({ name: undefined, housenumber: '77', street: 'Unter den Linden', postcode: undefined });
+ expect(photonDisplayName(house.properties)).toBe('77, Unter den Linden, Mitte, Berlin, Deutschland');
+ });
+
it('PHOTON-MAP-006: leaves out what is missing and what repeats', () => {
const city = feature({ name: 'Berlin', street: undefined, district: undefined, postcode: undefined, type: 'city' });
expect(photonDisplayName(city.properties)).toBe('Berlin, Deutschland');
@@ -88,7 +93,7 @@ describe('asNominatimHit', () => {
describe('asNominatimReverse', () => {
it('PHOTON-MAP-010: fills the address fields Nominatim fills, the sight under its main tag', () => {
expect(asNominatimReverse(feature({ housenumber: '1' }))).toEqual({
- display_name: 'Brandenburger Tor, Pariser Platz 1, Mitte, Berlin, 10117, Deutschland',
+ display_name: 'Brandenburger Tor, 1, Pariser Platz, Mitte, Berlin, 10117, Deutschland',
name: 'Brandenburger Tor',
address: {
road: 'Pariser Platz',