2019-09-17 13:03:20 -04:00
|
|
|
import { TileCache } from "./tileCache";
|
2019-10-07 08:34:22 -04:00
|
|
|
import { BoundingBox, TileParams, Tile } from "./types";
|
2019-09-17 13:35:05 -04:00
|
|
|
import { getBuildingsDataConfig, getHighlightDataConfig, BUILDING_LAYER_DEFINITIONS } from "./dataDefinition";
|
2019-10-07 08:34:22 -04:00
|
|
|
import { isOutsideExtent } from "./util";
|
|
|
|
import { renderDataSourceTile } from "./renderers/renderDataSourceTile";
|
|
|
|
import { getTileWithCaching } from "./renderers/getTileWithCaching";
|
|
|
|
import { stitchTile } from "./renderers/stitchTile";
|
|
|
|
import { createBlankTile } from "./renderers/createBlankTile";
|
2019-09-17 13:35:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all tilesets handled by the tile server
|
|
|
|
*/
|
|
|
|
const allTilesets = ['highlight', ...Object.keys(BUILDING_LAYER_DEFINITIONS)];
|
2019-09-17 13:03:20 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Zoom level when we switch from rendering direct from database to instead composing tiles
|
|
|
|
* from the zoom level below - gets similar effect, with much lower load on Postgres
|
|
|
|
*/
|
|
|
|
const STITCH_THRESHOLD = 12;
|
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
/**
|
|
|
|
* Hard-code extent so we can short-circuit rendering and return empty/transparent tiles outside the area of interest
|
|
|
|
* bbox in CRS epsg:3857 in form: [w, s, e, n]
|
|
|
|
*/
|
|
|
|
const EXTENT_BBOX: BoundingBox = [-61149.622628, 6667754.851372, 28128.826409, 6744803.375884];
|
2019-09-17 13:03:20 -04:00
|
|
|
|
|
|
|
const tileCache = new TileCache(
|
|
|
|
process.env.TILECACHE_PATH,
|
|
|
|
{
|
2019-10-02 09:34:44 -04:00
|
|
|
tilesets: ['date_year', 'size_storeys', 'location', 'likes', 'conservation_area', 'sust_dec', 'building_attachment_form'],
|
2019-09-17 13:03:20 -04:00
|
|
|
minZoom: 9,
|
|
|
|
maxZoom: 18,
|
|
|
|
scales: [1, 2]
|
|
|
|
},
|
|
|
|
({ tileset, z }: TileParams) => (tileset === 'date_year' && z <= 16) ||
|
|
|
|
((tileset === 'base_light' || tileset === 'base_night') && z <= 17) ||
|
|
|
|
z <= 13
|
|
|
|
);
|
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
const renderBuildingTile = (t: TileParams, d: any) => renderDataSourceTile(t, d, getBuildingsDataConfig);
|
|
|
|
const renderHighlightTile = (t: TileParams, d: any) => renderDataSourceTile(t, d, getHighlightDataConfig);
|
2019-09-17 13:03:20 -04:00
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
function cacheOrCreateBuildingTile(tileParams: TileParams, dataParams: any): Promise<Tile> {
|
|
|
|
return getTileWithCaching(tileParams, dataParams, tileCache, stitchOrRenderBuildingTile);
|
|
|
|
}
|
2019-09-17 13:03:20 -04:00
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
function stitchOrRenderBuildingTile(tileParams: TileParams, dataParams: any): Promise<Tile> {
|
|
|
|
if (tileParams.z <= STITCH_THRESHOLD) {
|
|
|
|
// stitch tile, using cache recursively
|
|
|
|
return stitchTile(tileParams, dataParams, cacheOrCreateBuildingTile);
|
|
|
|
} else {
|
|
|
|
return renderBuildingTile(tileParams, dataParams);
|
|
|
|
}
|
|
|
|
}
|
2019-09-17 13:03:20 -04:00
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
function renderTile(tileParams: TileParams, dataParams: any): Promise<Tile> {
|
|
|
|
if (isOutsideExtent(tileParams, EXTENT_BBOX)) {
|
|
|
|
return createBlankTile();
|
|
|
|
}
|
2019-09-17 13:03:20 -04:00
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
if (tileParams.tileset === 'highlight') {
|
|
|
|
return renderHighlightTile(tileParams, dataParams);
|
|
|
|
}
|
2019-09-17 13:03:20 -04:00
|
|
|
|
2019-10-07 08:34:22 -04:00
|
|
|
return cacheOrCreateBuildingTile(tileParams, dataParams);
|
|
|
|
}
|
2019-09-17 13:03:20 -04:00
|
|
|
|
|
|
|
export {
|
2019-09-17 13:35:05 -04:00
|
|
|
allTilesets,
|
2019-10-07 08:34:22 -04:00
|
|
|
renderTile,
|
2019-09-17 13:03:20 -04:00
|
|
|
tileCache
|
2019-09-17 13:35:05 -04:00
|
|
|
};
|