From 53cf5bb28287b1ba3d791cb3a6d7d4982c7e111f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 4 Jul 2021 15:17:23 +0200 Subject: [PATCH] Lazily create Regular shape canvases Creating the cached canvases is expensive and they may never be used. E. g. the hit detect canvas is not needed with the Immediate renderer and if a feature is never in the viewport the image is not needed either. --- src/ol/style/RegularShape.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/ol/style/RegularShape.js b/src/ol/style/RegularShape.js index 2d289e5930..233be675ae 100644 --- a/src/ol/style/RegularShape.js +++ b/src/ol/style/RegularShape.js @@ -77,7 +77,7 @@ class RegularShape extends ImageStyle { * @private * @type {Object} */ - this.canvas_ = {}; + this.canvas_ = undefined; /** * @private @@ -489,28 +489,13 @@ class RegularShape extends ImageStyle { */ render() { const renderOptions = this.createRenderOptions(); - - const context = createCanvasContext2D( - renderOptions.size, - renderOptions.size - ); - - this.draw_(renderOptions, context, 1); - - this.canvas_ = {}; - this.canvas_[1] = context.canvas; - - // canvas.width and height are rounded to the closest integer - const size = context.canvas.width; - const imageSize = size; + const size = renderOptions.size; const displacement = this.getDisplacement(); - - this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size]; - this.createHitDetectionCanvas_(renderOptions); - + this.canvas_ = {}; this.anchor_ = [size / 2 - displacement[0], size / 2 + displacement[1]]; this.size_ = [size, size]; - this.imageSize_ = [imageSize, imageSize]; + this.imageSize_ = [size, size]; + this.hitDetectionImageSize_ = [size, size]; } /**