mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
65 lines
1.2 KiB
JavaScript
65 lines
1.2 KiB
JavaScript
import {parse} from 'qs';
|
|
|
|
const POI = 'POI';
|
|
const STATION = 'ST';
|
|
const ADDRESS = 'ADR';
|
|
|
|
const leadingZeros = /^0+/;
|
|
|
|
const parseLocation = (ctx, l) => {
|
|
const {profile} = ctx;
|
|
|
|
if (!l) {
|
|
return null;
|
|
}
|
|
|
|
const lid = parse(l.id, {delimiter: '@'});
|
|
const res = {
|
|
type: 'location',
|
|
id: (l.extId || lid.L || l.evaNumber || '').replace(leadingZeros, '') || null,
|
|
};
|
|
|
|
if (l.lat && l.lon) {
|
|
res.latitude = l.lat;
|
|
res.longitude = l.lon;
|
|
} else if ('X' in lid && 'Y' in lid) {
|
|
res.latitude = lid.Y / 1000000;
|
|
res.longitude = lid.X / 1000000;
|
|
}
|
|
|
|
if (l.type === STATION || l.extId || l.evaNumber) {
|
|
const stop = {
|
|
type: 'stop', // TODO station
|
|
id: res.id,
|
|
name: l.name,
|
|
location: 'number' === typeof res.latitude
|
|
? res
|
|
: null, // todo: remove `.id`
|
|
};
|
|
// TODO subStops
|
|
|
|
if ('products' in l) {
|
|
stop.products = profile.parseProductsBitmask(ctx, l.products);
|
|
}
|
|
|
|
// TODO isMeta
|
|
// TODO station
|
|
// TODO entrances, lines, transitAuthority, dhid, ids
|
|
return stop;
|
|
}
|
|
|
|
if (l.type === ADDRESS) {
|
|
res.address = l.name;
|
|
} else {
|
|
res.name = l.name;
|
|
}
|
|
if (l.type === POI) {
|
|
res.poi = true;
|
|
}
|
|
|
|
return res;
|
|
};
|
|
|
|
export {
|
|
parseLocation,
|
|
};
|