Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 33 additions & 10 deletions src/olmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkState<OlmapResponse> | undefined> => {
if (osmId === -1) {
return undefined;
}
const fetchOlmapUrl = async (
url: string
): Promise<NetworkState<OlmapResponse>> => {
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) {
Expand Down Expand Up @@ -171,6 +172,28 @@ export const fetchOlmapData = async (
}
};

export const fetchOlmapData = async (
osmId?: number,
locale?: string,
olmapId?: number
): Promise<NetworkState<OlmapResponse> | 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<OlmapResponse>,
osmData: Array<ElementWithCoordinates>
Expand Down