per tile back when it's paused

This commit is contained in:
javi 2014-09-09 22:50:10 +02:00
parent 6b70e9e03b
commit 8cf52da304

View File

@ -183,12 +183,31 @@ L.TorqueLayer = L.CanvasLayer.extend({
canvas.width = canvas.width; canvas.width = canvas.width;
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
for(t in this._tiles) { for(t in this._tiles) {
tile = this._tiles[t]; tile = this._tiles[t];
if (tile) { if (tile) {
if (this.animator.isRunning()) {
tile._tileCache = null;
}
pos = this.getTilePos(tile.coord); pos = this.getTilePos(tile.coord);
ctx.setTransform(1, 0, 0, 1, pos.x, pos.y); ctx.setTransform(1, 0, 0, 1, pos.x, pos.y);
this.renderer.renderTile(tile, this.key, pos.x, pos.y); if ( this.isRunning()) {
this.renderer.renderTile(tile, this.key, pos.x, pos.y);
} else {
var bufferSize = 40;
if (!tile._tileCache) {
var backCanvas = document.createElement('canvas');
backCanvas.width = backCanvas.height = 256 + bufferSize * 2;
var c = this.renderer._ctx;
this.renderer._ctx = backCanvas.getContext('2d');
this.renderer.renderTile(tile, this.key, pos.x - bufferSize, pos.y - bufferSize);
tile._tileCache = new Image();
tile._tileCache.src = backCanvas.toDataURL();
this.renderer._ctx = c;
}
this.renderer._ctx.drawImage(tile._tileCache, -bufferSize, -bufferSize);
}
} }
} }