adds turbocarto integration

This commit is contained in:
Francisco Dans 2016-07-04 18:50:22 +02:00
parent 2377029350
commit 5f92bdc9da

View File

@ -3,6 +3,8 @@ 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 turbocarto = require('turbo-carto');
var CartoDatasource = require('./datasource');
var TAU = Math.PI * 2; var TAU = Math.PI * 2;
var DEFAULT_CARTOCSS = [ var DEFAULT_CARTOCSS = [
@ -62,6 +64,7 @@ var Filters = require('./torque_filters');
throw new Error("canvas can't be undefined"); throw new Error("canvas can't be undefined");
} }
this.options = options; this.options = options;
this.layer = options.layer;
this._canvas = canvas; this._canvas = canvas;
this._ctx = canvas.getContext('2d'); this._ctx = canvas.getContext('2d');
this._sprites = []; // sprites per layer this._sprites = []; // sprites per layer
@ -69,7 +72,7 @@ var Filters = require('./torque_filters');
this._icons = {}; this._icons = {};
this._iconsToLoad = 0; this._iconsToLoad = 0;
this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass}); this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass});
this.setCartoCSS(this.options.cartocss || DEFAULT_CARTOCSS); this.style = this.options.cartocss || DEFAULT_CARTOCSS;
this.TILE_SIZE = 256; this.TILE_SIZE = 256;
this._style = null; this._style = null;
this._gradients = {}; this._gradients = {};
@ -80,18 +83,20 @@ var Filters = require('./torque_filters');
torque.extend(PointRenderer.prototype, torque.Event, { torque.extend(PointRenderer.prototype, torque.Event, {
clearCanvas: function() { clearCanvas: function() {
var canvas = this._canvas; if (this._Map) {
var color = this._Map['-torque-clear-color'] var canvas = this._canvas;
// shortcut for the default value var color = this._Map['-torque-clear-color']
if (color === "rgba(255, 255, 255, 0)" || !color) { // shortcut for the default value
this._canvas.width = this._canvas.width; if (color === "rgba(255, 255, 255, 0)" || !color) {
} else { this._canvas.width = this._canvas.width;
var ctx = this._ctx; } else {
ctx.setTransform(1, 0, 0, 1, 0, 0); var ctx = this._ctx;
var compop = this._Map['comp-op'] ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.globalCompositeOperation = compop2canvas(compop) || compop; var compop = this._Map['comp-op']
ctx.fillStyle = color; ctx.globalCompositeOperation = compop2canvas(compop) || compop;
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = color;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
} }
}, },
@ -104,8 +109,13 @@ var Filters = require('./torque_filters');
// sets the cartocss style to render stuff // sets the cartocss style to render stuff
// //
setCartoCSS: function(cartocss) { setCartoCSS: function(cartocss) {
// clean sprites var self = this;
this.setShader(new carto.RendererJS().render(cartocss)); var datasource = new CartoDatasource(self.layer._tiles);
turbocarto(cartocss, datasource, function (err, parsedCartoCSS) {
self.setShader(new carto.RendererJS().render(parsedCartoCSS));
self.layer.redraw();
self.layer.animator.start()
});
}, },
setShader: function(shader) { setShader: function(shader) {