From 70c05071a8bff62b01ca74f800ae18d002bcb56e Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Tue, 17 Sep 2019 18:01:09 +0100 Subject: [PATCH] Add windowed renderer --- app/src/tiles/renderers/windowedRenderer.ts | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/src/tiles/renderers/windowedRenderer.ts diff --git a/app/src/tiles/renderers/windowedRenderer.ts b/app/src/tiles/renderers/windowedRenderer.ts new file mode 100644 index 00000000..b63e901e --- /dev/null +++ b/app/src/tiles/renderers/windowedRenderer.ts @@ -0,0 +1,34 @@ +import { Image } from "mapnik"; + +import { BoundingBox, TileParams, TileRenderer } from "../types"; +import { getXYZ } from "../util"; + +class WindowedRenderer implements TileRenderer { + constructor( + /** Bounding box defining the renderer window */ + public bbox: BoundingBox, + + /** Renderer to use for tile requests inside window */ + public insideWindowRenderer: TileRenderer, + + /** Renderer to use for tile requests outside window */ + public outsideWindowRenderer: TileRenderer + ) {} + + getTile(tileParams: TileParams, dataParams: any): Promise { + if(this.isOutsideExtent(tileParams)) { + return this.outsideWindowRenderer.getTile(tileParams, dataParams); + } else { + return this.insideWindowRenderer.getTile(tileParams, dataParams); + } + } + + private isOutsideExtent({x, y, z}: TileParams) { + const xy = getXYZ(this.bbox, z); + return xy.minY > y || xy.maxY < y || xy.minX > x || xy.maxX < x; + } +} + +export { + WindowedRenderer +};