Support multiple values/operands

This commit is contained in:
Raul Ochoa 2017-03-05 23:31:32 +01:00
parent b6186d884c
commit 2c092f6b39
2 changed files with 15 additions and 1 deletions

View File

@ -36,7 +36,9 @@ tree.Value.prototype = {
v = "'" + v + "'";
} else if (val.is === 'field') {
// replace [variable] by ctx['variable']
v = v.replace(/\[(.*)\]/g, "data['$1']");
v = v.replace(/\[([^\]]*)\]/g, function(matched) {
return matched.replace(/\[(.*)\]/g, "data['$1']");
});
}else if (val.is === 'call') {
v = JSON.stringify({
name: val.name,

View File

@ -183,4 +183,16 @@ describe('RenderingJS', function() {
assert.equal(st.args[2].args[0].value, 10);
});
it("should work with multiple operands", function(){
var css = [
'#layer {',
' marker-width: [value] * [value] * 0.5;',
'}'
].join('\n');
var shader = (new carto.RendererJS({ debug: false })).render(css);
var layer = shader.getLayers()[0];
var width = layer.shader['marker-width'].style({value: 4}, {zoom: 1});
assert.equal(width, 8);
});
});