From fefe100131d291faecf0c790c4f424e5da721bf3 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 30 Aug 2024 14:18:04 -0700 Subject: [PATCH] Revert "use the server-side geocoded addresses for place names" This reverts commit e07206fad0caf6064a68cf145258a8915496b965. --- www/js/diary/addressNamesHelper.ts | 31 +++--------------------------- www/js/types/diaryTypes.ts | 12 +++--------- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/www/js/diary/addressNamesHelper.ts b/www/js/diary/addressNamesHelper.ts index ee5c0660d..660ab25f4 100644 --- a/www/js/diary/addressNamesHelper.ts +++ b/www/js/diary/addressNamesHelper.ts @@ -77,23 +77,6 @@ import Bottleneck from 'bottleneck'; import { displayError, logDebug } from '../plugin/logger'; import { CompositeTrip } from '../types/diaryTypes'; -export type NominatimResponse = { - address: { - road?: string; - pedestrian?: string; - suburb?: string; - neighbourhood?: string; - hamlet?: string; - city?: string; - town?: string; - county?: string; - state?: string; - postcode?: string; - country?: string; - country_code?: string; - }; -}; - let nominatimLimiter = new Bottleneck({ maxConcurrent: 2, minTime: 500 }); export const resetNominatimLimiter = () => { const newLimiter = new Bottleneck({ maxConcurrent: 2, minTime: 500 }); @@ -144,7 +127,7 @@ async function fetchNominatimLocName(loc_geojson) { status = ${response.status}; data = ${JSON.stringify(data)}`); localStorage.setItem(coordsStr, JSON.stringify(data)); - publish(coordsStr, JSON.stringify(data)); + publish(coordsStr, data); } catch (error) { if (!nominatimError) { nominatimError = error; @@ -155,16 +138,8 @@ async function fetchNominatimLocName(loc_geojson) { // Schedules nominatim fetches for the start and end locations of a trip export function fillLocationNamesOfTrip(trip: CompositeTrip) { - [trip.start_confirmed_place, trip.end_confirmed_place].forEach((place) => { - if (place?.geocoded_address || place?.reverse_geocode) { - const coordsStr = place.location.coordinates.toString(); - const data = place.reverse_geocode || { address: place.geocoded_address }; - localStorage.setItem(coordsStr, JSON.stringify(data)); - publish(coordsStr, JSON.stringify(data)); - } else { - nominatimLimiter.schedule(() => fetchNominatimLocName(place.location)); - } - }); + nominatimLimiter.schedule(() => fetchNominatimLocName(trip.end_loc)); + nominatimLimiter.schedule(() => fetchNominatimLocName(trip.start_loc)); } // a React hook that takes a trip or place and returns an array of its address names diff --git a/www/js/types/diaryTypes.ts b/www/js/types/diaryTypes.ts index c959dc944..53b618be0 100644 --- a/www/js/types/diaryTypes.ts +++ b/www/js/types/diaryTypes.ts @@ -2,7 +2,6 @@ and user input objects. As much as possible, these types parallel the types used in the server code. */ -import { NominatimResponse } from '../diary/addressNamesHelper'; import { BaseModeKey, MotionTypeKey } from '../diary/diaryHelper'; import useDerivedProperties from '../diary/useDerivedProperties'; import { VehicleIdentity } from './appConfigTypes'; @@ -33,13 +32,8 @@ export type ConfirmedPlace = { exit_fmt_time: string; // ISO string e.g. 2023-10-31T12:00:00.000-04:00 exit_local_dt: LocalDt; exit_ts: number; // Unix timestamp - - // one of these depending on what we decide to keep on the server - geocoded_address?: NominatimResponse['address']; - reverse_geocode?: NominatimResponse; - key: string; - location: Point; + location: Geometry; origin_key: string; raw_places: ObjectId[]; source: string; @@ -102,7 +96,7 @@ export type CompositeTrip = { confirmed_trip: ObjectId; distance: number; duration: number; - end_confirmed_place: ConfirmedPlace; + end_confirmed_place: BEMData; end_fmt_time: string; end_loc: Point; end_local_dt: LocalDt; @@ -119,7 +113,7 @@ export type CompositeTrip = { raw_trip: ObjectId; sections: SectionData[]; source: string; - start_confirmed_place: ConfirmedPlace; + start_confirmed_place: BEMData; start_fmt_time: string; start_loc: Point; start_local_dt: LocalDt;