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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 57x 42x 42x 42x 34x 42x 42x 20x 42x 41x 42x 57x 13x 18x 18x 18x 13x | import { Coordinates } from "features/search/utils/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 addressParts: Array<string> = [];
// Primary locality (city/town level)
const primaryLocality =
place.address.city ||
place.address.town ||
place.address.village ||
place.address.municipality ||
place.address.hamlet;
if (primaryLocality) {
addressParts.push(primaryLocality);
}
// Administrative region (state/province level)
const adminRegion =
place.address.state ||
place.address.province ||
place.address.state_district;
if (adminRegion) {
addressParts.push(adminRegion);
}
// Country
if (place.address.country) {
addressParts.push(place.address.country);
}
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);
};
|