From 58b5fef3da33b20eb1262dca3906db4969ad272e Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 2 Apr 2014 16:44:57 +0200 Subject: [PATCH] Allow to make canvas smaller when it is too big For performance reason, we only make the canvas bigger, but not smaller. With this change, we also make it smaller, but only when we know that its current size exceeds the maximum dimensions. --- src/ol/renderer/canvas/canvastilelayerrenderer.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ol/renderer/canvas/canvastilelayerrenderer.js b/src/ol/renderer/canvas/canvastilelayerrenderer.js index 724af798d0..626d39ec8e 100644 --- a/src/ol/renderer/canvas/canvastilelayerrenderer.js +++ b/src/ol/renderer/canvas/canvastilelayerrenderer.js @@ -44,6 +44,12 @@ ol.renderer.canvas.TileLayer = function(mapRenderer, tileLayer) { */ this.canvasSize_ = null; + /** + * @private + * @type {boolean} + */ + this.canvasTooBig_; + /** * @private * @type {CanvasRenderingContext2D} @@ -203,17 +209,21 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = this.canvas_ = context.canvas; this.canvasSize_ = [canvasWidth, canvasHeight]; this.context_ = context; + this.canvasTooBig_ = !this.testCanvasSize(context, this.canvasSize_); } else { goog.asserts.assert(!goog.isNull(this.canvasSize_)); goog.asserts.assert(!goog.isNull(this.context_)); canvas = this.canvas_; context = this.context_; if (this.canvasSize_[0] < canvasWidth || - this.canvasSize_[1] < canvasHeight) { - // Canvas is too small, make it bigger + this.canvasSize_[1] < canvasHeight || + (this.canvasTooBig_ && (this.canvasSize_[0] > canvasWidth || + this.canvasSize_[1] > canvasHeight))) { + // Canvas is too small or too big, resize it canvas.width = canvasWidth; canvas.height = canvasHeight; this.canvasSize_ = [canvasWidth, canvasHeight]; + this.canvasTooBig_ = !this.testCanvasSize(context, this.canvasSize_); this.renderedCanvasTileRange_ = null; } else { canvasWidth = this.canvasSize_[0];