Compare commits

...

2 Commits

2 changed files with 52 additions and 20 deletions

View File

@ -48,10 +48,39 @@
* Index: Array index to the properties * 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 r;
var x = new this.options.coordinates_data_type(rows.length); var x = options.x || new options.coordinates_data_type(rows.length);
var y = new this.options.coordinates_data_type(rows.length); var y = options.y || new options.coordinates_data_type(rows.length);
// count number of dates // count number of dates
var dates = 0; var dates = 0;
@ -64,16 +93,16 @@
} }
} }
if(this.options.cumulative) { if(options.cumulative) {
dates = (1 + maxDateSlots) * rows.length; dates = (1 + maxDateSlots) * rows.length;
} }
var type = this.options.cumulative ? Uint32Array: Uint8ClampedArray; var type = options.cumulative ? Uint32Array: Uint8ClampedArray;
// reserve memory for all the dates // reserve memory for all the dates
var timeIndex = new Int32Array(maxDateSlots + 1); //index-size var timeIndex = new Int32Array(maxDateSlots + 1); //index-size
var timeCount = new Int32Array(maxDateSlots + 1); 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 renderDataPos = new Uint32Array(dates);
var rowsPerSlot = {}; var rowsPerSlot = {};
@ -81,15 +110,15 @@
// precache pixel positions // precache pixel positions
for (var r = 0; r < rows.length; ++r) { for (var r = 0; r < rows.length; ++r) {
var row = rows[r]; var row = rows[r];
x[r] = row.x__uint8 * this.options.resolution; x[r] = row.x__uint8 * options.resolution;
y[r] = row.y__uint8 * this.options.resolution; y[r] = row.y__uint8 * options.resolution;
var dates = row.dates__uint16; var dates = row.dates__uint16;
var vals = row.vals__uint8; var vals = row.vals__uint8;
if (!this.options.cumulative) { if (!options.cumulative) {
for (var j = 0, len = dates.length; j < len; ++j) { for (var j = 0, len = dates.length; j < len; ++j) {
var rr = rowsPerSlot[dates[j]] || (rowsPerSlot[dates[j]] = []); var rr = rowsPerSlot[dates[j]] || (rowsPerSlot[dates[j]] = []);
if(this.options.cumulative) { if(options.cumulative) {
vals[j] += prev_val; vals[j] += prev_val;
} }
prev_val = vals[j]; prev_val = vals[j];
@ -152,7 +181,7 @@
}; };
}, },
setSteps: function(steps, opt) { setSteps: function(steps, opt) {
opt = opt || {}; opt = opt || {};
if (this.options.steps !== steps) { if (this.options.steps !== steps) {
this.options.steps = steps; this.options.steps = steps;
@ -257,7 +286,7 @@
torque.net.get( url , function (data) { torque.net.get( url , function (data) {
if (data && data.responseText) { if (data && data.responseText) {
var rows = JSON.parse(data.responseText); var rows = JSON.parse(data.responseText);
callback(self.proccessTile(rows, coord, zoom)); self.proccessTile(rows, coord, zoom,callback.bind(self));
} else { } else {
callback(null); callback(null);
} }
@ -314,6 +343,7 @@
_fetchMap: function(callback) { _fetchMap: function(callback) {
var self = this; var self = this;
torque.net.get(this.options.tileJSON, function (data) { torque.net.get(this.options.tileJSON, function (data) {
data = JSON.parse(data.response); data = JSON.parse(data.response);
if (data) { if (data) {
@ -334,4 +364,4 @@
} }
}; };
module.exports = tileJSON; module.exports = tileJSON;

View File

@ -44,14 +44,16 @@ function getTile(jsonRelPath, cartocss, z, x, y, step, callback) {
var canvas = new Canvas(256, 256); var canvas = new Canvas(256, 256);
var pointRenderer = new torque.renderer.Point(canvas, rendererOptions); 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 = { module.exports = {