mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
fix(server): put a Photon house number before its street as Nominatim does
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user