|
|
@ -20,6 +20,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|
|
|
if (!torque.isBrowserSupported()) {
|
|
|
|
if (!torque.isBrowserSupported()) {
|
|
|
|
throw new Error("browser is not supported by torque");
|
|
|
|
throw new Error("browser is not supported by torque");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._tileStream = {}
|
|
|
|
options.tileLoader = true;
|
|
|
|
options.tileLoader = true;
|
|
|
|
this.key = 0;
|
|
|
|
this.key = 0;
|
|
|
|
if (options.cartocss) {
|
|
|
|
if (options.cartocss) {
|
|
|
@ -72,7 +73,25 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|
|
|
var tileData = this.provider.getTileData(t, t.zoom, function(tileData) {
|
|
|
|
var tileData = this.provider.getTileData(t, t.zoom, function(tileData) {
|
|
|
|
// don't load tiles that are not being shown
|
|
|
|
// don't load tiles that are not being shown
|
|
|
|
if (t.zoom !== self._map.getZoom()) return;
|
|
|
|
if (t.zoom !== self._map.getZoom()) return;
|
|
|
|
|
|
|
|
tileData.steps = self.provider.getSteps();
|
|
|
|
self._tileLoaded(t, tileData);
|
|
|
|
self._tileLoaded(t, tileData);
|
|
|
|
|
|
|
|
if (self.options.streaming) {
|
|
|
|
|
|
|
|
var k = self._tileKey(t);
|
|
|
|
|
|
|
|
var stream = self._tileStream[k];
|
|
|
|
|
|
|
|
if (!stream) {
|
|
|
|
|
|
|
|
console.log("creating stream ", k);
|
|
|
|
|
|
|
|
stream = self._tileStream[k] = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream.length) {
|
|
|
|
|
|
|
|
var last = stream[stream.length - 1];
|
|
|
|
|
|
|
|
tileData.startKey = last.startKey + last.steps;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tileData.startKey = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(" - start", tileData.startKey);
|
|
|
|
|
|
|
|
console.log(" - steps", tileData.steps);
|
|
|
|
|
|
|
|
stream.push(tileData);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (tileData) {
|
|
|
|
if (tileData) {
|
|
|
|
self.redraw();
|
|
|
|
self.redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -183,12 +202,29 @@ 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) {
|
|
|
|
var tiles = this._tiles;
|
|
|
|
tile = this._tiles[t];
|
|
|
|
|
|
|
|
|
|
|
|
if (this.options.streaming) {
|
|
|
|
|
|
|
|
tiles = this._tileStream
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var key = this.key;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(t in tiles) {
|
|
|
|
|
|
|
|
tile = tiles[t];
|
|
|
|
|
|
|
|
// search for the stream index for this.key
|
|
|
|
|
|
|
|
if (this.options.streaming) {
|
|
|
|
|
|
|
|
var c = 0;
|
|
|
|
|
|
|
|
while(c < tile.length && this.key >= (tile[c].startKey + tile[c].steps)) {
|
|
|
|
|
|
|
|
++c;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tile = tile[c];
|
|
|
|
|
|
|
|
}
|
|
|
|
if (tile) {
|
|
|
|
if (tile) {
|
|
|
|
|
|
|
|
key = this.key - tile.startKey;
|
|
|
|
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);
|
|
|
|
this.renderer.renderTile(tile, key, pos.x, pos.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|