histograms tiles
This commit is contained in:
parent
c27b2471da
commit
26d0d40e35
@ -58,10 +58,41 @@
|
||||
* Index: Array index to the properties
|
||||
* }
|
||||
*/
|
||||
proccessTile: function(rows, coord, zoom) {
|
||||
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 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){
|
||||
if(typeof(Worker) === "undefined"){
|
||||
callback(this.proccessTileSerial(rows,coord,zoom, this.options))
|
||||
}
|
||||
else{
|
||||
var worker = this.createProccessTileWorker()
|
||||
worker.onmessage = function(e){
|
||||
callback(e.data)
|
||||
worker.terminate()
|
||||
}
|
||||
|
||||
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}))
|
||||
}
|
||||
},
|
||||
|
||||
proccessTileSerial: function(rows, coord, zoom,options) {
|
||||
var r;
|
||||
var x = new this.options.coordinates_data_type(rows.length);
|
||||
var y = new this.options.coordinates_data_type(rows.length);
|
||||
var x = options.x || new options.coordinates_data_type(rows.length);
|
||||
var y = options.y || new options.coordinates_data_type(rows.length);
|
||||
|
||||
// count number of dates
|
||||
var dates = 0;
|
||||
@ -74,16 +105,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
if(this.options.cumulative) {
|
||||
if(options.cumulative) {
|
||||
dates = (1 + maxDateSlots) * rows.length;
|
||||
}
|
||||
|
||||
var type = this.options.cumulative ? Uint32Array: Uint8ClampedArray;
|
||||
var type = options.cumulative ? Uint32Array: Uint8ClampedArray;
|
||||
|
||||
// reserve memory for all the dates
|
||||
var timeIndex = new Int32Array(maxDateSlots + 1); //index-size
|
||||
var timeCount = new Int32Array(maxDateSlots + 1);
|
||||
var renderData = new (this.options.valueDataType || type)(dates);
|
||||
var renderData = new (options.valueDataType || type)(dates);
|
||||
var renderDataPos = new Uint32Array(dates);
|
||||
|
||||
var rowsPerSlot = {};
|
||||
@ -91,15 +122,15 @@
|
||||
// precache pixel positions
|
||||
for (var r = 0; r < rows.length; ++r) {
|
||||
var row = rows[r];
|
||||
x[r] = row.x__uint8 * this.options.resolution;
|
||||
y[r] = row.y__uint8 * this.options.resolution;
|
||||
x[r] = row.x__uint8 * options.resolution;
|
||||
y[r] = row.y__uint8 * options.resolution;
|
||||
|
||||
var dates = row.dates__uint16;
|
||||
var vals = row.vals__uint8;
|
||||
if (!this.options.cumulative) {
|
||||
if (!options.cumulative) {
|
||||
for (var j = 0, len = dates.length; j < len; ++j) {
|
||||
var rr = rowsPerSlot[dates[j]] || (rowsPerSlot[dates[j]] = []);
|
||||
if(this.options.cumulative) {
|
||||
if(options.cumulative) {
|
||||
vals[j] += prev_val;
|
||||
}
|
||||
prev_val = vals[j];
|
||||
@ -162,7 +193,7 @@
|
||||
};
|
||||
},
|
||||
|
||||
setSteps: function(steps, opt) {
|
||||
setSteps: function(steps, opt) {
|
||||
opt = opt || {};
|
||||
if (this.options.steps !== steps) {
|
||||
this.options.steps = steps;
|
||||
@ -270,7 +301,7 @@
|
||||
torque.net.get( url , function (data) {
|
||||
if (data && data.responseText) {
|
||||
var rows = JSON.parse(data.responseText);
|
||||
callback(self.proccessTile(rows, coord, zoom));
|
||||
self.proccessTile(rows.pixels, coord, zoom,callback.bind(self));
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
@ -327,6 +358,7 @@
|
||||
|
||||
_fetchMap: function(callback) {
|
||||
var self = this;
|
||||
|
||||
torque.net.get(this.options.tileJSON, function (data) {
|
||||
data = JSON.parse(data.response);
|
||||
if (data) {
|
||||
|
@ -44,14 +44,16 @@ function getTile(jsonRelPath, cartocss, z, x, y, step, callback) {
|
||||
|
||||
var canvas = new Canvas(256, 256);
|
||||
var pointRenderer = new torque.renderer.Point(canvas, rendererOptions);
|
||||
provider.proccessTile(rows, {x: x, y: y}, z, function(tile){
|
||||
pointRenderer.renderTile(tile, step, function(err) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
pointRenderer.applyFilters();
|
||||
return callback(null, canvas);
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
pointRenderer.renderTile(provider.proccessTile(rows, {x: x, y: y}, z), step, function(err) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
pointRenderer.applyFilters();
|
||||
return callback(null, canvas);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
Reference in New Issue
Block a user