Reuse ol.Size object
This commit is contained in:
@@ -130,29 +130,26 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
var tileRangeWidth = tileRange.getWidth();
|
var tileRangeWidth = tileRange.getWidth();
|
||||||
var tileRangeHeight = tileRange.getHeight();
|
var tileRangeHeight = tileRange.getHeight();
|
||||||
|
|
||||||
var canvasSize = new ol.Size(
|
var canvasWidth = tileSize.width * tileRange.getWidth();
|
||||||
tileSize.width * tileRange.getWidth(),
|
var canvasHeight = tileSize.height * tileRange.getHeight();
|
||||||
tileSize.height * tileRange.getHeight());
|
|
||||||
|
|
||||||
var canvas, context;
|
var canvas, context;
|
||||||
if (goog.isNull(this.canvas_)) {
|
if (goog.isNull(this.canvas_)) {
|
||||||
canvas = /** @type {HTMLCanvasElement} */
|
canvas = /** @type {HTMLCanvasElement} */
|
||||||
(goog.dom.createElement(goog.dom.TagName.CANVAS));
|
(goog.dom.createElement(goog.dom.TagName.CANVAS));
|
||||||
canvas.width = canvasSize.width;
|
canvas.width = canvasWidth;
|
||||||
canvas.height = canvasSize.height;
|
canvas.height = canvasHeight;
|
||||||
context = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
|
context = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
|
||||||
this.canvas_ = canvas;
|
this.canvas_ = canvas;
|
||||||
this.canvasSize_ = canvasSize;
|
|
||||||
this.context_ = context;
|
this.context_ = context;
|
||||||
this.renderedCanvasTileRange_ = null;
|
this.renderedCanvasTileRange_ = null;
|
||||||
} else {
|
} else {
|
||||||
canvas = this.canvas_;
|
canvas = this.canvas_;
|
||||||
context = this.context_;
|
context = this.context_;
|
||||||
if (this.canvasSize_.width < canvasSize.width ||
|
if (this.canvasSize_.width < canvasWidth ||
|
||||||
this.canvasSize_.height < canvasSize.height) {
|
this.canvasSize_.height < canvasHeight) {
|
||||||
canvas.width = canvasSize.width;
|
canvas.width = canvasWidth;
|
||||||
canvas.height = canvasSize.height;
|
canvas.height = canvasHeight;
|
||||||
this.canvasSize_ = canvasSize;
|
|
||||||
this.renderedCanvasTileRange_ = null;
|
this.renderedCanvasTileRange_ = null;
|
||||||
} else if (z != this.renderedCanvasZ_ ||
|
} else if (z != this.renderedCanvasZ_ ||
|
||||||
!this.renderedCanvasTileRange_.containsTileRange(tileRange)) {
|
!this.renderedCanvasTileRange_.containsTileRange(tileRange)) {
|
||||||
@@ -163,8 +160,14 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
var canvasTileRange, canvasTileRangeWidth, minX, minY;
|
var canvasTileRange, canvasTileRangeWidth, minX, minY;
|
||||||
if (z != this.renderedCanvasZ_ ||
|
if (z != this.renderedCanvasZ_ ||
|
||||||
goog.isNull(this.renderedCanvasTileRange_)) {
|
goog.isNull(this.renderedCanvasTileRange_)) {
|
||||||
canvasTileRangeWidth = canvasSize.width / tileSize.width;
|
if (goog.isNull(this.canvasSize_)) {
|
||||||
var canvasTileRangeHeight = canvasSize.height / tileSize.height;
|
this.canvasSize_ = new ol.Size(canvasWidth, canvasHeight);
|
||||||
|
} else {
|
||||||
|
this.canvasSize_.width = canvasWidth;
|
||||||
|
this.canvasSize_.height = canvasHeight;
|
||||||
|
}
|
||||||
|
canvasTileRangeWidth = canvasWidth / tileSize.width;
|
||||||
|
var canvasTileRangeHeight = canvasHeight / tileSize.height;
|
||||||
minX = tileRange.minX +
|
minX = tileRange.minX +
|
||||||
Math.floor((canvasTileRangeWidth - tileRange.getWidth()) / 2);
|
Math.floor((canvasTileRangeWidth - tileRange.getWidth()) / 2);
|
||||||
minY = tileRange.minY +
|
minY = tileRange.minY +
|
||||||
@@ -181,6 +184,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
canvasTileRangeWidth = canvasTileRange.getWidth();
|
canvasTileRangeWidth = canvasTileRange.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goog.asserts.assert(!goog.isNull(this.canvasSize_));
|
||||||
goog.asserts.assert(canvasTileRange.containsTileRange(tileRange));
|
goog.asserts.assert(canvasTileRange.containsTileRange(tileRange));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user