2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-12-11 19:25:29 +01:00
|
|
|
const POI = 'P'
|
|
|
|
const STATION = 'S'
|
|
|
|
const ADDRESS = 'A'
|
2017-11-11 22:35:41 +01:00
|
|
|
|
|
|
|
// todo: what is s.rRefL?
|
2018-06-13 19:59:44 +02:00
|
|
|
const parseLocation = (profile, opt, {lines}, l) => {
|
2017-12-11 19:25:29 +01:00
|
|
|
const res = {type: 'location'}
|
|
|
|
if (l.crd) {
|
|
|
|
res.latitude = l.crd.y / 1000000
|
|
|
|
res.longitude = l.crd.x / 1000000
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2017-12-11 19:25:29 +01:00
|
|
|
if (l.type === STATION) {
|
2018-07-10 23:32:34 +02:00
|
|
|
const stop = {
|
|
|
|
type: l.isMainMast ? 'station' : 'stop',
|
2017-12-11 19:25:29 +01:00
|
|
|
id: l.extId,
|
2018-05-07 11:48:08 +02:00
|
|
|
name: l.name ? profile.parseStationName(l.name) : null,
|
2018-03-13 21:06:27 +01:00
|
|
|
location: 'number' === typeof res.latitude ? res : null
|
2017-12-11 19:25:29 +01:00
|
|
|
}
|
2018-01-26 16:25:13 +01:00
|
|
|
|
2018-07-10 23:32:34 +02:00
|
|
|
if ('pCls' in l) stop.products = profile.parseProducts(l.pCls)
|
2018-01-26 16:25:13 +01:00
|
|
|
|
2018-06-28 13:00:33 +02:00
|
|
|
if (
|
|
|
|
opt.stationLines &&
|
|
|
|
Array.isArray(l.pRefL) &&
|
|
|
|
Array.isArray(lines)
|
|
|
|
) {
|
2018-07-10 23:32:34 +02:00
|
|
|
stop.lines = []
|
2018-01-26 16:25:13 +01:00
|
|
|
for (let pRef of l.pRefL) {
|
|
|
|
const line = lines[pRef]
|
2018-07-10 23:32:34 +02:00
|
|
|
if (line) stop.lines.push(line)
|
2018-01-26 16:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 23:32:34 +02:00
|
|
|
return stop
|
2017-12-11 19:25:29 +01:00
|
|
|
}
|
|
|
|
|
2017-12-11 19:53:26 +01:00
|
|
|
if (l.type === ADDRESS) res.address = l.name
|
2017-12-11 19:25:29 +01:00
|
|
|
else res.name = l.name
|
2018-12-28 22:12:28 +01:00
|
|
|
if (l.type === POI) res.id = l.extId || null
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2017-11-12 01:23:34 +01:00
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = parseLocation
|