mirror of https://github.com/pelias/api.git
Gibran Parvez
7 years ago
4 changed files with 63 additions and 54 deletions
@ -1,43 +1,37 @@
|
||||
"use strict"; |
||||
|
||||
'use strict'; |
||||
|
||||
const _ = require('lodash'); |
||||
const DATUM = 'WGE'; |
||||
const external = require('../service/external'); |
||||
const logger = require( 'pelias-logger' ).get( 'api' ); |
||||
|
||||
"use strict"; |
||||
|
||||
|
||||
|
||||
function converter( req, res, next) { |
||||
let result; |
||||
try{ |
||||
if(_.find(req.query, (val, key) => val === 'mgrs')){ |
||||
//If mgrs is specified as a conversion parameter
|
||||
//let mgrsConverter = new MGRS_converter(DATUM);
|
||||
if(req.query.from === 'mgrs' && req.query.to === 'decdeg'){ |
||||
logger.info("testing"); |
||||
result = external.geotrans(req.query.q); |
||||
logger.info(result); |
||||
} |
||||
} |
||||
if(typeof result === 'string' && result.indexOf('ERROR') > -1){ |
||||
//Relay error
|
||||
throw result; |
||||
try{ |
||||
external.geotrans(req.query.q).then(function(gtResult){ |
||||
if(typeof gtResult === 'string' && gtResult.indexOf('ERROR') > -1){ |
||||
res.send(gtResult); |
||||
throw gtResult; |
||||
} |
||||
result.properties.from = req.query.from; |
||||
result.properties.to = req.query.to; |
||||
if(result.properties.name.toLowerCase() !== req.query.q.toLowerCase()){ |
||||
result.properties.name = req.query.q.toUpperCase(); |
||||
else{ |
||||
res.send(addQueryProperties(gtResult, req.query)); |
||||
} |
||||
}).catch(function(error){ |
||||
res.send({'error':error}); |
||||
}); |
||||
} |
||||
catch(error){ |
||||
result = {"error": error}; |
||||
res.send({'error': error}); |
||||
} |
||||
} |
||||
finally{ |
||||
res.send(result); |
||||
} |
||||
} |
||||
|
||||
function addQueryProperties (geojson, query){ |
||||
geojson.properties.from = query.from; |
||||
geojson.properties.to = query.to; |
||||
return geojson; |
||||
} |
||||
|
||||
module.exports = converter; |
||||
|
Loading…
Reference in new issue