diff --git a/format/address.js b/format/address.js index 51e710dc..9395bfd6 100644 --- a/format/address.js +++ b/format/address.js @@ -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) } diff --git a/format/location.js b/format/location.js index eb243d16..1ee26dc9 100644 --- a/format/location.js +++ b/format/location.js @@ -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}`) diff --git a/format/poi.js b/format/poi.js index 22abe0f5..2f60a826 100644 --- a/format/poi.js +++ b/format/poi.js @@ -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), diff --git a/format/station.js b/format/station.js index a2440c47..26c42dda 100644 --- a/format/station.js +++ b/format/station.js @@ -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 }) } diff --git a/p/oebb/index.js b/p/oebb/index.js index 7d2ca5c3..54e62058 100644 --- a/p/oebb/index.js +++ b/p/oebb/index.js @@ -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) } diff --git a/parse/location.js b/parse/location.js index 95bf7cf6..126829b7 100644 --- a/parse/location.js +++ b/parse/location.js @@ -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 }