|
|
|
@ -12,11 +12,9 @@ tree.Definition.prototype.clone = function() {
|
|
|
|
|
return obj;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a copy of this ruleset with only
|
|
|
|
|
* rules related to a specific symbolizer, but otherwise identical
|
|
|
|
|
* selectors.
|
|
|
|
|
*/
|
|
|
|
|
// Return a copy of this ruleset with only
|
|
|
|
|
// rules related to a specific symbolizer, but otherwise identical
|
|
|
|
|
// selectors.
|
|
|
|
|
tree.Definition.prototype.filterSymbolizer = function(symbolizer) {
|
|
|
|
|
var newDefinition = this.clone();
|
|
|
|
|
newDefinition.rules = newDefinition.rules.filter(function(rule) {
|
|
|
|
@ -25,6 +23,9 @@ tree.Definition.prototype.filterSymbolizer = function(symbolizer) {
|
|
|
|
|
return newDefinition;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get a list of all of the symbolizer types
|
|
|
|
|
// that this definition will affect as a result of
|
|
|
|
|
// its rules.
|
|
|
|
|
tree.Definition.prototype.symbolizers = function() {
|
|
|
|
|
// reduce used to make the result of this
|
|
|
|
|
// an array of unique values.
|
|
|
|
@ -36,10 +37,8 @@ tree.Definition.prototype.symbolizers = function() {
|
|
|
|
|
}, []);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find a rule by name within this ruleset,
|
|
|
|
|
* returning it if possible. Otherwise not returning.
|
|
|
|
|
*/
|
|
|
|
|
// Find a rule by name within this ruleset,
|
|
|
|
|
// returning it if possible. Otherwise not returning.
|
|
|
|
|
tree.Definition.prototype.hasRule = function(name) {
|
|
|
|
|
this.rules_cache = (!this.dirty && this.rules_cache)
|
|
|
|
|
? this.rules_cache
|
|
|
|
@ -50,6 +49,9 @@ tree.Definition.prototype.hasRule = function(name) {
|
|
|
|
|
return this.rules_cache[name];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Take all of the rules from a given definition that
|
|
|
|
|
// this definition doesn't have already, and add them to this
|
|
|
|
|
// definition.
|
|
|
|
|
tree.Definition.prototype.inheritFrom = function(definition) {
|
|
|
|
|
for (var i = 0; i < definition.rules.length; i++) {
|
|
|
|
|
if (!this.hasRule(definition.rules[i].name)) {
|
|
|
|
@ -59,6 +61,9 @@ tree.Definition.prototype.inheritFrom = function(definition) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get all of the unique rules in this definition, in
|
|
|
|
|
// specificity order. Mapnik doesn't allow multiple attributes
|
|
|
|
|
// in Symbolizers.
|
|
|
|
|
tree.Definition.prototype.unique_rules = function() {
|
|
|
|
|
if (this.unique_rules_cache) return this.unique_rules_cache;
|
|
|
|
|
var rules = {},
|
|
|
|
@ -73,6 +78,7 @@ tree.Definition.prototype.unique_rules = function() {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tree.Definition.prototype.toXML = function(env) {
|
|
|
|
|
// Return a cached compilation if one is available.
|
|
|
|
|
if (this._xml) return this._xml;
|
|
|
|
|
|
|
|
|
|
var sym = this.symbolizers();
|
|
|
|
@ -86,17 +92,25 @@ tree.Definition.prototype.toXML = function(env) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sym) {
|
|
|
|
|
// Some Mapnik symbolizers, like TextSymbolizer, don't
|
|
|
|
|
// have defaults for all properties and will fail if they
|
|
|
|
|
// aren't given. Thus, at the last minute check that these
|
|
|
|
|
// are satisfied.
|
|
|
|
|
if (reqfail = tree.Reference.requiredProperties(
|
|
|
|
|
sym,
|
|
|
|
|
this.unique_rules())) {
|
|
|
|
|
env.error({
|
|
|
|
|
message: reqfail,
|
|
|
|
|
index: this.unique_rules()[0] && this.unique_rules()[0].index,
|
|
|
|
|
index: this.unique_rules()[0] && this.unique_rules()[0].filename
|
|
|
|
|
index: this.unique_rules()[0] &&
|
|
|
|
|
this.unique_rules()[0].index,
|
|
|
|
|
index: this.unique_rules()[0] &&
|
|
|
|
|
this.unique_rules()[0].filename
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Come up with a symbolizer name based on the name from
|
|
|
|
|
// Reference.
|
|
|
|
|
var symname = sym ? sym.charAt(0).toUpperCase()
|
|
|
|
|
+ sym.slice(1).replace(/\-./, function(str) {
|
|
|
|
|
return str[1].toUpperCase();
|
|
|
|
|