From ae0202d6da9752710487054c86fdfdffc26e00b7 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Tue, 17 Sep 2019 18:01:48 +0100 Subject: [PATCH] Add blank, branching renderers --- app/src/tiles/renderers/blankRenderer.ts | 21 ++++++++++++++++++ app/src/tiles/renderers/branchingRenderer.ts | 23 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 app/src/tiles/renderers/blankRenderer.ts create mode 100644 app/src/tiles/renderers/branchingRenderer.ts diff --git a/app/src/tiles/renderers/blankRenderer.ts b/app/src/tiles/renderers/blankRenderer.ts new file mode 100644 index 00000000..2d3187ed --- /dev/null +++ b/app/src/tiles/renderers/blankRenderer.ts @@ -0,0 +1,21 @@ +import { Image } from "mapnik"; +import sharp from 'sharp'; + +import { TileParams, TileRenderer } from "../types"; + +class BlankRenderer implements TileRenderer { + getTile(tileParams: TileParams): Promise { + return sharp({ + create: { + width: 1, + height: 1, + channels: 4, + background: { r: 0, g: 0, b: 0, alpha: 0 } + } + }).png().toBuffer(); + } +} + +export { + BlankRenderer +}; diff --git a/app/src/tiles/renderers/branchingRenderer.ts b/app/src/tiles/renderers/branchingRenderer.ts new file mode 100644 index 00000000..ce7d78da --- /dev/null +++ b/app/src/tiles/renderers/branchingRenderer.ts @@ -0,0 +1,23 @@ +import { Image } from "mapnik"; + +import { TileParams, TileRenderer } from "../types"; + +class BranchingRenderer { + constructor( + public branchTestFn: (tileParams: TileParams) => boolean, + public trueResultTileRenderer: TileRenderer, + public falseResultTileRenderer: TileRenderer + ) {} + + getTile(tileParams: TileParams, dataParams: any): Promise { + if(this.branchTestFn(tileParams)) { + return this.trueResultTileRenderer.getTile(tileParams, dataParams); + } else { + return this.falseResultTileRenderer.getTile(tileParams, dataParams); + } + } +} + +export { + BranchingRenderer +};