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) {
|
2017-02-22 02:27:06 +00:00
|
|
|
for (var x in data) {
|
|
|
|
if (data[x].hasOwnProperty('latitude')) {
|
|
|
|
data[x]['latitude'] = new Number(data[x]['latitude']).toFixed(2);
|
|
|
|
}
|
|
|
|
if (data[x].hasOwnProperty('longitude')) {
|
|
|
|
data[x]['longitude'] = new Number(data[x]['longitude']).toFixed(2);
|
|
|
|
}
|
|
|
|
if (data[x].hasOwnProperty('altitude')) {
|
|
|
|
data[x]['altitude'] = new Number(data[x]['altitude']).toFixed(0);
|
|
|
|
}
|
|
|
|
}
|
2017-01-09 08:41:53 +00:00
|
|
|
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) {
|
2017-02-18 02:51:24 +00:00
|
|
|
for (var x in data) {
|
|
|
|
if (data[x].hasOwnProperty('latitude')) {
|
|
|
|
data[x]['latitude'] = new Number(data[x]['latitude']).toFixed(2);
|
|
|
|
}
|
|
|
|
if (data[x].hasOwnProperty('longitude')) {
|
|
|
|
data[x]['longitude'] = new Number(data[x]['longitude']).toFixed(2);
|
|
|
|
}
|
|
|
|
if (data[x].hasOwnProperty('altitude')) {
|
|
|
|
data[x]['altitude'] = new Number(data[x]['altitude']).toFixed(0);
|
|
|
|
}
|
|
|
|
}
|
2017-01-09 08:41:53 +00:00
|
|
|
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;
|