adds turbocarto integration
This commit is contained in:
parent
2377029350
commit
5f92bdc9da
@ -3,6 +3,8 @@ var cartocss = require('./cartocss_render');
|
||||
var Profiler = require('../profiler');
|
||||
var carto = global.carto || require('carto');
|
||||
var Filters = require('./torque_filters');
|
||||
var turbocarto = require('turbo-carto');
|
||||
var CartoDatasource = require('./datasource');
|
||||
|
||||
var TAU = Math.PI * 2;
|
||||
var DEFAULT_CARTOCSS = [
|
||||
@ -62,6 +64,7 @@ var Filters = require('./torque_filters');
|
||||
throw new Error("canvas can't be undefined");
|
||||
}
|
||||
this.options = options;
|
||||
this.layer = options.layer;
|
||||
this._canvas = canvas;
|
||||
this._ctx = canvas.getContext('2d');
|
||||
this._sprites = []; // sprites per layer
|
||||
@ -69,7 +72,7 @@ var Filters = require('./torque_filters');
|
||||
this._icons = {};
|
||||
this._iconsToLoad = 0;
|
||||
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._style = null;
|
||||
this._gradients = {};
|
||||
@ -80,18 +83,20 @@ var Filters = require('./torque_filters');
|
||||
torque.extend(PointRenderer.prototype, torque.Event, {
|
||||
|
||||
clearCanvas: function() {
|
||||
var canvas = this._canvas;
|
||||
var color = this._Map['-torque-clear-color']
|
||||
// shortcut for the default value
|
||||
if (color === "rgba(255, 255, 255, 0)" || !color) {
|
||||
this._canvas.width = this._canvas.width;
|
||||
} else {
|
||||
var ctx = this._ctx;
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
var compop = this._Map['comp-op']
|
||||
ctx.globalCompositeOperation = compop2canvas(compop) || compop;
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
if (this._Map) {
|
||||
var canvas = this._canvas;
|
||||
var color = this._Map['-torque-clear-color']
|
||||
// shortcut for the default value
|
||||
if (color === "rgba(255, 255, 255, 0)" || !color) {
|
||||
this._canvas.width = this._canvas.width;
|
||||
} else {
|
||||
var ctx = this._ctx;
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
var compop = this._Map['comp-op']
|
||||
ctx.globalCompositeOperation = compop2canvas(compop) || compop;
|
||||
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
|
||||
//
|
||||
setCartoCSS: function(cartocss) {
|
||||
// clean sprites
|
||||
this.setShader(new carto.RendererJS().render(cartocss));
|
||||
var self = this;
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user