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 _ = require('lodash'); |
||||||
const DATUM = 'WGE'; |
const DATUM = 'WGE'; |
||||||
const external = require('../service/external'); |
const external = require('../service/external'); |
||||||
const logger = require( 'pelias-logger' ).get( 'api' ); |
|
||||||
|
|
||||||
"use strict"; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function converter( req, res, next) { |
function converter( req, res, next) { |
||||||
let result; |
|
||||||
try{ |
|
||||||
if(_.find(req.query, (val, key) => val === 'mgrs')){ |
if(_.find(req.query, (val, key) => val === 'mgrs')){ |
||||||
//If mgrs is specified as a conversion parameter
|
if(req.query.from === 'mgrs' && req.query.to === 'decdeg'){ |
||||||
//let mgrsConverter = new MGRS_converter(DATUM);
|
try{ |
||||||
if(req.query.from === 'mgrs' && req.query.to === 'decdeg'){ |
external.geotrans(req.query.q).then(function(gtResult){ |
||||||
logger.info("testing"); |
if(typeof gtResult === 'string' && gtResult.indexOf('ERROR') > -1){ |
||||||
result = external.geotrans(req.query.q); |
res.send(gtResult); |
||||||
logger.info(result); |
throw gtResult; |
||||||
} |
} |
||||||
} |
else{ |
||||||
if(typeof result === 'string' && result.indexOf('ERROR') > -1){ |
res.send(addQueryProperties(gtResult, req.query)); |
||||||
//Relay error
|
} |
||||||
throw result; |
}).catch(function(error){ |
||||||
|
res.send({'error':error}); |
||||||
|
}); |
||||||
|
} |
||||||
|
catch(error){ |
||||||
|
res.send({'error': error}); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
result.properties.from = req.query.from; |
} |
||||||
result.properties.to = req.query.to; |
|
||||||
if(result.properties.name.toLowerCase() !== req.query.q.toLowerCase()){ |
function addQueryProperties (geojson, query){ |
||||||
result.properties.name = req.query.q.toUpperCase(); |
geojson.properties.from = query.from; |
||||||
} |
geojson.properties.to = query.to; |
||||||
} |
return geojson; |
||||||
catch(error){ |
|
||||||
result = {"error": error}; |
|
||||||
} |
|
||||||
finally{ |
|
||||||
res.send(result); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
|
||||||
module.exports = converter; |
module.exports = converter; |
||||||
|
Loading…
Reference in new issue