Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 51x 29x 29x 29x 203x 61x 29x 51x 13x 17x 17x 17x 13x | import { Coordinates } from "features/search/constants";
export interface NominatimPlace {
address: {
[city: string]: string;
state_district: string;
state: string;
postcode: string;
country: string;
country_code: string;
};
boundingbox: Coordinates;
category: string;
display_name: string;
icon: string;
importance: number;
lat: string;
licence: string;
lon: string;
osm_type: string;
osm_id: string;
place_id: number;
place_rank: number;
type: string;
}
export const simplifyPlaceDisplayName = (place: NominatimPlace) => {
const addressFields = [
"village",
"town",
"neighbourhood",
"suburb",
"city",
"state",
"country",
];
const addressParts: Array<string> = [];
for (const field of addressFields) {
if (field in place.address) {
addressParts.push(place.address[field]);
}
}
return addressParts.join(", ");
};
export const filterDuplicatePlaces = (places: NominatimPlace[] = []) => {
const deduplicatedPlaces = places.reduce((previousRecord, currentPlace) => {
const importance = currentPlace.importance ?? 0;
const displayName = simplifyPlaceDisplayName(currentPlace);
return previousRecord[displayName]?.importance >= importance
? previousRecord
: { ...previousRecord, [displayName]: currentPlace };
}, {} as Record<string, NominatimPlace>);
return Object.values(deduplicatedPlaces);
};
|