sjy-ecos/routes/api.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-02-06 09:10:14 +00:00
var GeoJSON = require('geojson');
2017-01-09 08:41:53 +00:00
var express = require('express');
var router = express.Router();
var models_gis = require('../model/sjy_gis.js');
var models_eco = require('../model/sjy_eco.js');
router.get('/', function (req, res, next) {
res.status(200).send('sjy')
});
router.get('/eco/:tab_name', function (req, res, next) {
var tab_name = req.params.tab_name;
models_eco.getAll(tab_name)
.then(function (data) {
res.status(200)
.json({
status: 'success',
data: data
});
})
.catch(function (err) { res.status(500).send(err) });
});
router.get('/gis/:tab_name', function (req, res, next) {
var tab_name = req.params.tab_name;
models_gis.getAll(tab_name)
.then(function (data) {
res.status(200)
.json({
status: 'success',
data: data
});
})
.catch(function (err) { res.status(500).send(err) });
});
2017-02-06 09:10:14 +00:00
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) });
});
2017-01-09 08:41:53 +00:00
module.exports = router;