Fix byFilter regression

This commit is contained in:
Tom MacWright 2013-07-09 15:00:13 -04:00
parent afac483b35
commit bbeff81a16
3 changed files with 12 additions and 7 deletions

View File

@ -228,7 +228,8 @@ carto.Renderer.prototype.render = function render(m, callback) {
// //
// @param {Array} the current list of rules // @param {Array} the current list of rules
// @param {Object} definition a Definition object to add to the rules // @param {Object} definition a Definition object to add to the rules
// @param {Object} byFilter an object/dictionary of existing filters // @param {Object} byFilter an object/dictionary of existing filters. This is
// actually keyed `attachment->filter`
// @param {Object} env the current environment // @param {Object} env the current environment
function addRules(current, definition, byFilter, env) { function addRules(current, definition, byFilter, env) {
var newFilters = definition.filters, var newFilters = definition.filters,
@ -296,7 +297,8 @@ function inheritDefinitions(definitions, env) {
var inheritTime = +new Date(); var inheritTime = +new Date();
// definitions are ordered by specificity, // definitions are ordered by specificity,
// high (index 0) to low // high (index 0) to low
var byAttachment = {}, byFilter = {}; var byAttachment = {},
byFilter = {};
var result = []; var result = [];
var current, previous, attachment; var current, previous, attachment;
@ -307,19 +309,22 @@ function inheritDefinitions(definitions, env) {
}); });
for (var i = 0; i < definitions.length; i++) { for (var i = 0; i < definitions.length; i++) {
attachment = definitions[i].attachment; attachment = definitions[i].attachment;
current = [definitions[i]]; current = [definitions[i]];
if (!byAttachment[attachment]) { if (!byAttachment[attachment]) {
byAttachment[attachment] = []; byAttachment[attachment] = [];
byAttachment[attachment].attachment = attachment; byAttachment[attachment].attachment = attachment;
byFilter[attachment] = {}; byFilter[attachment] = {};
result.push(byAttachment[attachment]); result.push(byAttachment[attachment]);
} }
// Iterate over all subsequent rules. // Iterate over all subsequent rules.
for (var j = i + 1; j < definitions.length; j++) { for (var j = i + 1; j < definitions.length; j++) {
if (definitions[j].attachment === attachment) { if (definitions[j].attachment === attachment) {
// Only inherit rules from the same attachment. // Only inherit rules from the same attachment.
current = addRules(current, definitions[j], byFilter, env); current = addRules(current, definitions[j], byFilter[attachment], env);
} }
} }

View File

@ -2,7 +2,7 @@
[type='primary'] { [type='primary'] {
line-color: red; line-color: red;
} }
[foo='bar'] { [foo='bar'] {
line-width: 10; line-width: 10;
} }
} }
@ -14,4 +14,4 @@
[foo='bar'] { [foo='bar'] {
line-width: 10; line-width: 10;
} }
} }

View File

@ -1,4 +1,4 @@
<Style name="style" filter-mode="first" > <Style name="style" filter-mode="first">
<Rule> <Rule>
<Filter>([foo] = 'bar') and ([type] = 'primary')</Filter> <Filter>([foo] = 'bar') and ([type] = 'primary')</Filter>
<LineSymbolizer stroke-width="10" stroke="#ff0000" /> <LineSymbolizer stroke-width="10" stroke="#ff0000" />
@ -12,7 +12,7 @@
<LineSymbolizer stroke="#ff0000" /> <LineSymbolizer stroke="#ff0000" />
</Rule> </Rule>
</Style> </Style>
<Style name="style-outline" filter-mode="first" > <Style name="style-outline" filter-mode="first">
<Rule> <Rule>
<Filter>([foo] = 'bar') and ([type] = 'primary')</Filter> <Filter>([foo] = 'bar') and ([type] = 'primary')</Filter>
<LineSymbolizer stroke-width="10" stroke="#ff0000" /> <LineSymbolizer stroke-width="10" stroke="#ff0000" />