From 8cf52da304df1be21392f3c0396e8a260d49bf4f Mon Sep 17 00:00:00 2001 From: javi Date: Tue, 9 Sep 2014 22:50:10 +0200 Subject: [PATCH] per tile back when it's paused --- lib/torque/leaflet/torque.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index a20b6d9..9ff9d6f 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -183,12 +183,31 @@ L.TorqueLayer = L.CanvasLayer.extend({ canvas.width = canvas.width; var ctx = canvas.getContext('2d'); + for(t in this._tiles) { tile = this._tiles[t]; if (tile) { + if (this.animator.isRunning()) { + tile._tileCache = null; + } pos = this.getTilePos(tile.coord); 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); + } } }