mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parent
d3551d2e51
commit
07389ef418
4 changed files with 42 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const formatLocationIdentifier = require('./location-identifier')
|
||||||
const formatCoord = require('./coord')
|
const formatCoord = require('./coord')
|
||||||
|
|
||||||
const formatAddress = (a) => {
|
const formatAddress = (a) => {
|
||||||
|
@ -7,13 +8,16 @@ const formatAddress = (a) => {
|
||||||
throw new Error('invalid address')
|
throw new Error('invalid address')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const data = {
|
||||||
type: 'A',
|
A: '2', // address
|
||||||
name: a.address,
|
O: a.address,
|
||||||
crd: {
|
X: formatCoord(a.longitude),
|
||||||
x: formatCoord(a.longitude),
|
Y: formatCoord(a.latitude)
|
||||||
y: formatCoord(a.latitude)
|
|
||||||
}
|
}
|
||||||
|
if (a.id) data.L = a.id
|
||||||
|
return {
|
||||||
|
name: a.address,
|
||||||
|
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'
|
'use strict'
|
||||||
|
|
||||||
|
const formatLocationIdentifier = require('./location-identifier')
|
||||||
const formatCoord = require('./coord')
|
const formatCoord = require('./coord')
|
||||||
|
|
||||||
const formatPoi = (p) => {
|
const formatPoi = (p) => {
|
||||||
|
@ -8,13 +9,14 @@ const formatPoi = (p) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'P',
|
|
||||||
name: p.name,
|
name: p.name,
|
||||||
lid: 'L=' + p.id,
|
lid: formatLocationIdentifier({
|
||||||
crd: {
|
A: '4', // POI
|
||||||
x: formatCoord(p.longitude),
|
O: p.name,
|
||||||
y: formatCoord(p.latitude)
|
L: p.id,
|
||||||
}
|
X: formatCoord(p.longitude),
|
||||||
|
Y: formatCoord(p.latitude)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
'use strict'
|
'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
|
module.exports = formatStation
|
||||||
|
|
Loading…
Add table
Reference in a new issue