From 10c6009ffaffe4023b54ad461615f7abef6fd33c Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 15 May 2019 09:41:36 +0200 Subject: [PATCH] Lazily create the hit detection context --- src/ol/render/canvas/ExecutorGroup.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ol/render/canvas/ExecutorGroup.js b/src/ol/render/canvas/ExecutorGroup.js index 371f3f3c5d..6180223528 100644 --- a/src/ol/render/canvas/ExecutorGroup.js +++ b/src/ol/render/canvas/ExecutorGroup.js @@ -82,7 +82,7 @@ class ExecutorGroup extends Disposable { * @private * @type {CanvasRenderingContext2D} */ - this.hitDetectionContext_ = createCanvasContext2D(1, 1); + this.hitDetectionContext_; /** * @private @@ -137,8 +137,11 @@ class ExecutorGroup extends Disposable { executors[key].disposeInternal(); } } - const canvas = this.hitDetectionContext_.canvas; - canvas.width = canvas.height = 0; + if (this.hitDetectionContext_) { + const canvas = this.hitDetectionContext_.canvas; + canvas.width = canvas.height = 0; + } + super.disposeInternal(); } @@ -187,6 +190,10 @@ class ExecutorGroup extends Disposable { 1 / resolution, -1 / resolution, -rotation, -coordinate[0], -coordinate[1]); + + if (!this.hitDetectionContext_) { + this.hitDetectionContext_ = createCanvasContext2D(contextSize, contextSize); + } const context = this.hitDetectionContext_; if (context.canvas.width !== contextSize || context.canvas.height !== contextSize) {