mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
parent
4a79b91680
commit
eb3ffba4fc
6 changed files with 16 additions and 10 deletions
|
@ -9,13 +9,14 @@ const formatAddress = (a) => {
|
|||
}
|
||||
|
||||
const data = {
|
||||
A: '2', // address
|
||||
A: '2', // address?
|
||||
O: a.address,
|
||||
X: formatCoord(a.longitude),
|
||||
Y: formatCoord(a.latitude)
|
||||
}
|
||||
if (a.id) data.L = a.id
|
||||
return {
|
||||
type: 'A', // address
|
||||
name: a.address,
|
||||
lid: formatLocationIdentifier(data)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ const formatLocation = (profile, l, name = 'location') => {
|
|||
if (l.type === 'station' || l.type === 'stop') {
|
||||
return profile.formatStation(l.id)
|
||||
}
|
||||
if ('string' === typeof l.id) return profile.formatPoi(l)
|
||||
if (l.poi) return profile.formatPoi(l)
|
||||
if ('string' === typeof l.address) return profile.formatAddress(l)
|
||||
if (!l.type) throw new Error(`missing ${name}.type`)
|
||||
throw new Error(`invalid ${name}.type: ${l.type}`)
|
||||
|
|
|
@ -9,9 +9,10 @@ const formatPoi = (p) => {
|
|||
}
|
||||
|
||||
return {
|
||||
type: 'P', // POI
|
||||
name: p.name,
|
||||
lid: formatLocationIdentifier({
|
||||
A: '4', // POI
|
||||
A: '4', // POI?
|
||||
O: p.name,
|
||||
L: p.id,
|
||||
X: formatCoord(p.longitude),
|
||||
|
|
|
@ -4,9 +4,10 @@ const formatLocationIdentifier = require('./location-identifier')
|
|||
|
||||
const formatStation = (id) => {
|
||||
return {
|
||||
type: 'S', // station
|
||||
// todo: name necessary?
|
||||
lid: formatLocationIdentifier({
|
||||
A: '1', // station
|
||||
A: '1', // station?
|
||||
L: id
|
||||
})
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ const parseLocation = (profile, opt, data, l) => {
|
|||
return Object.assign({
|
||||
type: 'location',
|
||||
id: res.id,
|
||||
poi: true,
|
||||
name: res.name
|
||||
}, res.location)
|
||||
}
|
||||
|
|
|
@ -10,19 +10,21 @@ const leadingZeros = /^0+/
|
|||
|
||||
// todo: what is s.rRefL?
|
||||
const parseLocation = (profile, opt, {lines}, l) => {
|
||||
const res = {type: 'location'}
|
||||
const lid = parse(l.lid, {delimiter: '@'})
|
||||
const res = {
|
||||
type: 'location',
|
||||
id: (l.extId || lid.L || '').replace(leadingZeros, '') || null
|
||||
}
|
||||
|
||||
if (l.crd) {
|
||||
res.latitude = l.crd.y / 1000000
|
||||
res.longitude = l.crd.x / 1000000
|
||||
}
|
||||
|
||||
const lid = parse(l.lid, {delimiter: '@'})
|
||||
const id = (l.extId || lid.L || '').replace(leadingZeros, '') || null
|
||||
|
||||
if (l.type === STATION) {
|
||||
const stop = {
|
||||
type: l.isMainMast ? 'station' : 'stop',
|
||||
id,
|
||||
id: res.id,
|
||||
name: l.name ? profile.parseStationName(l.name) : null,
|
||||
location: 'number' === typeof res.latitude ? res : null
|
||||
}
|
||||
|
@ -46,7 +48,7 @@ const parseLocation = (profile, opt, {lines}, l) => {
|
|||
|
||||
if (l.type === ADDRESS) res.address = l.name
|
||||
else res.name = l.name
|
||||
if (l.type === POI) res.id = id
|
||||
if (l.type === POI) res.poi = true
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue