mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
'use strict'; |
|
|
|
const _ = require('lodash'); |
|
const DATUM = 'WGE'; |
|
const external = require('../service/external'); |
|
|
|
|
|
function converter( req, res, next) { |
|
if(_.find(req.query, (val, key) => val === 'mgrs')){ |
|
if(req.query.from === 'mgrs' && req.query.to === 'decdeg'){ |
|
try{ |
|
external.geotrans(req.query.q).then(function(gtResult){ |
|
if(typeof gtResult === 'string' && gtResult.indexOf('ERROR') > -1){ |
|
res.send(gtResult); |
|
throw gtResult; |
|
} |
|
else{ |
|
res.send(addQueryProperties(gtResult, req.query)); |
|
} |
|
}).catch(function(error){ |
|
res.send({'error':error}); |
|
}); |
|
} |
|
catch(error){ |
|
res.send({'error': error}); |
|
} |
|
} |
|
} |
|
} |
|
|
|
function addQueryProperties (geojson, query){ |
|
geojson.properties.from = query.from; |
|
geojson.properties.to = query.to; |
|
return geojson; |
|
} |
|
|
|
module.exports = converter;
|
|
|