Merge pull request #8 from CartoDB/icon-list
Adding method to extract all "marker-file" properties
This commit is contained in:
commit
00c7a631b1
@ -5,6 +5,7 @@ var _ = global._ || require('underscore');
|
||||
|
||||
function CartoCSS(style, options) {
|
||||
this.options = options || {};
|
||||
this.imageURLs = [];
|
||||
if(style) {
|
||||
this.setStyle(style);
|
||||
}
|
||||
@ -164,6 +165,9 @@ CartoCSS.prototype = {
|
||||
}
|
||||
}
|
||||
},
|
||||
getImageURLs: function(){
|
||||
return this.imageURLs;
|
||||
},
|
||||
|
||||
parse: function(cartocss) {
|
||||
var parse_env = {
|
||||
@ -198,6 +202,12 @@ CartoCSS.prototype = {
|
||||
var layer = layers[key] = (layers[key] || {
|
||||
symbolizers: []
|
||||
});
|
||||
for(var u = 0; u<def.rules.length; u++){
|
||||
if(def.rules[u].name === "marker-file" || def.rules[u].name === "point-file"){
|
||||
var value = def.rules[u].value.value[0].value[0].value.value;
|
||||
this.imageURLs.push(value);
|
||||
}
|
||||
}
|
||||
layer.frames = [];
|
||||
layer.zoom = tree.Zoom.all;
|
||||
var props = def.toJS(parse_env);
|
||||
|
@ -74,6 +74,35 @@ describe('RenderingJS', function() {
|
||||
assert(layer0.getSymbolizers()[1] === 'line');
|
||||
});
|
||||
|
||||
it ("should return list of marker-files", function(){
|
||||
var css = [
|
||||
'Map {',
|
||||
'-torque-time-attribute: "date";',
|
||||
'-torque-aggregation-function: "count(cartodb_id)";',
|
||||
'-torque-frame-count: 760;',
|
||||
'-torque-animation-duration: 15;',
|
||||
'-torque-resolution: 2',
|
||||
'}',
|
||||
'#layer {',
|
||||
' marker-width: 3;',
|
||||
' marker-fill-opacity: 0.8;',
|
||||
' marker-fill: #FEE391; ',
|
||||
' marker-file: url(http://localhost:8081/gal.svg); ',
|
||||
' comp-op: "lighten";',
|
||||
' [value > 2] { marker-file: url(http://upload.wikimedia.org/wikipedia/commons/4/43/Flag_of_the_Galactic_Empire.svg); }',
|
||||
' [value > 3] { marker-file: url(http://upload.wikimedia.org/wikipedia/commons/c/c9/Flag_of_Syldavia.svg); }',
|
||||
' [frame-offset = 1] { marker-width: 10; marker-fill-opacity: 0.05;}',
|
||||
' [frame-offset = 2] { marker-width: 15; marker-fill-opacity: 0.02;}',
|
||||
'}'
|
||||
].join('\n');
|
||||
var shader = (new carto.RendererJS({ debug: true })).render(css);
|
||||
var markerURLs = shader.getImageURLs();
|
||||
var against = ["http://localhost:8081/gal.svg", "http://upload.wikimedia.org/wikipedia/commons/4/43/Flag_of_the_Galactic_Empire.svg", "http://upload.wikimedia.org/wikipedia/commons/c/c9/Flag_of_Syldavia.svg"];
|
||||
for(var i = 0; i<against.length; i++){
|
||||
assert(against[i] == markerURLs[i])
|
||||
}
|
||||
})
|
||||
|
||||
it ("should return variable for styles that change", function() {
|
||||
var style = '#test { marker-width: [prop]; }';
|
||||
var shader = (new carto.RendererJS({ debug: true })).render(style);
|
||||
|
Loading…
Reference in New Issue
Block a user