mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:27:07 +00:00
Add endpoint for retrieving real-time data as GeoJSON
This commit is contained in:
@@ -134,6 +134,9 @@ app.map({
|
||||
// },
|
||||
'/navdata/': {
|
||||
get: [ mw.navdata.get ],
|
||||
'gis/:featuretype(line|point)': {
|
||||
get: [ mw.gis.navdata.get ]
|
||||
}
|
||||
}
|
||||
//
|
||||
// '/user': {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
module.exports = {
|
||||
project: require('./project')
|
||||
project: require('./project'),
|
||||
navdata: require('./navdata')
|
||||
};
|
||||
|
||||
40
lib/www/server/api/middleware/gis/navdata/get.js
Normal file
40
lib/www/server/api/middleware/gis/navdata/get.js
Normal 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);
|
||||
}
|
||||
|
||||
};
|
||||
3
lib/www/server/api/middleware/gis/navdata/index.js
Normal file
3
lib/www/server/api/middleware/gis/navdata/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
get: require('./get')
|
||||
};
|
||||
Reference in New Issue
Block a user