Compare commits

...

63 Commits

Author SHA1 Message Date
Francisco Dans
1dfd2c6bf1 shitass refactor 2015-05-14 19:26:22 +02:00
Francisco Dans
ea4445ab8d shrinks isopleth function 2015-05-14 16:43:17 +02:00
Francisco Dans
5cdda8d8c7 draw and invalidate refactor 2015-05-14 16:42:58 +02:00
Francisco Dans
7d7cd9fefd unimportant tweaks 2015-05-14 16:42:39 +02:00
Francisco Dans
bfd28c9a7d makes sure that no pixels are drawn out of bounds 2015-05-13 16:02:18 +02:00
Francisco Dans
b6bc9185c7 Merge branch 'master' of github.com:CartoDB/torque into aequus 2015-05-13 15:29:23 +02:00
Francisco Dans
50087b7b4b applies filters by selecting a mode and then drawing 2015-05-12 12:14:29 +02:00
Francisco Dans
59a84690c2 compatibilizes ballrenderer with cartocss 2015-05-12 12:14:03 +02:00
Francisco Dans
eb4d739bca adds compatibility with default renderer 2015-05-12 12:13:34 +02:00
Francisco Dans
2d6632afb8 establishes optimal min opacity of 20 2015-05-12 12:12:54 +02:00
Francisco Dans
df494cadb6 integrates mode selection in the draw function 2015-05-12 12:12:18 +02:00
Francisco Dans
3db32964f0 caches balls by radii 2015-05-12 12:11:54 +02:00
Francisco Dans
66d27019fc removes multiplication from getNeighbors 2015-05-12 12:09:33 +02:00
Francisco Dans
30e7f3fca9 Merge branch 'master' into aequus 2015-05-11 10:40:13 +02:00
Francisco Dans
5d143d4270 various optimisations for contour 2015-05-04 18:13:09 +02:00
Francisco Dans
5e2bf59c4e commas 2015-05-04 10:45:19 +02:00
Francisco Dans
e6e6664e28 improves example a bit 2015-04-30 10:15:30 +02:00
Francisco Dans
b7f1253c95 adds webworkify dependency 2015-04-30 10:15:04 +02:00
Francisco Dans
4e6744abe9 starts webworker support for colorizing 2015-04-30 10:13:15 +02:00
Francisco Dans
6d16120336 adds colorize worker 2015-04-30 10:12:25 +02:00
Francisco Dans
ee332d0762 doesn't colorize is alpha is 0 or less 2015-04-29 16:24:30 +02:00
Francisco Dans
bd479fc507 adds heatmap functionality to renderer 2015-04-29 16:20:34 +02:00
Francisco Dans
f3e9e2e3f2 puts ball precaching in different method 2015-04-29 16:19:53 +02:00
Francisco Dans
ac5b2aaf7b adjusts radius 2015-04-29 16:19:22 +02:00
Francisco Dans
52dbe5fd33 changes a couple of things in examples 2015-04-28 12:41:06 +02:00
Francisco Dans
edd49ec100 uses clamped array for values 2015-04-28 12:30:15 +02:00
Francisco Dans
4b6c680ae9 adds clamped type 2015-04-28 12:28:23 +02:00
Francisco Dans
f283167c41 adds available workers property 2015-04-28 12:27:05 +02:00
Francisco Dans
32d2334c18 adds web worker for ball renderer 2015-04-28 12:26:33 +02:00
Francisco Dans
944b5c500d adds color to isopleth 2015-04-27 12:57:54 +02:00
Francisco Dans
285260b8b0 adds colour to contours 2015-04-27 12:52:51 +02:00
Francisco Dans
62b9de79aa adds contour degradation 2015-04-27 12:52:26 +02:00
Francisco Dans
884144a442 Merge branch 'master' into aequus 2015-04-27 12:25:50 +02:00
Francisco Dans
c524df2f01 comments out cumulative in example 2015-02-27 10:32:08 +01:00
Francisco Dans
6ded5dafc9 makes isopleth work again in spito of lack of movement 2015-02-27 10:31:23 +01:00
Francisco Dans
aa79eeda20 adds getballindices 2015-02-26 18:19:48 +01:00
Francisco Dans
dc7516e9e6 modifies navy example to try renderer 2015-02-26 16:07:39 +01:00
Francisco Dans
3f9a8f4a18 full invalidation only on animation end 2015-02-26 16:06:39 +01:00
Francisco Dans
deacb1ae00 adds repeat checks in isopleth 2015-02-26 16:05:58 +01:00
Francisco Dans
83b6b3d058 invalidates layers a bit smarter 2015-02-26 16:05:25 +01:00
Francisco Dans
a8a8d79d86 caches balls 2015-02-26 16:03:20 +01:00
Francisco Dans
204df7829d makes sure that animation is paused when steps is one 2015-02-26 16:02:06 +01:00
Francisco Dans
98a37771ca gets rid of unnecessary stuff in isopleth 2015-02-25 18:10:31 +01:00
Francisco Dans
6a0fe4beb7 removes map_range 2015-02-25 18:08:33 +01:00
Francisco Dans
68ff448f78 invalidates pointarray when not cumulative 2015-02-25 18:02:41 +01:00
Francisco Dans
171a5b6e0c optimizes horizontalLine 2015-02-25 18:01:38 +01:00
Francisco Dans
7f72ae01af conveys draw calls in flush method 2015-02-25 12:47:55 +01:00
Francisco Dans
8e8ae30dc8 adds isInvalid to check for layers with wrong values 2015-02-25 12:47:12 +01:00
Francisco Dans
3fe1c60d61 simplifies invalidate 2015-02-25 12:46:45 +01:00
Francisco Dans
51fc104793 changes name to pointLayer 2015-02-25 12:46:26 +01:00
Francisco Dans
d048652ba9 optimizes drawnTemp a bit more 2015-02-25 12:45:45 +01:00
Francisco Dans
9479b214fa initialises layers JIT, instead of in the constructor 2015-02-25 12:42:21 +01:00
Francisco Dans
43e6cb7a37 invalidates the canvas properly 2015-02-25 12:40:43 +01:00
Francisco Dans
4f41136d24 calls draw at the end of each tile render instead of each canvas 2015-02-24 12:12:04 +01:00
Francisco Dans
a36fd0936a comments out comp ops 2015-02-24 12:11:37 +01:00
Francisco Dans
bc37a754a8 constructs the ballRenderer JIT 2015-02-24 12:11:04 +01:00
Francisco Dans
7ad4f21cc7 removes normalisation to 255 since native already does that 2015-02-24 12:10:21 +01:00
Francisco Dans
ea7f4efb23 checks for repeated lines using a simple array, optimizing the hell of horizontalLine 2015-02-24 12:09:46 +01:00
Francisco Dans
169de36bcf uses only canvas object, renames it to avoid future problems 2015-02-24 12:08:11 +01:00
Francisco Dans
4b240a4485 passes position on renderTile 2015-02-24 12:07:11 +01:00
Francisco Dans
d7d7396ba8 properly invalidates ballrenderer with each tile 2015-02-24 12:06:47 +01:00
Francisco Dans
cd396b19c3 prepares point renderer for ball renderer 2015-02-23 15:16:57 +01:00
Francisco Dans
82c5ef2b96 adds ball renderer 2015-02-23 15:15:43 +01:00
7 changed files with 449 additions and 147 deletions

