~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Rule.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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. */
 
4
 
 
5
 
 
6
/**
 
7
 * @requires OpenLayers/Util.js
 
8
 * @requires OpenLayers/Style.js
 
9
 */
 
10
 
 
11
/**
 
12
 * Class: OpenLayers.Rule
 
13
 * This class represents an SLD Rule, as being used for rule-based SLD styling.
 
14
 */
 
15
OpenLayers.Rule = OpenLayers.Class({
 
16
    
 
17
    /**
 
18
     * Property: id
 
19
     * {String} A unique id for this session.
 
20
     */
 
21
    id: null,
 
22
    
 
23
    /**
 
24
     * APIProperty: name
 
25
     * {String} name of this rule
 
26
     */
 
27
    name: 'default',
 
28
    
 
29
    /**
 
30
     * Property: title
 
31
     * {String} Title of this rule (set if included in SLD)
 
32
     */
 
33
    title: null,
 
34
    
 
35
    /**
 
36
     * Property: description
 
37
     * {String} Description of this rule (set if abstract is included in SLD)
 
38
     */
 
39
    description: null,
 
40
 
 
41
    /**
 
42
     * Property: context
 
43
     * {Object} An optional object with properties that the rule should be
 
44
     * evaluated against. If no context is specified, feature.attributes will
 
45
     * be used.
 
46
     */
 
47
    context: null,
 
48
    
 
49
    /**
 
50
     * Property: filter
 
51
     * {<OpenLayers.Filter>} Optional filter for the rule.
 
52
     */
 
53
    filter: null,
 
54
 
 
55
    /**
 
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 
 
61
     * ignored.
 
62
     */
 
63
    elseFilter: false,
 
64
    
 
65
    /**
 
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
 
72
     * SLD.
 
73
     */
 
74
    symbolizer: null,
 
75
    
 
76
    /**
 
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}"
 
81
     */
 
82
    minScaleDenominator: null,
 
83
 
 
84
    /**
 
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}"
 
89
     */
 
90
    maxScaleDenominator: null,
 
91
    
 
92
    /** 
 
93
     * Constructor: OpenLayers.Rule
 
94
     * Creates a Rule.
 
95
     *
 
96
     * Parameters:
 
97
     * options - {Object} An optional object with properties to set on the
 
98
     *           rule
 
99
     * 
 
100
     * Returns:
 
101
     * {<OpenLayers.Rule>}
 
102
     */
 
103
    initialize: function(options) {
 
104
        this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
 
105
        this.symbolizer = {};
 
106
 
 
107
        OpenLayers.Util.extend(this, options);
 
108
    },
 
109
 
 
110
    /** 
 
111
     * APIMethod: destroy
 
112
     * nullify references to prevent circular references and memory leaks
 
113
     */
 
114
    destroy: function() {
 
115
        for (var i in this.symbolizer) {
 
116
            this.symbolizer[i] = null;
 
117
        }
 
118
        this.symbolizer = null;
 
119
    },
 
120
    
 
121
    /**
 
122
     * APIMethod: evaluate
 
123
     * evaluates this rule for a specific feature
 
124
     * 
 
125
     * Parameters:
 
126
     * feature - {<OpenLayers.Feature>} feature to apply the rule to.
 
127
     * 
 
128
     * Returns:
 
129
     * {Boolean} true if the rule applies, false if it does not.
 
130
     * This rule is the default rule and always returns true.
 
131
     */
 
132
    evaluate: function(feature) {
 
133
        var context = this.getContext(feature);
 
134
        var applies = true;
 
135
 
 
136
        if (this.minScaleDenominator || this.maxScaleDenominator) {
 
137
            var scale = feature.layer.map.getScale();
 
138
        }
 
139
        
 
140
        // check if within minScale/maxScale bounds
 
141
        if (this.minScaleDenominator) {
 
142
            applies = scale >= OpenLayers.Style.createLiteral(
 
143
                    this.minScaleDenominator, context);
 
144
        }
 
145
        if (applies && this.maxScaleDenominator) {
 
146
            applies = scale < OpenLayers.Style.createLiteral(
 
147
                    this.maxScaleDenominator, context);
 
148
        }
 
149
        
 
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);
 
155
            } else {
 
156
                applies = this.filter.evaluate(context);
 
157
            }
 
158
        }
 
159
 
 
160
        return applies;
 
161
    },
 
162
    
 
163
    /**
 
164
     * Method: getContext
 
165
     * Gets the context for evaluating this rule
 
166
     * 
 
167
     * Paramters:
 
168
     * feature - {<OpenLayers.Feature>} feature to take the context from if
 
169
     *           none is specified.
 
170
     */
 
171
    getContext: function(feature) {
 
172
        var context = this.context;
 
173
        if (!context) {
 
174
            context = feature.attributes || feature.data;
 
175
        }
 
176
        if (typeof this.context == "function") {
 
177
            context = this.context(feature);
 
178
        }
 
179
        return context;
 
180
    },
 
181
        
 
182
    CLASS_NAME: "OpenLayers.Rule"
 
183
});
 
 
b'\\ No newline at end of file'