mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:07:08 +00:00
Add GeoJSON output of planned lines
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
|
||||
const { plan } = require('../../../lib/db');
|
||||
|
||||
module.exports = async function (req, res, next) {
|
||||
|
||||
try {
|
||||
res.status(200).send(await plan.list(req.params.project, req.query));
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
23
lib/www/server/api/middleware/plan/list/geojson.js
Normal file
23
lib/www/server/api/middleware/plan/list/geojson.js
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
const { plan } = require('../../../../lib/db');
|
||||
|
||||
const geojson = async function (req, res, next) {
|
||||
try {
|
||||
const plans = await plan.list(req.params.project, req.query);
|
||||
const response = plans.filter(plan => plan.geometry).map(plan => {
|
||||
const feature = {
|
||||
type: "Feature",
|
||||
geometry: plan.geometry,
|
||||
properties: plan
|
||||
};
|
||||
delete feature.properties.geometry;
|
||||
return feature;
|
||||
});
|
||||
res.status(200).send(response);
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = geojson;
|
||||
23
lib/www/server/api/middleware/plan/list/index.js
Normal file
23
lib/www/server/api/middleware/plan/list/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const json = require('./json');
|
||||
const geojson = require('./geojson');
|
||||
|
||||
module.exports = async function (req, res, next) {
|
||||
try {
|
||||
const handlers = {
|
||||
"application/json": json,
|
||||
"application/geo+json": geojson,
|
||||
};
|
||||
|
||||
const mimetype = req.accepts(Object.keys(handlers));
|
||||
|
||||
if (mimetype) {
|
||||
res.set("Content-Type", mimetype);
|
||||
await handlers[mimetype](req, res, next);
|
||||
} else {
|
||||
res.status(406).send();
|
||||
next();
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
14
lib/www/server/api/middleware/plan/list/json.js
Normal file
14
lib/www/server/api/middleware/plan/list/json.js
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
const { plan } = require('../../../../lib/db');
|
||||
|
||||
const json = async function (req, res, next) {
|
||||
try {
|
||||
const response = await plan.list(req.params.project, req.query);
|
||||
res.status(200).send(response);
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = json;
|
||||
Reference in New Issue
Block a user