From bee28d61eadbd560691458a705d55451fe462bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 10 Jul 2021 20:32:55 +0200 Subject: [PATCH] cache render options object --- src/ol/style/RegularShape.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ol/style/RegularShape.js b/src/ol/style/RegularShape.js index 233be675ae..2fc4580a5f 100644 --- a/src/ol/style/RegularShape.js +++ b/src/ol/style/RegularShape.js @@ -152,6 +152,12 @@ class RegularShape extends ImageStyle { */ this.hitDetectionImageSize_ = null; + /** + * @private + * @type {RenderOptions} + */ + this.renderOptions_ = null; + this.render(); } @@ -211,9 +217,7 @@ class RegularShape extends ImageStyle { */ getHitDetectionImage() { if (!this.hitDetectionCanvas_) { - const renderOptions = this.createRenderOptions(); - - this.createHitDetectionCanvas_(renderOptions); + this.createHitDetectionCanvas_(this.renderOptions_); } return this.hitDetectionCanvas_; } @@ -227,7 +231,7 @@ class RegularShape extends ImageStyle { getImage(pixelRatio) { let image = this.canvas_[pixelRatio]; if (!image) { - const renderOptions = this.createRenderOptions(); + const renderOptions = this.renderOptions_; const context = createCanvasContext2D( renderOptions.size * pixelRatio, renderOptions.size * pixelRatio @@ -488,8 +492,8 @@ class RegularShape extends ImageStyle { * @protected */ render() { - const renderOptions = this.createRenderOptions(); - const size = renderOptions.size; + this.renderOptions_ = this.createRenderOptions(); + const size = this.renderOptions_.size; const displacement = this.getDisplacement(); this.canvas_ = {}; this.anchor_ = [size / 2 - displacement[0], size / 2 + displacement[1]];