cache render options object

This commit is contained in:
Maximilian Krög
2021-07-10 20:32:55 +02:00
parent 53cf5bb282
commit bee28d61ea
+10 -6
View File
@@ -152,6 +152,12 @@ class RegularShape extends ImageStyle {
*/ */
this.hitDetectionImageSize_ = null; this.hitDetectionImageSize_ = null;
/**
* @private
* @type {RenderOptions}
*/
this.renderOptions_ = null;
this.render(); this.render();
} }
@@ -211,9 +217,7 @@ class RegularShape extends ImageStyle {
*/ */
getHitDetectionImage() { getHitDetectionImage() {
if (!this.hitDetectionCanvas_) { if (!this.hitDetectionCanvas_) {
const renderOptions = this.createRenderOptions(); this.createHitDetectionCanvas_(this.renderOptions_);
this.createHitDetectionCanvas_(renderOptions);
} }
return this.hitDetectionCanvas_; return this.hitDetectionCanvas_;
} }
@@ -227,7 +231,7 @@ class RegularShape extends ImageStyle {
getImage(pixelRatio) { getImage(pixelRatio) {
let image = this.canvas_[pixelRatio]; let image = this.canvas_[pixelRatio];
if (!image) { if (!image) {
const renderOptions = this.createRenderOptions(); const renderOptions = this.renderOptions_;
const context = createCanvasContext2D( const context = createCanvasContext2D(
renderOptions.size * pixelRatio, renderOptions.size * pixelRatio,
renderOptions.size * pixelRatio renderOptions.size * pixelRatio
@@ -488,8 +492,8 @@ class RegularShape extends ImageStyle {
* @protected * @protected
*/ */
render() { render() {
const renderOptions = this.createRenderOptions(); this.renderOptions_ = this.createRenderOptions();
const size = renderOptions.size; const size = this.renderOptions_.size;
const displacement = this.getDisplacement(); const displacement = this.getDisplacement();
this.canvas_ = {}; this.canvas_ = {};
this.anchor_ = [size / 2 - displacement[0], size / 2 + displacement[1]]; this.anchor_ = [size / 2 - displacement[0], size / 2 + displacement[1]];