View File

@ -16,11 +16,12 @@
// define the torque layer style using cartocss
var CARTOCSS = [
'Map {',
'-torque-time-attribute: "date";',
'-torque-time-attribute: "postedtime";',
'-torque-aggregation-function: "count(cartodb_id)";',
'-torque-frame-count: 760;',
'-torque-animation-duration: 15;',
'-torque-frame-count: 1024;',
'-torque-animation-duration: 30;',
'-torque-resolution: 2',
//'-torque-data-aggregation:cumulative;',
'}',
'#layer {',
' marker-width: 3;',
@ -33,16 +34,14 @@
' [value > 5] { marker-fill: #CC4C02; }',
' [value > 6] { marker-fill: #993404; }',
' [value > 7] { marker-fill: #662506; }',
' [frame-offset = 1] { marker-width: 10; marker-fill-opacity: 0.05;}',
' [frame-offset = 2] { marker-width: 15; marker-fill-opacity: 0.02;}',
'}'
].join('\n');
var map = new L.Map('map', {
zoomControl: true,
center: [40, 0],
zoom: 3
center: [54.1109429427243, -2.724609375],
zoom: 6
});
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
@ -50,8 +49,8 @@
}).addTo(map);
var torqueLayer = new L.TorqueLayer({
user : 'viz2',
table : 'ow',
user : 'fdansv',
table : 'twitter_jeremyclarkson_clarksonsacked_',
cartocss: CARTOCSS
});
torqueLayer.error(function(err){
@ -60,7 +59,7 @@
}
});
torqueLayer.addTo(map);
torqueLayer.play()
torqueLayer.play();
</script>
</body>
</html>

