Skip to content

Commit

Permalink
make POIs objects with poi: true 💥
Browse files Browse the repository at this point in the history
fixes #42
  • Loading branch information
derhuerst committed Feb 28, 2019
1 parent 4a79b91 commit eb3ffba
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion format/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion format/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
3 changes: 2 additions & 1 deletion format/poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion format/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
1 change: 1 addition & 0 deletions p/oebb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 8 additions & 6 deletions parse/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit eb3ffba

Please sign in to comment.