clone rules that are already attached to a definition

This commit is contained in:
Konstantin Käfer 2011-02-02 17:01:10 -05:00
parent 50b9e86037
commit ed03f791fd
2 changed files with 12 additions and 0 deletions

View File

@ -7,6 +7,7 @@ tree.Definition = function Definition(selector, rules) {
this.rules = rules; this.rules = rules;
this.ruleIndex = []; this.ruleIndex = [];
for (var i = 0; i < this.rules.length; i++) { for (var i = 0; i < this.rules.length; i++) {
if ('zoom' in this.rules[i]) this.rules[i] = this.rules[i].clone();
this.rules[i].zoom = selector.zoom; this.rules[i].zoom = selector.zoom;
this.ruleIndex.push(this.rules[i].updateID()); this.ruleIndex.push(this.rules[i].updateID());
} }

View File

@ -9,6 +9,17 @@ tree.Rule = function Rule(name, value, index, filename) {
this.variable = (name.charAt(0) === '@'); this.variable = (name.charAt(0) === '@');
}; };
tree.Rule.prototype.clone = function() {
var clone = Object.create(tree.Rule.prototype);
clone.name = this.name
clone.value = this.value;
clone.index = this.index;
clone.symbolizer = this.symbolizer;
clone.filename = this.filename;
clone.variable = this.variable;
return clone;
};
tree.Rule.prototype.updateID = function() { tree.Rule.prototype.updateID = function() {
return this.id = this.zoom + '#' + this.name; return this.id = this.zoom + '#' + this.name;
}; };