evaluation of else filter in SLD. r=tschaub (closes #1317)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5978 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2008-02-03 17:48:19 +00:00
parent a664b6b390
commit 1faf641806
5 changed files with 96 additions and 28 deletions
+8 -1
View File
@@ -207,9 +207,16 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
if (filter && filter.length > 0) {
var rule = this.parseFilter(filter[0]);
} else {
// rule applies to all features (no filter or ElseFilter)
// start with an empty rule that always applies
var rule = new OpenLayers.Rule();
// and check if the rule is an ElseFilter
var elseFilter = this.getElementsByTagNameNS(xmlNode, this.ogcns,
"ElseFilter");
if (elseFilter && elseFilter.length > 0) {
rule.elseFilter = true;
}
}
rule.name = name;
// SCALE DENOMINATORS
+10
View File
@@ -20,6 +20,16 @@ OpenLayers.Rule = OpenLayers.Class({
*/
name: 'default',
/**
* Property: elseFilter
* {Boolean} Determines whether this rule is only to be applied only if
* no other rules match (ElseFilter according to the SLD specification).
* Default is false. For instances of OpenLayers.Rule, if elseFilter is
* false, the rule will always apply. For subclasses, the else property is
* ignored.
*/
elseFilter: false,
/**
* Property: symbolizer
* {Object} Hash of styles for this rule. Contains hashes of feature
+47 -20
View File
@@ -111,12 +111,13 @@ OpenLayers.Style = OpenLayers.Class({
var style = OpenLayers.Util.extend({}, this.defaultStyle);
var rules = this.rules;
var draw = rules.length == 0 ? true : false;
var rule;
for (var i=0; i<rules.length; i++) {
var elseRules = [];
var appliedRules = false;
for(var i=0; i<rules.length; i++) {
rule = rules[i];
// does the rule apply?
// does the rule apply?
var applies = rule.evaluate(feature);
if (rule.minScaleDenominator || rule.maxScaleDenominator) {
@@ -132,33 +133,59 @@ OpenLayers.Style = OpenLayers.Class({
applies = scale < OpenLayers.Style.createLiteral(
rule.maxScaleDenominator, feature);
}
if (draw && rule.CLASS_NAME == "OpenLayers.Rule") {
// apply plain rules only if no other applied (ElseFilter)
applies = false;
if(applies) {
if(rule instanceof OpenLayers.Rule && rule.elseFilter) {
elseRules.push(rule);
} else {
appliedRules = true;
this.applySymbolizer(rule, style, feature);
}
}
if (applies) {
draw = true;
// determine which symbolizer (Point, Line, Polygon) to use
var symbolizerPrefix = feature.geometry ?
this.getSymbolizerPrefix(feature.geometry) :
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
// merge the style with the current style
var symbolizer = this.rules[i].symbolizer[symbolizerPrefix];
OpenLayers.Util.extend(style, symbolizer);
}
// if no other rules apply, apply the rules with else filters
if(appliedRules == false && elseRules.length > 0) {
appliedRules = true;
for(var i=0; i<elseRules.length; i++) {
this.applySymbolizer(elseRules[i], style, feature);
}
}
// calculate literals for all styles in the propertyStyles cache
this.createLiterals(style, feature);
style.display = draw ? "" : "none";
// don't display if there were rules but none applied
if(rules.length > 0 && appliedRules == false) {
style.display = "none";
} else {
style.display = "";
}
return style;
},
/**
* Method: applySymbolizer
*
* Parameters:
* rule - {OpenLayers.Rule}
* style - {Object}
* feature - {<OpenLayer.Feature.Vector>}
*
* Returns:
* {Object} A style with new symbolizer applied.
*/
applySymbolizer: function(rule, style, feature) {
var symbolizerPrefix = feature.geometry ?
this.getSymbolizerPrefix(feature.geometry) :
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
// merge the style with the current style
var symbolizer = rule.symbolizer[symbolizerPrefix];
return OpenLayers.Util.extend(style, symbolizer);
},
/**
* Method: createLiterals
* creates literals for all style properties that have an entry in