From 28d940eb9362894ed090d184ac107493520c6d2c Mon Sep 17 00:00:00 2001 From: Henry Castro Date: Thu, 28 Apr 2022 08:56:19 -0400 Subject: [PATCH] browser: fix jsdom exception drawing in canvas jsdom requires that the tile is a HTMLCanvasElement element type Receiver.dataMessage (private/mmeeks/deltas/browser/node_modules/ws/lib/receiver.js:51 7:14) TypeError: The first argument must be an object at CanvasRenderingContext2D.ctx. [as drawImage] (private/mmeeks/deltas/browser/ node_modules/jsdom/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js:124:17) at TilesSection.paintSimple (private/mmeeks/deltas/browser/dist/bundle.js:1:136355 4) at TilesSection.paint (private/mmeeks/deltas/browser/dist/bundle.js:1:1364132) at TilesSection. (private/mmeeks/deltas/browser/dist/bundle.js:1:136981 2) Change-Id: I55b77e3a9ae80afd519f1a6c6c5388070c85193e Signed-off-by: Henry Castro --- browser/src/layer/tile/TilesSection.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/browser/src/layer/tile/TilesSection.ts b/browser/src/layer/tile/TilesSection.ts index 5f89ca1cc..37d5da65c 100644 --- a/browser/src/layer/tile/TilesSection.ts +++ b/browser/src/layer/tile/TilesSection.ts @@ -29,6 +29,7 @@ class TilesSection { map: any; offscreenCanvases: Array = new Array(0); oscCtxs: Array = new Array(0); + isJSDOM: boolean = false; // testing isCalcRTL: () => boolean; @@ -52,6 +53,7 @@ class TilesSection { this.sectionProperties.pageBackgroundFillColorWriter = 'white'; this.sectionProperties.pageBackgroundTextColor = 'grey'; this.sectionProperties.pageBackgroundFont = String(40 * app.roundedDpiScale) + 'px Arial'; + this.isJSDOM = typeof window === 'object' && window.name === 'nodejs'; } public onInitialize () { @@ -427,7 +429,13 @@ class TilesSection { // Ensure tile is loaded and is within document bounds. if (tile && tile.loaded && docLayer._isValidTile(coords)) { - this.paint(tile, ctx, false /* async? */); + if (this.isJSDOM) // perf-test code + { + if (tile.el && (tile.el instanceof HTMLCanvasElement)) + this.paint(tile, ctx, false /* async? */); + } + else + this.paint(tile, ctx, false /* async? */); } doneTiles.add(coords.key()); return true; // continue with remaining tiles.