85 lines
2.0 KiB
JavaScript
85 lines
2.0 KiB
JavaScript
var GeoJSON = require('geojson');
|
|
|
|
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) {
|
|
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);
|
|
}
|
|
}
|
|
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) {
|
|
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);
|
|
}
|
|
}
|
|
res.status(200)
|
|
.json({
|
|
status: 'success',
|
|
data: data
|
|
});
|
|
})
|
|
.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;
|