|
|
|
@ -6,7 +6,8 @@ var Filters = require('./torque_filters');
|
|
|
|
|
var turbocarto = require('turbo-carto');
|
|
|
|
|
var CartoDatasource = require('./datasource');
|
|
|
|
|
|
|
|
|
|
var TAU = Math.PI * 2;
|
|
|
|
|
var ERROR_IMG_URL = 'http://matataonboarding.localhost.lan:3000/assets/4.10.67/images/error.svg';
|
|
|
|
|
|
|
|
|
|
var DEFAULT_CARTOCSS = [
|
|
|
|
|
'#layer {',
|
|
|
|
|
' marker-fill: #662506;',
|
|
|
|
@ -120,6 +121,10 @@ var CartoDatasource = require('./datasource');
|
|
|
|
|
if (PointRenderer.isTurboCarto(cartocss)) {
|
|
|
|
|
var datasource = new CartoDatasource(self.layer._tiles);
|
|
|
|
|
turbocarto(cartocss, datasource, function (err, parsedCartoCSS) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.setShader(new carto.RendererJS().render(parsedCartoCSS));
|
|
|
|
|
self.layer.redraw();
|
|
|
|
|
self.layer.animator.start();
|
|
|
|
@ -137,6 +142,8 @@ var CartoDatasource = require('./datasource');
|
|
|
|
|
this._shader = shader;
|
|
|
|
|
this._Map = this._shader.getDefault().getStyle({}, { zoom: 0 });
|
|
|
|
|
var img_names = this._shader.getImageURLs();
|
|
|
|
|
img_names.push(ERROR_IMG_URL);
|
|
|
|
|
|
|
|
|
|
this._preloadIcons(img_names);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -212,6 +219,12 @@ var CartoDatasource = require('./datasource');
|
|
|
|
|
// renders all the layers (and frames for each layer) from cartocss
|
|
|
|
|
//
|
|
|
|
|
renderTile: function(tile, keys, callback) {
|
|
|
|
|
if (tile.error) {
|
|
|
|
|
this._renderErrorTile(tile);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this._iconsToLoad > 0) {
|
|
|
|
|
this.on('allIconsLoaded', function() {
|
|
|
|
|
this.renderTile.apply(this, [tile, keys, callback]);
|
|
|
|
@ -283,6 +296,11 @@ var CartoDatasource = require('./datasource');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_renderErrorTile: function(tile) {
|
|
|
|
|
var img = this._icons[ERROR_IMG_URL];
|
|
|
|
|
img && this._ctx.drawImage(img, 0, 0, this.TILE_SIZE, this.TILE_SIZE);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// renders a tile in the canvas for key defined in
|
|
|
|
|
// the torque tile
|
|
|
|
@ -464,47 +482,47 @@ var CartoDatasource = require('./datasource');
|
|
|
|
|
} else {
|
|
|
|
|
this.fire("allIconsLoaded");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
applyFilters: function(){
|
|
|
|
|
if(this._style){
|
|
|
|
|
if(this._style['image-filters']){
|
|
|
|
|
function gradientKey(imf){
|
|
|
|
|
var hash = ""
|
|
|
|
|
for(var i = 0; i < imf.args.length; i++){
|
|
|
|
|
var rgb = imf.args[i].rgb;
|
|
|
|
|
hash += rgb[0] + ":" + rgb[1] + ":" + rgb[2];
|
|
|
|
|
}
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
var gradient = this._gradients[gradientKey(this._style['image-filters'])];
|
|
|
|
|
if(!gradient){
|
|
|
|
|
function componentToHex(c) {
|
|
|
|
|
var hex = c.toString(16);
|
|
|
|
|
return hex.length == 1 ? "0" + hex : hex;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
function rgbToHex(r, g, b) {
|
|
|
|
|
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
|
|
|
applyFilters: function(){
|
|
|
|
|
if(this._style){
|
|
|
|
|
if(this._style['image-filters']){
|
|
|
|
|
function gradientKey(imf){
|
|
|
|
|
var hash = ""
|
|
|
|
|
for(var i = 0; i < imf.args.length; i++){
|
|
|
|
|
var rgb = imf.args[i].rgb;
|
|
|
|
|
hash += rgb[0] + ":" + rgb[1] + ":" + rgb[2];
|
|
|
|
|
}
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
gradient = {};
|
|
|
|
|
var colorize = this._style['image-filters'].args;
|
|
|
|
|
|
|
|
|
|
var increment = 1/colorize.length;
|
|
|
|
|
for (var i = 0; i < colorize.length; i++){
|
|
|
|
|
var key = increment * i + increment;
|
|
|
|
|
var rgb = colorize[i].rgb;
|
|
|
|
|
var formattedColor = rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
|
|
|
gradient[key] = formattedColor;
|
|
|
|
|
var gradient = this._gradients[gradientKey(this._style['image-filters'])];
|
|
|
|
|
if(!gradient){
|
|
|
|
|
function componentToHex(c) {
|
|
|
|
|
var hex = c.toString(16);
|
|
|
|
|
return hex.length == 1 ? "0" + hex : hex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rgbToHex(r, g, b) {
|
|
|
|
|
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
|
|
|
}
|
|
|
|
|
gradient = {};
|
|
|
|
|
var colorize = this._style['image-filters'].args;
|
|
|
|
|
|
|
|
|
|
var increment = 1/colorize.length;
|
|
|
|
|
for (var i = 0; i < colorize.length; i++){
|
|
|
|
|
var key = increment * i + increment;
|
|
|
|
|
var rgb = colorize[i].rgb;
|
|
|
|
|
var formattedColor = rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
|
|
|
gradient[key] = formattedColor;
|
|
|
|
|
}
|
|
|
|
|
this._gradients[gradientKey(this._style['image-filters'])] = gradient;
|
|
|
|
|
}
|
|
|
|
|
this._gradients[gradientKey(this._style['image-filters'])] = gradient;
|
|
|
|
|
this._filters.gradient(gradient);
|
|
|
|
|
this._filters.draw();
|
|
|
|
|
}
|
|
|
|
|
this._filters.gradient(gradient);
|
|
|
|
|
this._filters.draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PointRenderer.isTurboCarto = function (cartocss) {
|
|
|
|
|
var reservedWords = ['ramp', 'colorbrewer', 'buckets']
|
|
|
|
|