diff --git a/src/App.tsx b/src/App.tsx index 352255b0..bb77f5a4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -913,10 +913,14 @@ const App: React.FC = () => { }; }); // Fetch new data - const olmapData = await fetchOlmapData( - state.popupCoordinates.id, - state.locale - ); + const olmapData = + state.popupCoordinates.type === "olmap" + ? await fetchOlmapData( + undefined, + state.locale, + state.popupCoordinates.id + ) + : await fetchOlmapData(state.popupCoordinates.id, state.locale); setState((prevState: State): State => { if (prevState.popupCoordinates !== state.popupCoordinates) { return prevState; @@ -1035,17 +1039,11 @@ const App: React.FC = () => { highlights: noHighlights, }; } - // If an OLMap element was clicked, show details in the popup. - if (feature?.properties["@id"]?.startsWith("olmap")) { - return { - ...prevState, - editingNote: feature.properties["@id"].split("/").reverse()[0], - }; - } - // If an entrance or a loading place was clicked, show details in the popup. + // If an entrance, a loading place or an OLMap element was clicked, show details in the popup. if ( feature?.properties.entrance || - feature?.properties["parking:condition"] === "loading" + feature?.properties["parking:condition"] === "loading" || + feature?.properties["@id"]?.startsWith("olmap") ) { const element = geoJsonToElement(feature); return { diff --git a/src/olmap.ts b/src/olmap.ts index 67451319..76d60c7b 100644 --- a/src/olmap.ts +++ b/src/olmap.ts @@ -128,20 +128,21 @@ const processOlmapData = (data: OlmapResponse): OlmapResponse => { deliveryTypePriorities[a.deliveries || "null"] ); } + if (!data.image_notes) { + return { + image_notes: [data as unknown as OlmapNote], + id: data.id, + associated_entrances: [], + }; + } return data; }; -export const fetchOlmapData = async ( - osmId: number, - locale: string -): Promise | undefined> => { - if (osmId === -1) { - return undefined; - } +const fetchOlmapUrl = async ( + url: string +): Promise> => { try { - const response = await fetch( - `https://api.olmap.org/rest/osm_features/${osmId}/?language=${locale}` - ); + const response = await fetch(url); try { const data = await response.json(); if (!response.ok) { @@ -171,6 +172,28 @@ export const fetchOlmapData = async ( } }; +export const fetchOlmapData = async ( + osmId?: number, + locale?: string, + olmapId?: number +): Promise | undefined> => { + try { + if (olmapId) { + return await fetchOlmapUrl( + `https://api.olmap.org/rest/osm_image_notes/${olmapId}/` + ); + } + if (!osmId || osmId === -1) { + return undefined; + } + return await fetchOlmapUrl( + `https://api.olmap.org/rest/osm_features/${osmId}/?language=${locale}` + ); + } finally { + // no-op + } +}; + export const venueDataToGeoJSON = ( venueData: NetworkState, osmData: Array