Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #277 from mapbox/fix-attachment-order-breakage
Browse files Browse the repository at this point in the history
fix #247
  • Loading branch information
tmcw committed Jun 1, 2013
2 parents cfc90da + 4203578 commit 4cc262b
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/carto/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ carto.Renderer.prototype.renderMSS = function render(data, callback) {
var bench_name = '\tStyle "'+style_name+'" (#'+k+') toXML';
if (env.benchmark) console.time(bench_name);
// env.effects can be modified by this call
output.push(carto.tree.StyleXML(style_name, rule.attachment, rule.rules, env));
output.push(carto.tree.StyleXML(style_name, rule.attachment, rule, env));
if (env.benchmark) console.timeEnd(bench_name);
}
if (env.benchmark) console.timeEnd('Total Style generation');
Expand Down Expand Up @@ -130,7 +130,7 @@ carto.Renderer.prototype.render = function render(m, callback) {
style_name = l.name + (rule.attachment !== '__default__' ? '-' + rule.attachment : '');

// env.effects can be modified by this call
var styleXML = carto.tree.StyleXML(style_name, rule.attachment, rule.rules, env);
var styleXML = carto.tree.StyleXML(style_name, rule.attachment, rule, env);

if (styleXML) {
output.push(styleXML);
Expand Down Expand Up @@ -276,38 +276,41 @@ function inheritDefinitions(definitions, env) {
var inheritTime = +new Date();
// definitions are ordered by specificity,
// high (index 0) to low
var byFilter = {}, result = {}, current, previous, attachment;
var byAttachment = {}, byFilter = {};
var result = [];
var current, previous, attachment;

definitions.forEach(function(d) {
d.filters.ev(env);
if (!result[d.attachment]) {
result[d.attachment] = { rules: [], attachment: d.attachment };
byFilter[d.attachment] = { };
}
});

for (var i = 0; i < definitions.length; i++) {

attachment = definitions[i].attachment;
current = [definitions[i]];

if (!byAttachment[attachment]) {
byAttachment[attachment] = [];
byAttachment[attachment].attachment = attachment;
byFilter[attachment] = {};
result.push(byAttachment[attachment]);
}
// Iterate over all subsequent rules.
for (var j = i + 1; j < definitions.length; j++) {
if (definitions[j].attachment === attachment) {
// Only inherit rules from the same attachment.
current = addRules(current, definitions[j], byFilter[attachment], env);
current = addRules(current, definitions[j], byFilter, env);
}
}

for (var k = 0; k < current.length; k++) {
byFilter[attachment][current[k].filters] = current[k];
result[attachment].rules.push(current[k]);
byAttachment[attachment].push(current[k]);
}
}

if (env.benchmark) console.warn('Inheritance time: ' + ((new Date() - inheritTime)) + 'ms');

return _.values(result);
return result;

}

// Sort styles by the minimum index of their rules.
Expand Down

0 comments on commit 4cc262b

Please sign in to comment.