working with categories per tile
This commit is contained in:
parent
e65367e8a6
commit
164643d0f1
@ -544,14 +544,27 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
*/
|
*/
|
||||||
getValues: function(step) {
|
getValues: function(step) {
|
||||||
var values = [];
|
var values = [];
|
||||||
|
var idx = 0;
|
||||||
|
var mappedValues = [];
|
||||||
step = step === undefined ? this.key: step;
|
step = step === undefined ? this.key: step;
|
||||||
var t, tile;
|
var t, tile;
|
||||||
for(t in this._tiles) {
|
for(t in this._tiles) {
|
||||||
tile = this._tiles[t];
|
tile = this._tiles[t];
|
||||||
if (tile) {
|
if (tile) {
|
||||||
this.renderer.getValues(tile, step, values);
|
this.renderer.getValues(tile, step, values);
|
||||||
|
// map the categories
|
||||||
|
var mapping = tile.categories[step];
|
||||||
|
if (mapping) {
|
||||||
|
for (var i = idx; i <= values.length - idx; ++i) {
|
||||||
|
mappedValues.push(mapping[values[i]]);
|
||||||
|
}
|
||||||
|
idx = values.length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mappedValues.length) {
|
||||||
|
return mappedValues;
|
||||||
|
}
|
||||||
return values;
|
return values;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -27,18 +27,6 @@ var Profiler = require('../profiler');
|
|||||||
this._maxWorkerNo = this.options.maxWorkerNo || 4;
|
this._maxWorkerNo = this.options.maxWorkerNo || 4;
|
||||||
|
|
||||||
this.setupWorkerPool()
|
this.setupWorkerPool()
|
||||||
// category mapping for each column
|
|
||||||
this.categoryMapping = {}
|
|
||||||
this.categoryMappingSize = {}
|
|
||||||
|
|
||||||
// generate the mapping, global for all the tiles
|
|
||||||
var fields = this.options.fields;
|
|
||||||
for (var i = 0 ; i < fields.length; ++i) {
|
|
||||||
if (fields[i].type === 'cat') {
|
|
||||||
this.categoryMapping[fields[i].name] = {}
|
|
||||||
this.categoryMappingSize[fields[i].name] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.options.tiler_protocol = options.tiler_protocol || 'http';
|
this.options.tiler_protocol = options.tiler_protocol || 'http';
|
||||||
this.options.tiler_domain = options.tiler_domain || 'cartodb.com';
|
this.options.tiler_domain = options.tiler_domain || 'cartodb.com';
|
||||||
@ -103,7 +91,7 @@ var Profiler = require('../profiler');
|
|||||||
/**
|
/**
|
||||||
* Creates a worker to process the tile
|
* Creates a worker to process the tile
|
||||||
*/
|
*/
|
||||||
createProccessTileWorker:function(){
|
createProccessTileWorker: function(){
|
||||||
var workerFunction = "var proccessTile ="+ this.proccessTileSerial.toString()
|
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.rows,data.coord, data.zoom, data.options)))}"
|
||||||
var script = workerFunction + wrapper;
|
var script = workerFunction + wrapper;
|
||||||
@ -112,20 +100,17 @@ var Profiler = require('../profiler');
|
|||||||
return worker
|
return worker
|
||||||
},
|
},
|
||||||
|
|
||||||
proccessTile:function(rows,coord,zoom,callback){
|
proccessTile: function(rows, coord, zoom, callback){
|
||||||
|
var self = this;
|
||||||
if(typeof(Worker) === "undefined"){
|
if(typeof(Worker) === "undefined"){
|
||||||
callback(this.proccessTileSerial(rows,coord,zoom, this.options))
|
callback(this.proccessTileSerial(rows,coord,zoom, this.options))
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
|
var workerSafeOptions = {
|
||||||
|
|
||||||
var workerSafeOptions= {
|
|
||||||
x : new Uint8Array(rows.length),
|
|
||||||
y : new Uint8Array(rows.length),
|
|
||||||
resolution: this.options.resolution,
|
resolution: this.options.resolution,
|
||||||
fields: this.options.fields
|
fields: this.options.fields
|
||||||
}
|
}
|
||||||
this.requestWorker(rows,coord,zoom,workerSafeOptions,callback)
|
this.requestWorker(rows, coord, zoom, workerSafeOptions, callback)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -139,6 +124,7 @@ var Profiler = require('../profiler');
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
proccessTileSerial: function(rows, coord, zoom, options) {
|
proccessTileSerial: function(rows, coord, zoom, options) {
|
||||||
|
// utility function for hashing categories
|
||||||
var r;
|
var r;
|
||||||
var x = new Uint8Array(rows.length);
|
var x = new Uint8Array(rows.length);
|
||||||
var y = new Uint8Array(rows.length);
|
var y = new Uint8Array(rows.length);
|
||||||
@ -149,6 +135,17 @@ var Profiler = require('../profiler');
|
|||||||
var prof_process_time = Profiler.metric('ProviderJSON:process_time').start()
|
var prof_process_time = Profiler.metric('ProviderJSON:process_time').start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var categoryMapping = {}
|
||||||
|
var categoryMappingSize = {}
|
||||||
|
var fields = options.fields;
|
||||||
|
|
||||||
|
for (var i = 0 ; i < fields.length; ++i) {
|
||||||
|
if (fields[i].type === 'cat') {
|
||||||
|
categoryMapping[i] = {};
|
||||||
|
categoryMappingSize[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// count number of steps
|
// count number of steps
|
||||||
var maxDateSlots = Object.keys(rows[0].d).length;
|
var maxDateSlots = Object.keys(rows[0].d).length;
|
||||||
var steps = maxDateSlots;
|
var steps = maxDateSlots;
|
||||||
@ -198,16 +195,11 @@ var Profiler = require('../profiler');
|
|||||||
var k = 'f' + (j + 1)
|
var k = 'f' + (j + 1)
|
||||||
var v = vals[k];
|
var v = vals[k];
|
||||||
if (options.fields[j].type === 'cat') {
|
if (options.fields[j].type === 'cat') {
|
||||||
var mapping = this.categoryMapping[options.fields[j].name];
|
var mapping = categoryMapping[j];
|
||||||
var m = mapping[v]
|
var m = mapping[v]
|
||||||
if (!m) {
|
if (!m) {
|
||||||
var count = this.categoryMappingSize[options.fields[j].name];
|
var count = ++categoryMappingSize[j];
|
||||||
if (count < 100) {
|
|
||||||
++this.categoryMappingSize[options.fields[j].name];
|
|
||||||
v = mapping[v] = count;
|
v = mapping[v] = count;
|
||||||
} else {
|
|
||||||
v = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
v = m;
|
v = m;
|
||||||
}
|
}
|
||||||
@ -242,6 +234,18 @@ var Profiler = require('../profiler');
|
|||||||
prof_process_time.end();
|
prof_process_time.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// invert the mapping
|
||||||
|
var invertedMapping = {}
|
||||||
|
for (var i = 0 ; i < fields.length; ++i) {
|
||||||
|
if (fields[i].type === 'cat') {
|
||||||
|
var cat = categoryMapping[i];
|
||||||
|
invertedMapping[i] = {}
|
||||||
|
for (var k in cat) {
|
||||||
|
invertedMapping[i][cat[k]] = k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
@ -255,7 +259,8 @@ var Profiler = require('../profiler');
|
|||||||
timeIndex: timeIndex,
|
timeIndex: timeIndex,
|
||||||
renderDataPos: renderDataPos,
|
renderDataPos: renderDataPos,
|
||||||
renderData: renderData,
|
renderData: renderData,
|
||||||
maxDate: maxDateSlots
|
maxDate: maxDateSlots,
|
||||||
|
categories: invertedMapping
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user