moved logic to torque bi

This commit is contained in:
javi 2015-12-02 10:11:48 +01:00
parent ce6ba46893
commit 1eb1344916
2 changed files with 64 additions and 169 deletions

View File

@ -10,7 +10,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
providers: { providers: {
'sql_api': torque.providers.json, 'sql_api': torque.providers.json,
'filterable_sql_api': torque.providers.filterableJson,
'url_template': torque.providers.JsonArray, 'url_template': torque.providers.JsonArray,
'windshaft': torque.providers.windshaft, 'windshaft': torque.providers.windshaft,
'tileJSON': torque.providers.tileJSON 'tileJSON': torque.providers.tileJSON
@ -29,7 +28,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
options.tileLoader = true; options.tileLoader = true;
this.key = 0; this.key = 0;
this.prevRenderedKey = 0; this.prevRenderedKey = 0;
this._filters = {}
if (options.cartocss) { if (options.cartocss) {
torque.extend(options, torque.common.TorqueLayer.optionsFromCartoCSS(options.cartocss)); torque.extend(options, torque.common.TorqueLayer.optionsFromCartoCSS(options.cartocss));
} }
@ -109,42 +107,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
}, },
setFilters: function() {
this.provider.setFilters(this._filters);
this._reloadTiles();
return this;
},
filterByRange: function(variableName, start, end) {
this._filters[variableName] = {type: 'range', range: {start: start, end: end} }
this._filtersChanged()
this.fire('dataUpdate')
return this
},
filterByCat: function(variableName, categories, exclusive) {
this._filters[variableName] = {type: 'cat', categories: categories, exclusive: !!exclusive };
this._filtersChanged()
return this
},
clearFilter: function(name){
if(name) {
delete this._filters[name]
}
else {
this._filters = {}
}
this._filtersChanged()
return this
},
_filtersChanged:function(){
this.provider._filters = this._filters;
this._clearTileCaches()
this._render()
},
_clearTileCaches: function() { _clearTileCaches: function() {
var t, tile; var t, tile;
for(t in this._tiles) { for(t in this._tiles) {
@ -160,81 +122,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
this._clearTileCaches(); this._clearTileCaches();
}, },
valuesForRangeVariable:function(variable){
var t, tile;
var variable_id = this.provider.idForRange(variable)
var values = [ ]
for(t in this._tiles){
tile = this._tiles[t]
var noPoints = tile.x.length;
for(var i=0; i < tile.x.length; i++){
if(tile.renderFlags[i] ){
value = tile.renderData[variable_id*noPoints + i]
values.push(value)
}
}
}
return values;
},
valuesForCatVariable:function(variable){
var t, tile;
var categories = this.provider.idsForCategory(variable)
var result = [ ]
for(t in this._tiles){
tile = this._tiles[t]
var noPoints = tile.x.length;
for(var i=0; i < tile.x.length; i++){
if(tile.renderFlags[i] ){
var vals={}
Object.keys(categories).forEach(function(categoryName){
var variable_id = categories[categoryName]
value = tile.renderData[variable_id*noPoints + i]
vals[categoryName] = value
}.bind(this))
result.push(vals)
}
}
}
return result;
},
getValues:function(variable,callback){
var type= this.provider._mapping[variable].type
if(type=='float'){
callback(this.valuesForRangeVariable(variable))
}
else{
callback(this.valuesForCatVariable(variable))
}
},
getHistogramForDataset: function(varName, start, end, bins, own_filter, callback) {
var tiles = [{x: 0, y: 0, z: 0}];
this.provider.getHistogramForTiles(varName, start, end, bins, tiles, own_filter, callback);
},
getAggregationForVisibleRegion: function(varName, agg, own_filter, callback) {
var tiles = this.visibleTiles();
this.provider.getAggregationForTiles(varName, agg, tiles, own_filter, callback);
},
getHistogramForVisibleRegion: function(varName, start, end, bins, own_filter, callback) {
var tiles = this.visibleTiles();
this.provider.getHistogramForTiles(varName, start, end, bins, tiles, own_filter, callback);
},
getCategoriesForVisibleRegion: function(varName, callback){
var tiles = this.visibleTiles();
this.provider.getCategoriesForTiles(varName, tiles, callback);
},
onAdd: function (map) { onAdd: function (map) {
map.on({ map.on({
'zoomend': this._clearCaches, 'zoomend': this._clearCaches,
@ -325,62 +212,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
canvas.width = canvas.width; canvas.width = canvas.width;
}, },
getDataForPoint:function(x,y,callback, maxNo, tolerance){
var maxNo = maxNo || 10
var tolerance = tolerance || 10
for(var t in this._tiles ){
tile = this._tiles[t];
pos = this.getTilePos(tile.coord);
var tileWidth = 255.0/this.options.resolution
xx = x - pos.x;
yy = y - pos.y;
if(xx >= 0 && yy >= 0 && xx < 255 && yy <= 255) {
this.provider.getDataForTorquePixel(tile.coord,xx,yy,maxNo,tolerance,callback)
return this
}
}
callback(null)
return this
},
/*
_filterTile:function(tile){
var noPoints = tile.x.length
var renderFlags = []
for(var i =0; i < noPoints; i++){
var includePoint = true
Object.keys(this._filters).forEach(function(key){
var filter = this._filters[key]
var variableId = this.provider.idForRange(key)
var value = tile.renderData[variableId*noPoints+i]
if(filter.type=='range'){
if(value < filter.range.start || value > filter.range.end){
includePoint = false;
}
}
else if (filter.type=='cat'){
var ids = this.provider.idsForCategory(key);
filter.categories.forEach(function(key){
var catId = ids[key]
var value = tile.renderData[catId*noPoints + i]
if(value==0){
includePoint= false
}
}.bind(this))
}
}.bind(this))
renderFlags[i] = includePoint
}
return renderFlags
},
*/
/** /**
* render the selectef key * render the selectef key
* don't call this function directly, it's called by * don't call this function directly, it's called by

View File

@ -0,0 +1,64 @@
L.TorqueLayer.extend({
initialize: function(options) {
this._filters = {}
L.TorqueLayer.prototype.initialize.call(this, options);
},
setFilters: function() {
this.provider.setFilters(this._filters);
this._reloadTiles();
return this;
},
filterByRange: function(variableName, start, end) {
this._filters[variableName] = {type: 'range', range: {start: start, end: end} }
this._filtersChanged()
this.fire('dataUpdate')
return this
},
filterByCat: function(variableName, categories, exclusive) {
this._filters[variableName] = {type: 'cat', categories: categories, exclusive: !!exclusive };
this._filtersChanged()
return this
},
clearFilter: function(name){
if(name) {
delete this._filters[name]
}
else {
this._filters = {}
}
this._filtersChanged()
return this
},
_filtersChanged:function(){
this.provider._filters = this._filters;
this._clearTileCaches()
this._render()
},
getHistogramForDataset: function(varName, start, end, bins, own_filter, callback) {
var tiles = [{x: 0, y: 0, z: 0}];
this.provider.getHistogramForTiles(varName, start, end, bins, tiles, own_filter, callback);
},
getAggregationForVisibleRegion: function(varName, agg, own_filter, callback) {
var tiles = this.visibleTiles();
this.provider.getAggregationForTiles(varName, agg, tiles, own_filter, callback);
},
getHistogramForVisibleRegion: function(varName, start, end, bins, own_filter, callback) {
var tiles = this.visibleTiles();
this.provider.getHistogramForTiles(varName, start, end, bins, tiles, own_filter, callback);
},
getCategoriesForVisibleRegion: function(varName, callback){
var tiles = this.visibleTiles();
this.provider.getCategoriesForTiles(varName, tiles, callback);
},
});