diff --git a/format/address.js b/format/address.js index 2774c380..51e710dc 100644 --- a/format/address.js +++ b/format/address.js @@ -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) } } diff --git a/format/location-identifier.js b/format/location-identifier.js new file mode 100644 index 00000000..83fedd3a --- /dev/null +++ b/format/location-identifier.js @@ -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 diff --git a/format/poi.js b/format/poi.js index 3991e4c6..22abe0f5 100644 --- a/format/poi.js +++ b/format/poi.js @@ -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) + }) } } diff --git a/format/station.js b/format/station.js index 418e5181..a2440c47 100644 --- a/format/station.js +++ b/format/station.js @@ -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