From 16e0f35c74f2ff672eefac1eff05f1bd13d719fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20K=C3=A9kesi?= <64812024+KristofKekesi@users.noreply.github.com> Date: Wed, 26 Aug 2026 00:21:23 +0200 Subject: [PATCH] Feat: GBFS v3 support for station names GBFS v3 uses `LocalizedString` for `name` and `short_name` of the stations. This caused stations from v3 to have names like `[object Object]`. This commit makes the code handle v3 names. It default to locale 'en' then fallbacks to the first option in the array. Documentation for v3: https://gbfs.org/documentation/reference/#station_informationjson --- src/sources/gbfsStations.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/sources/gbfsStations.js b/src/sources/gbfsStations.js index 9c5b93528..cd90b12dd 100644 --- a/src/sources/gbfsStations.js +++ b/src/sources/gbfsStations.js @@ -63,15 +63,27 @@ export function parseStationInformation(payload) { const stationMap = new Map(); for (const raw of stations) { - // Accept both GBFS 2.x (station_id) and alternate (id) field names + // Accept both GBFS (station_id) and alternate (id) field names const stationId = String(raw?.station_id ?? raw?.id ?? '').trim(); const lat = Number(raw?.lat ?? raw?.latitude); const lon = Number(raw?.lon ?? raw?.longitude); if (!stationId || !Number.isFinite(lat) || !Number.isFinite(lon)) continue; + let name; + if (payload?.version >= 3) { + const handleLocalizedString = (array) => + array.find((localizedString) => + localizedString.language.toLowerCase() === 'en') || array[0]; + name = String( + handleLocalizedString(raw?.name).text || + handleLocalizedString(raw?.short_name).text || '').trim(); + } else { + name = String(raw?.name || raw?.short_name || '').trim(); + } + stationMap.set(stationId, { stationId, - name: String(raw?.name || raw?.short_name || '').trim(), + name, lat, lon, capacity: toNonNegativeInteger(raw?.capacity),