working with categories per tile
This commit is contained in:
parent
e65367e8a6
commit
164643d0f1
@ -544,13 +544,26 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
||||
*/
|
||||
getValues: function(step) {
|
||||
var values = [];
|
||||
var idx = 0;
|
||||
var mappedValues = [];
|
||||
step = step === undefined ? this.key: step;
|
||||
var t, tile;
|
||||
for(t in this._tiles) {
|
||||
tile = this._tiles[t];
|
||||
if (tile) {
|
||||
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;
|
||||
},
|
||||
|
@ -27,18 +27,6 @@ var Profiler = require('../profiler');
|
||||
this._maxWorkerNo = this.options.maxWorkerNo || 4;
|
||||
|
||||
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_domain = options.tiler_domain || 'cartodb.com';
|
||||
@ -113,15 +101,12 @@ var Profiler = require('../profiler');
|
||||
},
|
||||
|
||||
proccessTile: function(rows, coord, zoom, callback){
|
||||
var self = this;
|
||||
if(typeof(Worker) === "undefined"){
|
||||
callback(this.proccessTileSerial(rows,coord,zoom, this.options))
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
var workerSafeOptions = {
|
||||
x : new Uint8Array(rows.length),
|
||||
y : new Uint8Array(rows.length),
|
||||
resolution: this.options.resolution,
|
||||
fields: this.options.fields
|
||||
}
|
||||
@ -139,6 +124,7 @@ var Profiler = require('../profiler');
|
||||
* }
|
||||
*/
|
||||
proccessTileSerial: function(rows, coord, zoom, options) {
|
||||
// utility function for hashing categories
|
||||
var r;
|
||||
var x = 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 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
|
||||
var maxDateSlots = Object.keys(rows[0].d).length;
|
||||
var steps = maxDateSlots;
|
||||
@ -198,16 +195,11 @@ var Profiler = require('../profiler');
|
||||
var k = 'f' + (j + 1)
|
||||
var v = vals[k];
|
||||
if (options.fields[j].type === 'cat') {
|
||||
var mapping = this.categoryMapping[options.fields[j].name];
|
||||
var mapping = categoryMapping[j];
|
||||
var m = mapping[v]
|
||||
if (!m) {
|
||||
var count = this.categoryMappingSize[options.fields[j].name];
|
||||
if (count < 100) {
|
||||
++this.categoryMappingSize[options.fields[j].name];
|
||||
var count = ++categoryMappingSize[j];
|
||||
v = mapping[v] = count;
|
||||
} else {
|
||||
v = 0;
|
||||
}
|
||||
} else {
|
||||
v = m;
|
||||
}
|
||||
@ -242,6 +234,18 @@ var Profiler = require('../profiler');
|
||||
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 {
|
||||
x: x,
|
||||
y: y,
|
||||
@ -255,7 +259,8 @@ var Profiler = require('../profiler');
|
||||
timeIndex: timeIndex,
|
||||
renderDataPos: renderDataPos,
|
||||
renderData: renderData,
|
||||
maxDate: maxDateSlots
|
||||
maxDate: maxDateSlots,
|
||||
categories: invertedMapping
|
||||
};
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user