mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
parent
d3551d2e51
commit
07389ef418
4 changed files with 42 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const formatLocationIdentifier = require('./location-identifier')
|
||||
const formatCoord = require('./coord')
|
||||
|
||||
const formatAddress = (a) => {
|
||||
|
@ -7,13 +8,16 @@ const formatAddress = (a) => {
|
|||
throw new Error('invalid address')
|
||||
}
|
||||
|
||||
const data = {
|
||||
A: '2', // address
|
||||
O: a.address,
|
||||
X: formatCoord(a.longitude),
|
||||
Y: formatCoord(a.latitude)
|
||||
}
|
||||
if (a.id) data.L = a.id
|
||||
return {
|
||||
type: 'A',
|
||||
name: a.address,
|
||||
crd: {
|
||||
x: formatCoord(a.longitude),
|
||||
y: formatCoord(a.latitude)
|
||||
}
|
||||
lid: formatLocationIdentifier(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
format/location-identifier.js
Normal file
14
format/location-identifier.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
const sep = '@'
|
||||
|
||||
const formatLocationIdentifier = (data) => {
|
||||
let str = ''
|
||||
for (let key in data) {
|
||||
if (!Object.prototype.hasOwnProperty.call(data, key)) continue
|
||||
str += key + '=' + data[key] + sep // todo: escape, but how?
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
module.exports = formatLocationIdentifier
|
|
@ -1,5 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const formatLocationIdentifier = require('./location-identifier')
|
||||
const formatCoord = require('./coord')
|
||||
|
||||
const formatPoi = (p) => {
|
||||
|
@ -8,13 +9,14 @@ const formatPoi = (p) => {
|
|||
}
|
||||
|
||||
return {
|
||||
type: 'P',
|
||||
name: p.name,
|
||||
lid: 'L=' + p.id,
|
||||
crd: {
|
||||
x: formatCoord(p.longitude),
|
||||
y: formatCoord(p.latitude)
|
||||
}
|
||||
lid: formatLocationIdentifier({
|
||||
A: '4', // POI
|
||||
O: p.name,
|
||||
L: p.id,
|
||||
X: formatCoord(p.longitude),
|
||||
Y: formatCoord(p.latitude)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
'use strict'
|
||||
|
||||
const formatStation = id => ({type: 'S', lid: 'L=' + id})
|
||||
const formatLocationIdentifier = require('./location-identifier')
|
||||
|
||||
const formatStation = (id) => {
|
||||
return {
|
||||
// todo: name necessary?
|
||||
lid: formatLocationIdentifier({
|
||||
A: '1', // station
|
||||
L: id
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = formatStation
|
||||
|
|
Loading…
Add table
Reference in a new issue