2019-09-17 13:03:20 -04:00
|
|
|
import { strictParseInt } from "../parse";
|
2019-11-07 02:48:51 -05:00
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
import { DataConfig } from "./types";
|
2019-09-17 13:03:20 -04:00
|
|
|
|
|
|
|
const BUILDING_LAYER_DEFINITIONS = {
|
|
|
|
base_light: `(
|
|
|
|
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`,
|
|
|
|
base_night: `(
|
|
|
|
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`,
|
|
|
|
date_year: `(
|
|
|
|
SELECT
|
|
|
|
b.date_year as date_year,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
2019-10-02 08:32:00 -04:00
|
|
|
) as date_year`,
|
2019-09-17 13:03:20 -04:00
|
|
|
size_storeys: `(
|
|
|
|
SELECT
|
|
|
|
(
|
|
|
|
coalesce(b.size_storeys_attic, 0) +
|
|
|
|
coalesce(b.size_storeys_core, 0)
|
|
|
|
) as size_storeys,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
2019-10-02 08:32:00 -04:00
|
|
|
) as size_stories`,
|
2020-01-16 09:52:10 -05:00
|
|
|
size_height: `(
|
|
|
|
SELECT
|
2020-01-16 12:04:17 -05:00
|
|
|
b.size_height_apex as size_height,
|
2020-01-16 09:52:10 -05:00
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE g.geometry_id = b.geometry_id
|
|
|
|
) as size_height`,
|
2020-04-01 07:18:44 -04:00
|
|
|
construction_core_material: `(
|
|
|
|
SELECT
|
2020-04-17 12:01:21 -04:00
|
|
|
b.construction_core_material::text as construction_core_material,
|
2020-04-01 07:18:44 -04:00
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE g.geometry_id = b.geometry_id
|
2020-04-17 12:01:21 -04:00
|
|
|
) as construction_core_material`,
|
2019-09-17 13:03:20 -04:00
|
|
|
location: `(
|
|
|
|
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 +
|
|
|
|
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
|
|
|
|
) as location_info_count,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as location`,
|
|
|
|
likes: `(
|
|
|
|
SELECT
|
|
|
|
g.geometry_geom,
|
|
|
|
b.likes_total as likes
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
AND b.likes_total > 0
|
2019-10-02 08:32:00 -04:00
|
|
|
) as likes`,
|
2020-02-09 17:51:03 -05:00
|
|
|
planning_combined: `(
|
|
|
|
SELECT
|
|
|
|
g.geometry_geom,
|
|
|
|
(
|
|
|
|
CASE
|
|
|
|
WHEN b.planning_list_cat = 'Listed Building' and b.planning_list_grade = 'I' THEN 'Grade I Listed'
|
|
|
|
WHEN b.planning_list_cat = 'Listed Building' and b.planning_list_grade = 'II*' THEN 'Grade II* Listed'
|
|
|
|
WHEN b.planning_list_cat = 'Listed Building' and b.planning_list_grade = 'II' THEN 'Grade II Listed'
|
|
|
|
WHEN b.planning_in_local_list THEN 'Locally Listed'
|
|
|
|
ELSE 'None'
|
|
|
|
END
|
2020-02-16 15:44:45 -05:00
|
|
|
) as listing_type,
|
|
|
|
b.planning_in_conservation_area
|
2020-02-09 17:51:03 -05:00
|
|
|
FROM geometries as g
|
|
|
|
JOIN buildings as b
|
|
|
|
ON g.geometry_id = b.geometry_id
|
|
|
|
WHERE
|
|
|
|
b.planning_in_conservation_area
|
|
|
|
OR b.planning_in_local_list
|
|
|
|
OR b.planning_list_cat is not null
|
2020-04-17 12:01:21 -04:00
|
|
|
) as planning_combined`,
|
2019-09-17 13:03:20 -04:00
|
|
|
conservation_area: `(
|
|
|
|
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
|
2019-10-02 08:32:00 -04:00
|
|
|
) as conservation_area`,
|
|
|
|
sust_dec: `(
|
|
|
|
SELECT
|
|
|
|
b.sust_dec::text as sust_dec,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
2019-10-02 09:34:44 -04:00
|
|
|
) as sust_dec`,
|
|
|
|
building_attachment_form: `(
|
|
|
|
SELECT
|
|
|
|
b.building_attachment_form::text as building_attachment_form,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM
|
|
|
|
geometries as g,
|
|
|
|
buildings as b
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = b.geometry_id
|
|
|
|
) as building_attachment_form`,
|
2019-12-02 10:10:45 -05:00
|
|
|
landuse: `(
|
|
|
|
SELECT
|
|
|
|
b.current_landuse_order,
|
|
|
|
g.geometry_geom
|
|
|
|
FROM geometries as g
|
|
|
|
JOIN buildings as b
|
|
|
|
ON g.geometry_id = b.geometry_id
|
|
|
|
) as current_landuse_order`,
|
2019-09-17 13:03:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const GEOMETRY_FIELD = 'geometry_geom';
|
|
|
|
|
2019-10-07 12:27:22 -04:00
|
|
|
function getBuildingLayerNames() {
|
|
|
|
return Object.keys(BUILDING_LAYER_DEFINITIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllLayerNames() {
|
|
|
|
return ['highlight', ...getBuildingLayerNames()];
|
|
|
|
}
|
|
|
|
|
2019-09-17 13:03:20 -04:00
|
|
|
function getBuildingsDataConfig(tileset: string, dataParams: any): DataConfig {
|
|
|
|
const table = BUILDING_LAYER_DEFINITIONS[tileset];
|
|
|
|
|
|
|
|
if(table == undefined) {
|
|
|
|
throw new Error('Invalid tileset requested');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
geometry_field: GEOMETRY_FIELD,
|
|
|
|
table: table
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHighlightDataConfig(tileset: string, dataParams: any): DataConfig {
|
|
|
|
let { highlight, base } = dataParams;
|
|
|
|
|
|
|
|
highlight = strictParseInt(highlight);
|
2019-09-17 13:19:21 -04:00
|
|
|
base = base || 'default';
|
2019-09-17 13:03:20 -04:00
|
|
|
|
2019-09-17 13:19:21 -04:00
|
|
|
if(isNaN(highlight) || base.match(/^\w+$/) == undefined) {
|
2019-09-17 13:03:20 -04:00
|
|
|
throw new Error('Bad parameters for highlight layer');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
geometry_field: GEOMETRY_FIELD,
|
|
|
|
table: `(
|
|
|
|
SELECT
|
|
|
|
g.geometry_geom,
|
|
|
|
'${base}' as base_layer
|
|
|
|
FROM
|
|
|
|
geometries as g
|
|
|
|
WHERE
|
|
|
|
g.geometry_id = ${highlight}
|
|
|
|
) as highlight`
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2019-10-07 12:27:22 -04:00
|
|
|
getBuildingLayerNames,
|
|
|
|
getAllLayerNames,
|
2019-09-17 13:03:20 -04:00
|
|
|
getBuildingsDataConfig,
|
|
|
|
getHighlightDataConfig
|
|
|
|
};
|