2024-02-06 22:58:49 +01:00
|
|
|
import {parse} from 'qs';
|
2019-02-05 19:07:19 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const POI = 'POI';
|
|
|
|
const STATION = 'ST';
|
|
|
|
const ADDRESS = 'ADR';
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const leadingZeros = /^0+/;
|
2018-10-15 17:31:28 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const parseLocation = (ctx, l) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
const {profile, opt} = ctx;
|
2019-10-20 00:19:11 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const lid = parse(l.id, {delimiter: '@'});
|
2019-02-07 17:46:49 +01:00
|
|
|
const res = {
|
|
|
|
type: 'location',
|
2024-02-06 22:58:49 +01:00
|
|
|
id: (l.extId || lid.L || '').replace(leadingZeros, '') || null,
|
|
|
|
};
|
2019-02-07 17:46:49 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if (l.lat && l.lon) {
|
|
|
|
res.latitude = l.lat;
|
|
|
|
res.longitude = l.lon;
|
2024-02-06 22:58:49 +01:00
|
|
|
} else if ('X' in lid && 'Y' in lid) {
|
|
|
|
res.latitude = lid.Y / 1000000;
|
|
|
|
res.longitude = lid.X / 1000000;
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if (l.type === STATION || l.extId) {
|
2018-07-10 23:32:34 +02:00
|
|
|
const stop = {
|
2024-12-07 16:16:31 +00:00
|
|
|
type: 'stop', // TODO station
|
2019-02-07 17:46:49 +01:00
|
|
|
id: res.id,
|
2024-12-07 16:16:31 +00:00
|
|
|
name: l.name,
|
2024-02-06 22:58:49 +01:00
|
|
|
location: 'number' === typeof res.latitude
|
|
|
|
? res
|
|
|
|
: null, // todo: remove `.id`
|
|
|
|
};
|
2024-12-07 16:16:31 +00:00
|
|
|
// TODO subStops
|
2020-02-15 19:13:43 +00:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if ('products' in l) {
|
|
|
|
stop.products = profile.parseProductsBitmask(ctx, l.products);
|
2020-03-07 00:28:47 +01:00
|
|
|
}
|
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
//TODO isMeta
|
|
|
|
//TODO station
|
|
|
|
//TODO entrances, lines, transitAuthority, dhid, ids
|
2024-02-06 22:58:49 +01:00
|
|
|
return stop;
|
2017-12-11 19:25:29 +01:00
|
|
|
}
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
if (l.type === ADDRESS) {
|
|
|
|
res.address = l.name;
|
|
|
|
} else {
|
|
|
|
res.name = l.name;
|
|
|
|
}
|
|
|
|
if (l.type === POI) {
|
|
|
|
res.poi = true;
|
|
|
|
}
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
return res;
|
|
|
|
};
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
2024-12-07 16:16:31 +00:00
|
|
|
parseLocation,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|