2017-11-12 00:53:34 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-02-15 17:31:43 +01:00
|
|
|
const formatLocationIdentifier = require('./location-identifier')
|
2017-11-12 00:53:34 +01:00
|
|
|
const formatCoord = require('./coord')
|
|
|
|
|
2017-11-12 19:15:13 +01:00
|
|
|
const formatAddress = (a) => {
|
2017-12-12 23:40:12 +01:00
|
|
|
if (a.type !== 'location' || !a.latitude || !a.longitude || !a.address) {
|
2017-12-12 23:15:06 +01:00
|
|
|
throw new Error('invalid address')
|
|
|
|
}
|
2017-11-12 19:15:13 +01:00
|
|
|
|
2018-02-15 17:31:43 +01:00
|
|
|
const data = {
|
2019-02-07 17:46:49 +01:00
|
|
|
A: '2', // address?
|
2018-02-15 17:31:43 +01:00
|
|
|
O: a.address,
|
|
|
|
X: formatCoord(a.longitude),
|
|
|
|
Y: formatCoord(a.latitude)
|
|
|
|
}
|
|
|
|
if (a.id) data.L = a.id
|
2017-11-12 00:53:34 +01:00
|
|
|
return {
|
2019-02-07 17:46:49 +01:00
|
|
|
type: 'A', // address
|
2017-12-12 23:40:12 +01:00
|
|
|
name: a.address,
|
2018-02-15 17:31:43 +01:00
|
|
|
lid: formatLocationIdentifier(data)
|
2017-11-12 00:53:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = formatAddress
|