1
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
2
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
3
* for the full text of the license. */
7
* @requires OpenLayers/Util.js
8
* @requires OpenLayers/Style.js
12
* Class: OpenLayers.Rule
13
* This class represents an SLD Rule, as being used for rule-based SLD styling.
15
OpenLayers.Rule = OpenLayers.Class({
19
* {String} A unique id for this session.
25
* {String} name of this rule
31
* {String} Title of this rule (set if included in SLD)
36
* Property: description
37
* {String} Description of this rule (set if abstract is included in SLD)
43
* {Object} An optional object with properties that the rule should be
44
* evaluated against. If no context is specified, feature.attributes will
51
* {<OpenLayers.Filter>} Optional filter for the rule.
56
* Property: elseFilter
57
* {Boolean} Determines whether this rule is only to be applied only if
58
* no other rules match (ElseFilter according to the SLD specification).
59
* Default is false. For instances of OpenLayers.Rule, if elseFilter is
60
* false, the rule will always apply. For subclasses, the else property is
66
* Property: symbolizer
67
* {Object} Symbolizer or hash of symbolizers for this rule. If hash of
68
* symbolizers, keys are one or more of ["Point", "Line", "Polygon"]. The
69
* latter if useful if it is required to style e.g. vertices of a line
70
* with a point symbolizer. Note, however, that this is not implemented
71
* yet in OpenLayers, but it is the way how symbolizers are defined in
77
* APIProperty: minScaleDenominator
78
* {Number} or {String} minimum scale at which to draw the feature.
79
* In the case of a String, this can be a combination of text and
80
* propertyNames in the form "literal ${propertyName}"
82
minScaleDenominator: null,
85
* APIProperty: maxScaleDenominator
86
* {Number} or {String} maximum scale at which to draw the feature.
87
* In the case of a String, this can be a combination of text and
88
* propertyNames in the form "literal ${propertyName}"
90
maxScaleDenominator: null,
93
* Constructor: OpenLayers.Rule
97
* options - {Object} An optional object with properties to set on the
101
* {<OpenLayers.Rule>}
103
initialize: function(options) {
104
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
105
this.symbolizer = {};
107
OpenLayers.Util.extend(this, options);
112
* nullify references to prevent circular references and memory leaks
114
destroy: function() {
115
for (var i in this.symbolizer) {
116
this.symbolizer[i] = null;
118
this.symbolizer = null;
122
* APIMethod: evaluate
123
* evaluates this rule for a specific feature
126
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
129
* {Boolean} true if the rule applies, false if it does not.
130
* This rule is the default rule and always returns true.
132
evaluate: function(feature) {
133
var context = this.getContext(feature);
136
if (this.minScaleDenominator || this.maxScaleDenominator) {
137
var scale = feature.layer.map.getScale();
140
// check if within minScale/maxScale bounds
141
if (this.minScaleDenominator) {
142
applies = scale >= OpenLayers.Style.createLiteral(
143
this.minScaleDenominator, context);
145
if (applies && this.maxScaleDenominator) {
146
applies = scale < OpenLayers.Style.createLiteral(
147
this.maxScaleDenominator, context);
150
// check if optional filter applies
151
if(applies && this.filter) {
152
// feature id filters get the feature, others get the context
153
if(this.filter.CLASS_NAME == "OpenLayers.Filter.FeatureId") {
154
applies = this.filter.evaluate(feature);
156
applies = this.filter.evaluate(context);
165
* Gets the context for evaluating this rule
168
* feature - {<OpenLayers.Feature>} feature to take the context from if
171
getContext: function(feature) {
172
var context = this.context;
174
context = feature.attributes || feature.data;
176
if (typeof this.context == "function") {
177
context = this.context(feature);
182
CLASS_NAME: "OpenLayers.Rule"
b'\\ No newline at end of file'