diff --git a/app.js b/app.js index 3d59fb6..0c1bab3 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,7 @@ var bodyParser = require('body-parser'); var ejs = require('ejs'); var fs = require('fs'); + if (process.env.NODE_ENV == '' || process.env.NODE_ENV == undefined) { process.env.NODE_ENV = 'development' } else { diff --git a/package.json b/package.json index 0d7966a..874ed6f 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "ejs": "~2.5.2", "express": "~4.14.0", "express-promise": "^0.4.0", + "geojson": "^0.4.1", "jquery": "^2.2.4", "morgan": "~1.7.0", "pg": "^6.1.2", diff --git a/routes/api.js b/routes/api.js index 890f0fb..c5acf9d 100644 --- a/routes/api.js +++ b/routes/api.js @@ -1,3 +1,5 @@ +var GeoJSON = require('geojson'); + var express = require('express'); var router = express.Router(); @@ -40,5 +42,21 @@ router.get('/gis/:tab_name', function (req, res, next) { .catch(function (err) { res.status(500).send(err) }); }); +router.get('/gis/geojson/:tab_name', function (req, res, next) { + + var tab_name = req.params.tab_name; + + models_gis.getAll(tab_name) + .then(function (data) { + GeoJSON.parse(data, { + Point: ['latitude', 'longitude'], + exclude: ['gid', 'id', 'the_geom'] + }, function (geojson) { + res.json(geojson) + }); + }) + .catch(function (err) { res.status(500).send(err) }); +}); + module.exports = router;