detects renderer from style

This commit is contained in:
Francisco Dans 2015-08-20 14:22:55 +02:00
parent 5f6a069791
commit 595c254dbe
2 changed files with 25 additions and 13 deletions

View File

@ -16,33 +16,42 @@
// define the torque layer style using cartocss // define the torque layer style using cartocss
var CARTOCSS = [ var CARTOCSS = [
'Map {', 'Map {',
'-torque-time-attribute: "cartodb_id";', '-torque-time-attribute: "date";',
'-torque-aggregation-function: "count(cartodb_id)";', '-torque-aggregation-function: "count(cartodb_id)";',
'-torque-frame-count: 1;', '-torque-frame-count: 760;',
'-torque-animation-duration: 1;', '-torque-animation-duration: 15;',
'-torque-resolution: 16', '-torque-resolution: 2',
'}', '}',
'#layer {', '#layer {',
'-isoline-line-ramp: colorize-alpha(blue, cyan, lightgreen, yellow , orange, red);', ' marker-width: 3;',
'-isoline-line-width: 0.4;', ' marker-fill-opacity: 0.8;',
'-isoline-line-opacity: 0.5', ' marker-fill: #FEE391; ',
' comp-op: "lighten";',
' [value > 2] { marker-fill: #FEC44F; }',
' [value > 3] { marker-fill: #FE9929; }',
' [value > 4] { marker-fill: #EC7014; }',
' [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'); ].join('\n');
var map = new L.Map('map', { var map = new L.Map('map', {
zoomControl: true, zoomControl: true,
center: [41.36031866306708, -73.388671875], center: [40, 0],
zoom: 4 zoom: 3
}); });
L.tileLayer('http://{s}.api.cartocdn.com/base-light/{z}/{x}/{y}.png', { L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
attribution: 'CartoDB' attribution: 'CartoDB'
}).addTo(map); }).addTo(map);
var torqueLayer = new L.TorqueLayer({ var torqueLayer = new L.TorqueLayer({
user : 'fdansv', user : 'viz2',
table : 'twitter_roosterteeth_roosterteeth_lege', table : 'ow',
cartocss: CARTOCSS cartocss: CARTOCSS
}); });
torqueLayer.error(function(err){ torqueLayer.error(function(err){

View File

@ -31,9 +31,12 @@ TorqueLayer.optionsFromLayer = function(mapConfig) {
}; };
TorqueLayer.optionsFromCartoCSS = function(cartocss) { TorqueLayer.optionsFromCartoCSS = function(cartocss) {
var renderer = cartocss.indexOf("-isoline-") > -1? "iso":"point";
var shader = new carto.RendererJS().render(cartocss); var shader = new carto.RendererJS().render(cartocss);
var mapConfig = shader.findLayer({ name: 'Map' }); var mapConfig = shader.findLayer({ name: 'Map' });
return TorqueLayer.optionsFromLayer(mapConfig); var options = TorqueLayer.optionsFromLayer(mapConfig);
options.renderer = renderer;
return options;
}; };
module.exports.TorqueLayer = TorqueLayer; module.exports.TorqueLayer = TorqueLayer;