Created
March 7, 2020 17:15
-
-
Save dbauszus-glx/282fdd658ef79439844a5b42c10a6e5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const auth = require('../../mod/auth/handler')({ | |
| public: true | |
| }) | |
| const dbs = require('../../mod/pg/dbs')() | |
| const _layers = require('../../mod/workspace/layers') | |
| const layers = [] | |
| module.exports = async (req, res) => { | |
| await auth(req, res) | |
| Object.assign(layers, [], await _layers(req, res)) | |
| if (res.finished) return | |
| const layer = layers[req.params.layer] | |
| var q = ` | |
| SELECT | |
| ${layer.qID || null} AS id, | |
| ST_asGeoJson(${layer.geom}) AS geomj | |
| FROM ${req.query.table};` | |
| var rows = await dbs[layer.dbs](q) | |
| if (rows instanceof Error) return res.status(500).send('Failed to query PostGIS table.') | |
| res.send(rows.map(row => ({ | |
| type: 'Feature', | |
| geometry: JSON.parse(row.geomj), | |
| properties: { | |
| id: row.id | |
| } | |
| }))) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment