2018-09-30 14:50:09 -04:00
|
|
|
/**
|
|
|
|
* Tileserver routes for Express app
|
|
|
|
*
|
|
|
|
*/
|
2018-09-10 05:44:32 -04:00
|
|
|
import express from 'express';
|
|
|
|
|
2019-01-22 17:37:44 -05:00
|
|
|
import { render_tile } from './tile';
|
2019-02-24 07:17:59 -05:00
|
|
|
import { strictParseInt } from '../parse';
|
2018-09-10 05:44:32 -04:00
|
|
|
|
|
|
|
// tiles router
|
|
|
|
const router = express.Router()
|
|
|
|
|
|
|
|
// basic geometry tiles
|
2018-10-25 05:16:18 -04:00
|
|
|
router.get('/base_light/:z/:x/:y.png', function(req, res) {
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
|
|
|
b.location_number as location_number,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as outline`
|
|
|
|
const style_def = ['base_light']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-10-25 05:16:18 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// dark theme
|
|
|
|
router.get('/base_night/:z/:x/:y.png', function(req, res) {
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
|
|
|
b.location_number as location_number,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as outline`
|
|
|
|
const style_def = ['base_night']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-09-10 05:44:32 -04:00
|
|
|
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 table_def = `(
|
2018-09-11 18:29:30 -04:00
|
|
|
SELECT
|
2018-09-30 16:53:57 -04:00
|
|
|
g.geometry_id = ${geometry_id} as focus,
|
2018-09-11 18:29:30 -04:00
|
|
|
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']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-09-10 05:44:32 -04:00
|
|
|
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 table_def = 'geometries'
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
2018-09-30 11:17:59 -04:00
|
|
|
b.date_year as date_year,
|
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 = ['date_year']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-09-10 05:44:32 -04:00
|
|
|
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 table_def = 'geometries'
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
2018-09-30 18:06:30 -04:00
|
|
|
(
|
|
|
|
coalesce(b.size_storeys_attic, 0) +
|
|
|
|
coalesce(b.size_storeys_core, 0)
|
|
|
|
) 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']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-09-10 05:44:32 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-10-25 07:39:41 -04:00
|
|
|
// location information depth
|
|
|
|
router.get('/location/:z/:x/:y.png', function(req, res) {
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
|
|
|
(
|
|
|
|
case when b.location_name is null then 0 else 1 end +
|
|
|
|
case when b.location_number is null then 0 else 1 end +
|
|
|
|
case when b.location_street is null then 0 else 1 end +
|
|
|
|
case when b.location_line_two is null then 0 else 1 end +
|
|
|
|
case when b.location_town is null then 0 else 1 end +
|
|
|
|
case when b.location_postcode is null then 0 else 1 end +
|
|
|
|
case when b.location_latitude is null then 0 else 1 end +
|
2019-01-22 16:40:35 -05:00
|
|
|
case when b.location_longitude is null then 0 else 1 end +
|
|
|
|
case when b.ref_toid is null then 0 else 1 end +
|
|
|
|
case when b.ref_osm_id is null then 0 else 1 end
|
2018-10-25 07:39:41 -04:00
|
|
|
) as location_info_count,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as location`
|
|
|
|
const style_def = ['location_info_count']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-10-25 07:39:41 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-10-25 08:48:48 -04:00
|
|
|
|
2019-01-19 11:55:30 -05:00
|
|
|
// likes
|
2018-10-25 08:48:48 -04:00
|
|
|
router.get('/likes/:z/:x/:y.png', function(req, res) {
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
2018-11-21 17:06:22 -05:00
|
|
|
g.geometry_geom,
|
|
|
|
b.likes_total as likes
|
2018-10-25 08:48:48 -04:00
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
AND b.likes_total > 0
|
|
|
|
) as location`
|
|
|
|
const style_def = ['likes']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2018-10-25 08:48:48 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2019-01-19 11:55:30 -05:00
|
|
|
|
|
|
|
// conservation status
|
|
|
|
router.get('/conservation_area/:z/:x/:y.png', function(req, res) {
|
|
|
|
const table_def = `(
|
|
|
|
SELECT
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
AND b.planning_in_conservation_area = true
|
|
|
|
) as conservation_area`
|
|
|
|
const style_def = ['planning_in_conservation_area']
|
2019-01-22 17:37:44 -05:00
|
|
|
render_tile(req.params, table_def, style_def, function(err, im) {
|
2019-01-19 11:55:30 -05:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'image/png'})
|
|
|
|
res.end(im.encodeSync('png'))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-09-10 05:44:32 -04:00
|
|
|
export default router;
|