diff --git a/lib/torque/provider/tilejson.js b/lib/torque/provider/tilejson.js index d4b2af7..3e6ff4e 100644 --- a/lib/torque/provider/tilejson.js +++ b/lib/torque/provider/tilejson.js @@ -19,6 +19,7 @@ var tileJSON = function (options) { this._ready = false; this._tileQueue = []; + this._filters = {} this.options = options; this.options.coordinates_data_type = this.options.coordinates_data_type || Uint8Array; @@ -49,6 +50,13 @@ this.reload() }, + _setFilter:function(variable, start,end){ + this._filters[variable] = {type:'range', start:start,end:end) + this.reload(); + }, + _removefilter:function(variable){ + this._filters[variable] = undefined + }, /** * return the torque tile encoded in an efficient javascript * structure: @@ -60,16 +68,16 @@ */ createProccessTileWorker:function(){ var workerFunction = "var proccessTile ="+ this.proccessTileSerial.toString() - var wrapper = "; self.onmessage = function(e){var data = JSON.parse(e.data); JSON.stringify(self.postMessage(proccessTile(data.rows,data.coord, data.zoom, data.options)))}" + var wrapper = "; self.onmessage = function(e){var data = JSON.parse(e.data); JSON.stringify(self.postMessage(proccessTile(data.response,data.coord, data.zoom, data.options)))}" var script = workerFunction + wrapper; var blob = new Blob([script], {type: "text/javascript"}) var worker = new Worker(window.URL.createObjectURL(blob)) return worker }, - proccessTile:function(rows,coord,zoom,callback){ + proccessTile:function(response,coord,zoom,callback){ if(typeof(Worker) === "undefined"){ - callback(this.proccessTileSerial(rows,coord,zoom, this.options)) + callback(this.proccessTileSerial(response,coord,zoom, this.options)) } else{ var worker = this.createProccessTileWorker() @@ -79,20 +87,22 @@ } var workerSafeOptions= { - x : new this.options.coordinates_data_type(rows.length), - y : new this.options.coordinates_data_type(rows.length), cumulative: this.options.cumulative, valueDataType: this.options.valueDataType, resolution: this.options.resolution, } - worker.postMessage(JSON.stringify({rows: rows, coord: {x:coord.x,y:coord.y}, zoom:zoom, options: workerSafeOptions})) + worker.postMessage(JSON.stringify({response: response, coord: {x:coord.x,y:coord.y}, zoom:zoom, options: workerSafeOptions})) } }, - proccessTileSerial: function(rows, coord, zoom,options) { + proccessTileSerial: function(response, coord, zoom,options) { var r; - var x = options.x || new options.coordinates_data_type(rows.length); - var y = options.y || new options.coordinates_data_type(rows.length); + var data = JSON.parse(response) + var rows = data.pixels + var histograms = data.histograms + + var x = options.x || new Uint8Array(rows.length); + var y = options.y || new Uint8Array(rows.length); // count number of dates var dates = 0; @@ -189,7 +199,8 @@ timeIndex: timeIndex, renderDataPos: renderDataPos, renderData: renderData, - maxDate: maxDateSlots + maxDate: maxDateSlots, + histogram: histograms }; }, @@ -300,8 +311,8 @@ } torque.net.get( url , function (data) { if (data && data.responseText) { - var rows = JSON.parse(data.responseText); - self.proccessTile(rows.pixels, coord, zoom,callback.bind(self)); + + self.proccessTile(data.responseText, coord, zoom,callback.bind(self)); } else { callback(null); }