Add endpoint for retrieving real-time data as GeoJSON

This commit is contained in:
D. Berge
2020-09-01 10:58:37 +02:00
parent 557d87de72
commit eded667d79
7 changed files with 136 additions and 1 deletions

View File

@@ -134,6 +134,9 @@ app.map({
// },
'/navdata/': {
get: [ mw.navdata.get ],
'gis/:featuretype(line|point)': {
get: [ mw.gis.navdata.get ]
}
}
//
// '/user': {

View File

@@ -1,3 +1,4 @@
module.exports = {
project: require('./project')
project: require('./project'),
navdata: require('./navdata')
};

View File

@@ -0,0 +1,40 @@
const { gis } = require('../../../../lib/db');
function makeOptions (query) {
const options = {};
if (query.hasOwnProperty("limit")) {
options.limit = Math.abs(Number(query.limit));
}
if (query.hasOwnProperty("bbox")) {
options.bbox = query.bbox
.split(",")
.slice(0, 4)
.map( (n, i) => (i % 2) ? Number(n) % 90 : Number(n) % 180 );
if (options.bbox.some(n => isNaN(n))) {
delete options.bbox;
}
}
return options;
}
module.exports = async function (req, res, next) {
const handler = req.params.featuretype == "point"
? gis.navdata.get.points
: gis.navdata.get.lines;
const options = makeOptions(req.query);
try {
res.status(200).send(await handler(options));
next();
} catch (err) {
next(err);
}
};

View File

@@ -0,0 +1,3 @@
module.exports = {
get: require('./get')
};