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; |
||||
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}); |
||||
} |
||||
} |
||||
} |
||||
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(); |
||||
} |
||||
} |
||||
catch(error){ |
||||
result = {"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; |
||||
|
@ -1,18 +1,23 @@
|
||||
const request = require('request'); |
||||
const logger = require('pelias-logger').get('api'); |
||||
|
||||
"use strict"; |
||||
|
||||
async function geotrans(coord) {
|
||||
const axios = require('axios'); |
||||
const geotransIP = process.env.GEOTRANS_IP; |
||||
|
||||
function geotrans(coord) {
|
||||
let result; |
||||
request(`http://10.0.2.62:3150?datum=WGE&coord=${coord}`, function (error, response, body) { |
||||
logger.info(response.body); |
||||
result = response.body; |
||||
return axios.get(`http://${geotransIP}:3150`, { |
||||
params:{ |
||||
'datum':'WGE', |
||||
'coord':coord |
||||
} |
||||
}) |
||||
.then(function (response){ |
||||
return response.data; |
||||
}).catch(function (reason){ |
||||
return reason; |
||||
}); |
||||
return result; |
||||
|
||||
} |
||||
|
||||
|
||||
module.exports = { |
||||
geotrans: geotrans |
||||
}; |
Loading…
Reference in new issue