mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
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
This commit is contained in:
1 parent
9beadbda63
commit
16e0f35c74
1 file changed
+14
-2
@@ -63,15 +63,27 @@ export function parseStationInformation(payload) {
|
|||||||
const stationMap = new Map();
|
const stationMap = new Map();
|
||||||
|
|
||||||
for (const raw of stations) {
|
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 stationId = String(raw?.station_id ?? raw?.id ?? '').trim();
|
||||||
const lat = Number(raw?.lat ?? raw?.latitude);
|
const lat = Number(raw?.lat ?? raw?.latitude);
|
||||||
const lon = Number(raw?.lon ?? raw?.longitude);
|
const lon = Number(raw?.lon ?? raw?.longitude);
|
||||||
if (!stationId || !Number.isFinite(lat) || !Number.isFinite(lon)) continue;
|
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, {
|
stationMap.set(stationId, {
|
||||||
stationId,
|
stationId,
|
||||||
name: String(raw?.name || raw?.short_name || '').trim(),
|
name,
|
||||||
lat,
|
lat,
|
||||||
lon,
|
lon,
|
||||||
capacity: toNonNegativeInteger(raw?.capacity),
|
capacity: toNonNegativeInteger(raw?.capacity),
|
||||||
|
|||||||
Reference in new issue
Block a user