View File

@ -60,6 +60,8 @@ L.TorqueLayer = L.CanvasLayer.extend({
this.setDuration = this.animator.duration.bind(this.animator);
this.isRunning = this.animator.isRunning.bind(this.animator);
this.lastStep = 0;
L.CanvasLayer.prototype.initialize.call(this, options);
@ -212,7 +214,9 @@ L.TorqueLayer = L.CanvasLayer.extend({
var canvas = this.getCanvas();
this.renderer.clearCanvas();
var ctx = canvas.getContext('2d');
var brrr = false;
for(t in this._tiles) {
tile = this._tiles[t];
if (tile) {
@ -228,12 +232,17 @@ L.TorqueLayer = L.CanvasLayer.extend({
// when the tile has a cached image just render it and avoid to render
// all the points
this.renderer._ctx.drawImage(tile._tileCache, 0, 0);
brrr = true;
} else {
this.renderer.renderTile(tile, this.key);
this.renderer.renderTile(tile, this.key, pos);
brrr = false;
}
}
}
this.renderer.applyFilters();
var full = this.getStep() < this.lastStep;
this.lastStep = this.getStep();
if(!brrr) this.renderer.flush(full);
//this.renderer.applyFilters();
// prepare caches if the animation is not running
// don't cache if the key has just changed, this avoids to cache

300
lib/torque/renderer/ball.js Normal file
View File

@ -0,0 +1,300 @@
//////////////////////////////////
// Torque BallRenderer //
// CartoDB, 2015 //
// developed by Francisco Dans //
//////////////////////////////////
function BallRenderer(torqueLayer){
this.torqueLayer = torqueLayer;
this.canvas = torqueLayer.renderer._canvas;
this.ctx = this.canvas.getContext("2d");
this.width = this.canvas.width;
this.chWidth = this.canvas.width * 4;
this.height = this.canvas.height;
this.size = this.width * this.height;
this.pointLayer = new Uint8ClampedArray(this.size);
this.drawnTemp = {};
this.gradient = {};
this.ballsSoFar = 0;
this.balls = 0;
this.cumulative = true;
this.availableWorkers = 10;
this.mode = "heat";
this.cachedBalls = [];
this.isoplethLayer = new Uint8Array(this.size);
this.initialize();
}
BallRenderer.prototype = {
initialize: function(){
var self = this;
this.torqueLayer._map.on("movestart", function(){
self.transit = true
});
this.torqueLayer._map.on("moveend", function(){
self.transit = false
});
},
getBallIndices: function(x, y){
var indices = new Int8Array(2*r+1);
return indices;
},
addBall: function(x0, y0, st){
this.radius = st["marker-width"];
if(this.cachedBalls[this.radius]){
if(x0 < 0 || y0 < 0 || x0 > this.width || y0 > this.height) return;
var startingPoint = this.getRIndexPos(x0, y0) - this.size - this.radius;
var i = 0,
pointer = startingPoint,
ballWidth = (this.radius*2),
linemax = startingPoint + 2 * this.radius,
endPoint = this.getRIndexPos(x0, y0) - this.cachedBalls[this.radius].length - this.radius
while (pointer <= endPoint){
while (pointer <= linemax){
this.pointLayer[pointer] += this.cachedBalls[this.radius][i];
i++;
pointer++;
}
linemax += this.width;
pointer += this.width - ballWidth;
}
}
else{
this.precacheBall(x0,y0);
}
},
precacheBall: function(x0, y0){
this.cachedBalls[this.radius] = new Uint8ClampedArray(Math.pow(2 * this.radius + 1, 2));
x0 = this.radius;
y0 = this.radius;
var orad = this.radius;
var x = this.radius;
var y = 0;
var radiusError = 1 - x;
while (x >= y){
// Try not to touch the following, it's a pain in the ass to write
this.horizontalLine(-x + x0, x + x0, y + y0, x0, y0);
this.horizontalLine(-y + x0, y + x0, -x + y0, x0, y0);
this.horizontalLine(-x + x0, x + x0, -y + y0, x0, y0);
this.horizontalLine(-y + x0, y + x0, x + y0, x0, y0);
++y;
if (radiusError<0){
radiusError += 2 * y + 1;
}
else{
--x;
radiusError += 2 * (y - x) + 1;
}
}
this.drawnTemp = {};
},
horizontalLine: function(xi, xf, yi, x0, y0){
// Assumes xi is on the left and xf is on the right
if(typeof this.drawnTemp[yi] === "undefined"){
while (xi <= xf){
this.addPoint(xi, yi, 50 - ((50 * this.lineDistance(xi, yi,x0,y0)) / this.radius));
++xi;
}
this.drawnTemp[yi] = true;
}
},
addPoint: function(x, y, alpha){
var indexPos = y*(this.radius*2+1)+x;
this.cachedBalls[this.radius][indexPos] += alpha;
},
map_range: function(value, low1, high1, low2, high2) {
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
},
lineDistance: function(x,y,x0,y0){
var xs = Math.pow(x - x0, 2);
var ys = Math.pow(y - y0, 2);
return Math.sqrt( xs + ys );
},
draw: function(modeData, dataArray){
if(this.mode === "contour"){
this.contour(5);
dataArray = this.fillLayer(this.contourLayer);
}
else if(this.mode === "isopleth"){
this.contour(10);
this.isopleth();
}
else if(this.mode === "heat"){
this.heatmap();
}
if (!dataArray){
if (this.isoplethLayer) dataArray = this.isoplethLayer;
else if (this.contourLayer) dataArray = this.fillLayer(this.contourLayer);
else if (this.heatmapLayer) dataArray = this.heatmapLayer;
else dataArray = this.pointLayer;
}
if(!this.imageData) this.imageData = this.ctx.createImageData(this.width, this.height);
this.imageData.data.set(dataArray);
this.ctx.putImageData(this.imageData, 0, 0);
},
fillLayer: function(layer){
var tempList = new Uint8Array(layer.length * 4);
for(i = 0; i<layer.length; i++){
tempList[i*4 + 3] = layer[i];
}
return tempList;
},
mergeLayers: function(from, to){
if (from.length !== to.length) throw("layers aren't of the same size"); return;
for (var i = 0; i<to.length; i++){
if(from[i+3]>0){
// There's a better way of doing this but I was lazy.
to[i] = from[i];
to[i+1] = from[i+1];
to[i+2] = from[i+2];
to[i+3] = from[i+3];
}
}
},
invalidate: function(){
if(this.torqueLayer.options.steps > 1){
for (var i = 0, len = this.pointLayer.length; i< len; i++){
this.pointLayer[i] -= 10;
}
}
else{
this.pointLayer = new Uint8ClampedArray(this.size);
}
if(typeof this.isoplethLayer !== 'undefined'){
this.contourLayer = new Uint8Array(this.size);
this.isoplethLayer = new Uint8Array(this.size);
}
else if(typeof this.contourLayer !== 'undefined'){
this.contourLayer = new Uint8Array(this.size);
}
else if(typeof this.heatmapLayer !== 'undefined'){
this.heatmapLayer = new Uint8Array(this.size * 4);
}
},
getRIndexPos: function(x,y){
var rIndexPos = y*this.width+x;
return rIndexPos;
},
getXYFromRIndex: function(index){
var x = (index % (this.width*4))/4;
var y = (index - 4 * x) / (4 * this.width);
return [x,y];
},
isEmpty: function(layer) {
for (var i = 0; i<layer.length; i+=4){
if(layer[i+3] > 0) return false;
}
return true;
},
isInvalid: function(layer) {
for (var i = 0; i<layer.length; i+=4){
if(layer[i+3]!==0 && !layer[i+3]) return true;
}
return false;
},
createArray: function(){
return new Uint8ClampedArray(this.size * 4);
},
contour: function(granularity){
if(!this.contourGradient){
var step = 255/granularity;
var i = 0, a = new Uint8ClampedArray(granularity+1), c=0;
while (i<255){
a[c] = i;
i += step;
c++;
}
a[a.length-1] = 255;
var l = -step/2;
this.contourGradient = new Uint8ClampedArray(1024);
for(var i = 0; i<a.length; i++){
var y = Math.round(i*step);
var thisAlpha = a[i];
while(y<step*(i+1)){
this.contourGradient[y*4+3] = thisAlpha;
y++;
}
}
}
var gradient = this.contourGradient;
if(!this.contourLayer) this.contourLayer = new Uint8Array(this.size);
for (var i = 0, len = this.pointLayer.length, alpha; i<len; i++){
if(this.pointLayer[i] > 0){
var alpha = this.pointLayer[i];
this.contourLayer[i] = gradient[alpha*4+3];
}
}
},
isopleth: function(){
for (var i = 0, len = this.contourLayer.length; i<len; i+=4){
var alpha = this.contourLayer[i + 3];
if (alpha > 100 && alpha < 120){
var n = i - this.chWidth,
s = i + this.chWidth,
neighbors = [n, n + 4, i + 4, s + 4, s, s - 4, i - 4, n -4];
for (var n = 0, ln = neighbors.length; n<ln; ++n){
var index = neighbors[n];
if(index>0 && (this.contourLayer[index+3] === 0 || this.contourLayer[index+3] !== this.contourLayer[i+3])){
this.isoplethLayer[index + 3] = Math.min(this.contourLayer[i+3],255);
}
}
}
}
},
heatmap: function (gradient){
if(!gradient) gradient = {
0.4: 'blue',
0.6: 'cyan',
0.7: 'lightgreen',
0.9: 'yellow',
1.0: 'red'
};
if(JSON.stringify(this.gradient) !== JSON.stringify(gradient)){
this.gradient = gradient;
// create a 256x1 gradient that we'll use to turn a grayscale heatmap into a colored one
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
gradientColours = ctx.createLinearGradient(0, 0, 0, 256);
canvas.width = 1;
canvas.height = 256;
for (var i in gradient) {
gradientColours.addColorStop(+i, gradient[i]);
}
ctx.fillStyle = gradientColours;
ctx.fillRect(0, 0, 1, 256);
this.gradientData = ctx.getImageData(0, 0, 1, 256).data;
}
this.colorize();
},
colorize: function () {
var grad = this.gradientData;
if(!this.heatmapLayer) this.heatmapLayer = new Uint8ClampedArray(this.size * 4);
for (var i = this.pointLayer.length-4, alpha; i>=0; i-=4){
alpha = this.pointLayer[i+3] * 4; // get gradient color from opacity value
if (alpha>0) {
this.heatmapLayer[i] = grad[alpha]; // R
this.heatmapLayer[i + 1] = grad[alpha + 1]; // G
this.heatmapLayer[i + 2] = grad[alpha + 2]; // B
this.heatmapLayer[i + 3] = alpha; // A
}
}
},
initColorWorkers: function(){
var workerCount = 3
this.colorWorkers = [];
for (var i = 0; i < workerCount; i++) {
this.colorWorkers.push(work(require('./colorWorker.js')));
}
}
}
module.exports = BallRenderer;

View File

View File

@ -0,0 +1,13 @@
onmessage = function(e){
var cutoff = e.data[1];
var subset = e.data[0].slice(b,f);
for (var i = subset.length-4, alpha; i>=0; i-=4){
alpha = subset[i+3] * 4; // get gradient color from opacity value
if (alpha>0) {
this.heatmapLayer[i] = grad[alpha]; // R
this.heatmapLayer[i + 1] = grad[alpha + 1]; // G
this.heatmapLayer[i + 2] = grad[alpha + 2]; // B
this.heatmapLayer[i + 3] = alpha; // A
}
}
}

View File

@ -2,7 +2,8 @@ var torque = require('../');
var cartocss = require('./cartocss_render');
var Profiler = require('../profiler');
var carto = global.carto || require('carto');
var Filters = require('./torque_filters');
var filters = require('./torque_filters');
var ballRenderer = require('./ball.js');
var TAU = Math.PI * 2;
var DEFAULT_CARTOCSS = [
@ -51,8 +52,7 @@ var Filters = require('./torque_filters');
this._sprites = []; // sprites per layer
this._shader = null;
this._icons = {};
this._iconsToLoad = 0;
this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass});
this._filters = filters(this._canvas);
this.setCartoCSS(this.options.cartocss || DEFAULT_CARTOCSS);
this.TILE_SIZE = 256;
this._style = null;
@ -129,6 +129,8 @@ var Filters = require('./torque_filters');
}
var canvas = this._createCanvas();
// take into account the exterior ring to calculate the size
var canvasSize = (st['marker-line-width'] || 0) + pointSize*2;
var ctx = canvas.getContext('2d');
var markerFile = st["marker-file"] || st["point-file"];
@ -151,7 +153,6 @@ var Filters = require('./torque_filters');
var canvasSize = (st['marker-line-width'] || 0) + pointSize*2;
var w = ctx.width = canvas.width = ctx.height = canvas.height = Math.ceil(canvasSize);
ctx.translate(w/2, w/2);
var mt = st['marker-type'];
if (mt && mt === 'rectangle') {
cartocss.renderRectangle(ctx, st);
@ -172,13 +173,11 @@ var Filters = require('./torque_filters');
//
// renders all the layers (and frames for each layer) from cartocss
//
renderTile: function(tile, key, callback) {
if (this._iconsToLoad > 0) {
this.on('allIconsLoaded', function() {
this.renderTile.apply(this, [tile, key, callback]);
});
return false;
renderTile: function(tile, key,pos) {
if(typeof this.ballRenderer === "undefined"){
this.ballRenderer = new ballRenderer(this._canvas);
}
// this._renderTile(tile, key, 0, null, null, null, pos);
var prof = Profiler.metric('torque.renderer.point.renderLayers').start();
var layers = this._shader.getLayers();
for(var i = 0, n = layers.length; i < n; ++i ) {
@ -189,14 +188,12 @@ var Filters = require('./torque_filters');
for(var fr = 0; fr < layer.frames().length; ++fr) {
var frame = layer.frames()[fr];
var fr_sprites = sprites[frame] || (sprites[frame] = []);
this._renderTile(tile, key - frame, frame, fr_sprites, layer);
this._renderTile(tile, key - frame, frame, fr_sprites, layer, null, pos);
}
}
}
prof.end(true);
return callback && callback(null);
// prof.end(true);
},
_createCanvas: function() {
@ -210,21 +207,6 @@ var Filters = require('./torque_filters');
? new this.options.imageClass()
: new Image();
},
_setImageSrc: function(img, url, callback) {
if (this.options.setImageSrc) {
this.options.setImageSrc(img, url, callback);
} else {
img.onload = function(){
callback(null);
};
img.onerror = function(){
callback(new Error('Could not load image'));
};
img.src = url;
}
},
_qualifyURL: function(url) {
if (typeof this.options.qualifyURL !== "undefined"){
return this.options.qualifyURL(url);
@ -240,42 +222,47 @@ var Filters = require('./torque_filters');
// renders a tile in the canvas for key defined in
// the torque tile
//
_renderTile: function(tile, key, frame_offset, sprites, shader, shaderVars) {
_renderTile: function(tile, key, frame_offset, sprites, shader, shaderVars, pos) {
shaderVars = shaderVars || { zoom: tile.z, 'frame-offset': frame_offset }
if (!this._canvas) return;
var prof = Profiler.metric('torque.renderer.point.renderTile').start();
var ctx = this._ctx;
var blendMode = compop2canvas(shader.eval('comp-op')) || this.options.blendmode;
if (blendMode) {
ctx.globalCompositeOperation = blendMode;
}
// var blendMode = compop2canvas(shader.eval('comp-op')) || this.options.blendmode;
// if (blendMode) {
// ctx.globalCompositeOperation = blendMode;
// }
if (this.options.cumulative && key > tile.maxDate) {
//TODO: precache because this tile is not going to change
key = tile.maxDate;
}
var tileMax = this.options.resolution * (this.TILE_SIZE/this.options.resolution - 1)
var activePixels = tile.timeCount[key];
var anchor = this.options.resolution/2;
if (activePixels) {
var pixelIndex = tile.timeIndex[key];
for(var p = 0; p < activePixels; ++p) {
var posIdx = tile.renderDataPos[pixelIndex + p];
var c = tile.renderData[pixelIndex + p];
if (c) {
var sp = sprites[c];
if (sp === undefined) {
sp = sprites[c] = this.generateSprite(shader, c, torque.extend({ zoom: tile.z, 'frame-offset': frame_offset }, shaderVars));
}
if (sp) {
var x = tile.x[posIdx]- (sp.width >> 1) + anchor;
var y = tileMax - tile.y[posIdx] + anchor; // flip mercator
ctx.drawImage(sp, x, y - (sp.height >> 1));
}
var x = tile.x[posIdx];
var y = tileMax - tile.y[posIdx]; // flip mercator
var st = shader.getStyle({
value: c
}, shaderVars);
this.ballRenderer.addBall(pos.x + x, pos.y + y, st);
// var sp = sprites[c];
// if (sp === undefined) {
// sp = sprites[c] = this.generateSprite(shader, c, torque.extend({ zoom: tile.z, 'frame-offset': frame_offset }, shaderVars));
// }
// if (sp) {
// var x = tile.x[posIdx]- (sp.width >> 1);
// var y = tileMax - tile.y[posIdx]; // flip mercator
// ctx.drawImage(sp, x, y - (sp.height >> 1));
// }
}
}
}
prof.end(true);
},
@ -347,62 +334,46 @@ var Filters = require('./torque_filters');
}
return null;
},
_preloadIcons: function(img_names) {
_preloadIcons: function(img_names){
var self = this;
if (img_names.length > 0 && !this._forcePoints) {
var qualifiedImageUrlSet = Object.keys(img_names.reduce(function(imgNamesMap, imgName) {
var qualifiedUrl = self._qualifyURL(imgName);
if (!self._icons[qualifiedUrl]) {
imgNamesMap[qualifiedUrl] = true;
}
return imgNamesMap;
}, {}));
var filtered = self._shader.getLayers().some(function(layer) {
return typeof layer.shader["image-filters"] !== "undefined";
});
this._iconsToLoad += qualifiedImageUrlSet.length;
qualifiedImageUrlSet.forEach(function(qualifiedImageUrl) {
self._icons[qualifiedImageUrl] = null;
var img = self._createImage();
if (filtered) {
img.crossOrigin = 'Anonymous';
this._icons = {};
if (img_names.length > 0 && !this._forcePoints){
for (var i = 0; i<img_names.length; i++){
var new_img = this._createImage();
this._icons[this._qualifyURL(img_names[i])] = null;
if (typeof self._icons.itemsToLoad === 'undefined'){
this._icons.itemsToLoad = img_names.length;
}
self._setImageSrc(img, qualifiedImageUrl, function(err) {
if (err) {
self._forcePoints = true;
self.clearSpriteCache();
self._iconsToLoad = 0;
self.fire("allIconsLoaded");
if(filtered) {
console.info("Only CORS-enabled, or same domain image-files can be used in combination with image-filters");
}
console.error("Couldn't get marker-file " + qualifiedImageUrl);
} else {
self._icons[qualifiedImageUrl] = img;
self._iconsToLoad--;
if (self._iconsToLoad <= 0){
var filtered = self._shader.getLayers().some(function(layer){return typeof layer.shader["image-filters"] !== "undefined"});
if (filtered){
new_img.crossOrigin = 'Anonymous';
}
new_img.onload = function(e){
self._icons[this.src] = this;
if (Object.keys(self._icons).length === img_names.length + 1){
self._icons.itemsToLoad--;
if (self._icons.itemsToLoad <= 0){
self.clearSpriteCache();
self.fire("allIconsLoaded");
}
}
});
});
} else {
this.fire("allIconsLoaded");
};
new_img.onerror = function(){
self._forcePoints = true;
self.clearSpriteCache();
if(filtered){
console.info("Only CORS-enabled, or same domain image-files can be used in combination with image-filters");
}
console.error("Couldn't get marker-file " + this.src);
};
this.itemsToLoad++;
new_img.src = img_names[i];
}
}
},
},
applyFilters: function(){
return;
if(this._style){
if(this._style['image-filters']){
function gradientKey(imf){
@ -439,6 +410,13 @@ var Filters = require('./torque_filters');
this._filters.draw();
}
}
},
flush: function(full){
this._ctx.setTransform(1, 0, 0, 1, 0, 0);
if(!this.ballRenderer) return;
this.ballRenderer.mode = "isopleth";
this.ballRenderer.draw();
this.ballRenderer.invalidate();
}
});

View File

@ -1,46 +1,49 @@
{
"name": "torque.js",
"version": "2.11.1",
"description": "Torque javascript library",
"repository": {
"type": "git",
"url": "git://github.com/CartoDB/torque.git"
},
"author": {
"name": "CartoDB",
"url": "http://cartodb.com/",
"email": "wadus@cartodb.com"
},
"contributors": [
"Andrew Hill <andrew@vizzuality.com>",
"Simon Tokumine <tokumine@google.com>",
"Javier Alvarez <jmedina@vizzuality.com>",
"Javier Arce <javierarce@vizzuality.com>",
"Javier Santana <jsantana@vizzuality.com>",
"Raúl Ochoa <rochoa@cartodb.com>",
"Nicklas Gummesson <nicklas@cartodb.com>",
"Francisco Dans <francisco@cartodb.com>"
],
"licenses": [{
"name": "torque.js",
"version": "2.11.1",
"description": "Torque javascript library",
"repository": {
"type": "git",
"url": "git://github.com/CartoDB/torque.git"
},
"author": {
"name": "CartoDB",
"url": "http://cartodb.com/",
"email": "wadus@cartodb.com"
},
"contributors": [
"Andrew Hill <andrew@vizzuality.com>",
"Simon Tokumine <tokumine@google.com>",
"Javier Alvarez <jmedina@vizzuality.com>",
"Javier Arce <javierarce@vizzuality.com>",
"Javier Santana <jsantana@vizzuality.com>",
"Raúl Ochoa <rochoa@cartodb.com>",
"Nicklas Gummesson <nicklas@cartodb.com>",
"Francisco Dans <francisco@cartodb.com>"
],
"licenses": [
{
"type": "BSD"
}],
"dependencies": {
"carto": "https://github.com/CartoDB/carto/archive/master.tar.gz"
},
"devDependencies": {
"leaflet": "0.7.3",
"underscore": "^1.6.0",
"node-qunit-phantomjs": "^1.0.0",
"browserify": "^7.0.0",
"mapnik": "https://github.com/CartoDB/node-mapnik/tarball/1.4.15-cdb1",
"canvas": "~1.2.1",
"request": "^2.53.0",
"qunit": "~0.7.5",
"qunitjs": "1.x",
"uglify-js": "1.3.3"
},
"scripts": {
"test": "make test-all"
},
"main": "./lib/torque/index.js"
}
],
"dependencies": {
"carto": "https://github.com/CartoDB/carto/archive/master.tar.gz",
"webworkify": "^1.0.2"
},
"devDependencies": {
"leaflet": "0.7.3",
"underscore": "^1.6.0",
"node-qunit-phantomjs": "^1.0.0",
"browserify": "^7.0.0",
"mapnik": "https://github.com/CartoDB/node-mapnik/tarball/1.4.15-cdb1",
"canvas": "~1.2.1",
"request": "^2.53.0",
"qunit": "~0.7.5",
"qunitjs": "1.x",
"uglify-js": "1.3.3"
},
"scripts": {
"test": "make test-all"
},
"main": "./lib/torque/index.js"
}