prepares point renderer for ball renderer

This commit is contained in:
Francisco Dans 2015-02-23 15:16:57 +01:00
parent 82c5ef2b96
commit cd396b19c3

View File

@ -3,6 +3,7 @@ var cartocss = require('./cartocss_render');
var Profiler = require('../profiler'); var Profiler = require('../profiler');
var carto = global.carto || require('carto'); 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 TAU = Math.PI * 2;
var DEFAULT_CARTOCSS = [ var DEFAULT_CARTOCSS = [
@ -56,6 +57,7 @@ var filters = require('./torque_filters');
this.TILE_SIZE = 256; this.TILE_SIZE = 256;
this._style = null; this._style = null;
this._gradients = {}; this._gradients = {};
this._ballRenderer = ballRenderer(this._canvas);
this._forcePoints = false; this._forcePoints = false;
} }
@ -163,22 +165,23 @@ var filters = require('./torque_filters');
// renders all the layers (and frames for each layer) from cartocss // renders all the layers (and frames for each layer) from cartocss
// //
renderTile: function(tile, key) { renderTile: function(tile, key) {
var prof = Profiler.metric('torque.renderer.point.renderLayers').start(); this._renderTile(tile, key, 0, null, null, null, pos);
var layers = this._shader.getLayers(); // var prof = Profiler.metric('torque.renderer.point.renderLayers').start();
for(var i = 0, n = layers.length; i < n; ++i ) { // var layers = this._shader.getLayers();
var layer = layers[i]; // for(var i = 0, n = layers.length; i < n; ++i ) {
if (layer.name() !== "Map") { // var layer = layers[i];
var sprites = this._sprites[i] || (this._sprites[i] = {}); // if (layer.name() !== "Map") {
// frames for each layer // var sprites = this._sprites[i] || (this._sprites[i] = {});
for(var fr = 0; fr < layer.frames().length; ++fr) { // // frames for each layer
var frame = layer.frames()[fr]; // for(var fr = 0; fr < layer.frames().length; ++fr) {
var fr_sprites = sprites[frame] || (sprites[frame] = []); // var frame = layer.frames()[fr];
this._renderTile(tile, key - frame, frame, fr_sprites, layer); // var fr_sprites = sprites[frame] || (sprites[frame] = []);
} // this._renderTile(tile, key - frame, frame, fr_sprites, layer);
} // }
} // }
// }
prof.end(true); // prof.end(true);
}, },
_createCanvas: function() { _createCanvas: function() {
@ -207,7 +210,7 @@ var filters = require('./torque_filters');
// renders a tile in the canvas for key defined in // renders a tile in the canvas for key defined in
// the torque tile // the torque tile
// //
_renderTile: function(tile, key, frame_offset, sprites, shader, shaderVars) { _renderTile: function(tile, key, frame_offset, sprites, shader, shaderVars, pos) {
if (!this._canvas) return; if (!this._canvas) return;
var prof = Profiler.metric('torque.renderer.point.renderTile').start(); var prof = Profiler.metric('torque.renderer.point.renderTile').start();
@ -228,15 +231,15 @@ var filters = require('./torque_filters');
var posIdx = tile.renderDataPos[pixelIndex + p]; var posIdx = tile.renderDataPos[pixelIndex + p];
var c = tile.renderData[pixelIndex + p]; var c = tile.renderData[pixelIndex + p];
if (c) { if (c) {
var sp = sprites[c]; // var sp = sprites[c];
if (sp === undefined) { // if (sp === undefined) {
sp = sprites[c] = this.generateSprite(shader, c, torque.extend({ zoom: tile.z, 'frame-offset': frame_offset }, shaderVars)); // sp = sprites[c] = this.generateSprite(shader, c, torque.extend({ zoom: tile.z, 'frame-offset': frame_offset }, shaderVars));
} // }
if (sp) { // if (sp) {
var x = tile.x[posIdx]- (sp.width >> 1); // var x = tile.x[posIdx]- (sp.width >> 1);
var y = tileMax - tile.y[posIdx]; // flip mercator // var y = tileMax - tile.y[posIdx]; // flip mercator
ctx.drawImage(sp, x, y - (sp.height >> 1)); // ctx.drawImage(sp, x, y - (sp.height >> 1));
} // }
} }
} }
} }