2018-09-10 05:44:32 -04:00
|
|
|
import express from 'express';
|
|
|
|
|
|
|
|
import { get_bbox, render_tile } from './tile';
|
2018-09-13 18:55:53 -04:00
|
|
|
import { strictParseInt } from './parse';
|
2018-09-10 05:44:32 -04:00
|
|
|
|
|
|
|
// tiles router
|
|
|
|
const router = express.Router()
|
|
|
|
|
|
|
|
// basic geometry tiles
|
|
|
|
router.get('/outline/:z/:x/:y.png', function(req, res) {
|
|
|
|
const bbox = get_bbox(req.params)
|
|
|
|
const table_def = 'geometries'
|
|
|
|
const style_def = ['polygon']
|
|
|
|
render_tile(bbox, table_def, style_def, function(err, im) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// highlight single geometry
|
|
|
|
router.get('/highlight/:z/:x/:y.png', function(req, res) {
|
|
|
|
const { highlight } = req.query
|
2018-09-13 18:55:53 -04:00
|
|
|
const geometry_id = strictParseInt(highlight);
|
|
|
|
if(isNaN(geometry_id)){
|
|
|
|
res.status(400).send({error:'Bad parameter'})
|
|
|
|
return
|
|
|
|
}
|
2018-09-10 05:44:32 -04:00
|
|
|
const bbox = get_bbox(req.params)
|
|
|
|
const table_def = `(
|
2018-09-11 18:29:30 -04:00
|
|
|
SELECT
|
|
|
|
(g.geometry_id = ${geometry_id}) as focus,
|
|
|
|
cast(
|
|
|
|
b.building_doc->>'location_number'
|
|
|
|
as text
|
|
|
|
) as location_number,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
2018-09-10 05:44:32 -04:00
|
|
|
) as highlight`
|
|
|
|
const style_def = ['highlight']
|
|
|
|
render_tile(bbox, table_def, style_def, function(err, im) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// date_year choropleth
|
|
|
|
router.get('/date_year/:z/:x/:y.png', function(req, res) {
|
|
|
|
const bbox = get_bbox(req.params)
|
|
|
|
// const table_def = 'geometries'
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
|
|
|
cast(
|
2018-09-13 18:55:53 -04:00
|
|
|
NULLIF(b.building_doc->>'date_year', '')
|
2018-09-10 05:44:32 -04:00
|
|
|
as integer
|
|
|
|
) as date_year,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as outline`
|
|
|
|
const style_def = ['date_year']
|
|
|
|
render_tile(bbox, table_def, style_def, function(err, im) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// date_year choropleth
|
|
|
|
router.get('/size_storeys/:z/:x/:y.png', function(req, res) {
|
|
|
|
const bbox = get_bbox(req.params)
|
|
|
|
// const table_def = 'geometries'
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
|
|
|
cast(
|
2018-09-13 18:55:53 -04:00
|
|
|
NULLIF(b.building_doc->>'size_attic', '')
|
2018-09-10 05:44:32 -04:00
|
|
|
as integer
|
2018-09-13 18:55:53 -04:00
|
|
|
) +
|
|
|
|
cast(
|
|
|
|
NULLIF(b.building_doc->>'size_core', '')
|
|
|
|
as integer
|
|
|
|
)
|
|
|
|
as size_storeys,
|
2018-09-10 05:44:32 -04:00
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as outline`
|
|
|
|
const style_def = ['size_storeys']
|
|
|
|
render_tile(bbox, table_def, style_def, function(err, im) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
export default router;
|