|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
var carto = require('./index');
|
|
|
|
|
var tree = require('./tree');
|
|
|
|
|
|
|
|
|
@ -29,7 +29,7 @@ carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
var output = [];
|
|
|
|
|
|
|
|
|
|
// Transform stylesheets into rulesets.
|
|
|
|
|
var rulesets = _(m.Stylesheet)
|
|
|
|
|
var rulesets = _(m.Stylesheet).chain()
|
|
|
|
|
.map(function(s) {
|
|
|
|
|
if (typeof s == 'string') {
|
|
|
|
|
throw new Error("Stylesheet object is expected not a string: '" + s + "'");
|
|
|
|
@ -50,31 +50,36 @@ carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
|
|
|
|
|
// Iterate through layers and create styles custom-built
|
|
|
|
|
// for each of them, and apply those styles to the layers.
|
|
|
|
|
m.Layer.forEach(function(l) {
|
|
|
|
|
var styles, l, classIndex, rules, sorted, matching;
|
|
|
|
|
for (var i = 0; i < m.Layer.length; i++) {
|
|
|
|
|
l = m.Layer[i];
|
|
|
|
|
styles = [];
|
|
|
|
|
classIndex = {};
|
|
|
|
|
|
|
|
|
|
if (env.benchmark) console.warn('processing layer: ' + l.id);
|
|
|
|
|
l.styles = [];
|
|
|
|
|
// Classes are given as space-separated alphanumeric strings.
|
|
|
|
|
var classes = (l['class'] || '').split(/\s+/g);
|
|
|
|
|
var matching = rulesets.filter(function(definition) {
|
|
|
|
|
return definition.appliesTo(l.name, classes);
|
|
|
|
|
for (var j = 0; j < classes.length; j++) {
|
|
|
|
|
classIndex[classes[j]] = true;
|
|
|
|
|
}
|
|
|
|
|
matching = rulesets.filter(function(definition) {
|
|
|
|
|
return definition.appliesTo(l.name, classIndex);
|
|
|
|
|
});
|
|
|
|
|
var rules = inheritRules(matching, env);
|
|
|
|
|
var sorted = sortStyles(rules, env);
|
|
|
|
|
rules = inheritRules(matching, env);
|
|
|
|
|
sorted = sortStyles(rules, env);
|
|
|
|
|
|
|
|
|
|
_(sorted).each(function(rule) {
|
|
|
|
|
var style = new tree.Style(l.name, rule.attachment, rule);
|
|
|
|
|
if (style) {
|
|
|
|
|
l.styles.push(style.name);
|
|
|
|
|
for (var k = 0, rule, style_name; k < sorted.length; k++) {
|
|
|
|
|
rule = sorted[k];
|
|
|
|
|
style_name = l.name + (rule.attachment !== '__default__' ? '-' + rule.attachment : '');
|
|
|
|
|
styles.push(style_name);
|
|
|
|
|
|
|
|
|
|
var xml = style.toXML(env);
|
|
|
|
|
// env.effects can be modified by this call
|
|
|
|
|
output.push(xml);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (l.styles.length) {
|
|
|
|
|
output.push((new carto.tree.Layer(l)).toXML());
|
|
|
|
|
// env.effects can be modified by this call
|
|
|
|
|
output.push(tree.Style.toXML(style_name, rule.attachment, rule, env));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (styles.length) {
|
|
|
|
|
output.push(carto.tree.Layer.toXML(l, styles));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output.unshift(env.effects.map(function(e) {
|
|
|
|
|
return e.toXML(env);
|
|
|
|
|