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); + } } }