kopia lustrzana https://github.com/manuelkasper/sotlas-api
Add endpoints to download GeoJSON data for associations/regions
rodzic
325ca0b702
commit
8f065a5cc8
73
geoexport.js
73
geoexport.js
|
@ -48,6 +48,24 @@ router.get('/associations/:association.kml', (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/associations/:association.geojson', (req, res) => {
|
||||||
|
res.cacheControl = {
|
||||||
|
noCache: true
|
||||||
|
};
|
||||||
|
|
||||||
|
res.set('Content-Type', 'application/geo+json');
|
||||||
|
res.set('Content-Disposition', 'attachment; filename="' + req.params.association + '.geojson"');
|
||||||
|
geoJsonForQuery('^' + req.params.association + '/', req.query, (err, geoJson) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(geoJson).end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/regions/:association/:region.gpx', (req, res) => {
|
router.get('/regions/:association/:region.gpx', (req, res) => {
|
||||||
res.cacheControl = {
|
res.cacheControl = {
|
||||||
noCache: true
|
noCache: true
|
||||||
|
@ -89,6 +107,24 @@ router.get('/regions/:association/:region.kml', (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/regions/:association/:region.geojson', (req, res) => {
|
||||||
|
res.cacheControl = {
|
||||||
|
noCache: true
|
||||||
|
};
|
||||||
|
|
||||||
|
res.set('Content-Type', 'application/geo+json');
|
||||||
|
res.set('Content-Disposition', 'attachment; filename="' + req.params.association + '_' + req.params.region + '.geojson"');
|
||||||
|
geoJsonForQuery('^' + req.params.association + '/' + req.params.region + '-', req.query, (err, geoJson) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(geoJson).end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function gpxForQuery(query, name, options, callback) {
|
function gpxForQuery(query, name, options, callback) {
|
||||||
let filter = {code: {$regex: query}};
|
let filter = {code: {$regex: query}};
|
||||||
|
@ -259,6 +295,43 @@ function kmlForRegion(associationCode, regionCode, options, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function geoJsonForQuery(query, options, callback) {
|
||||||
|
let filter = {code: {$regex: query}};
|
||||||
|
if (!options.inactive) {
|
||||||
|
filter.validFrom = {$lte: new Date()};
|
||||||
|
filter.validTo = {$gte: new Date()};
|
||||||
|
}
|
||||||
|
db.getDb().collection('summits').find(filter).sort({code: 1}).toArray((err, summits) => {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let features = summits.map(summit => {
|
||||||
|
return {
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [summit.coordinates.longitude, summit.coordinates.latitude]
|
||||||
|
},
|
||||||
|
id: summit.code,
|
||||||
|
properties: {
|
||||||
|
code: summit.code,
|
||||||
|
name: summit.name,
|
||||||
|
title: summitName(summit, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let geojson = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, geojson);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function summitName(summit, options) {
|
function summitName(summit, options) {
|
||||||
let name = summit.code;
|
let name = summit.code;
|
||||||
let nameopts = [];
|
let nameopts = [];
|
||||||
|
|
Ładowanie…
Reference in New Issue