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.
This commit is contained in:
1 parent
4dce59fe95
commit
58b5fef3da
1 file changed
+12
-2
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user