Project

General

Profile

Download (2.29 KB) Statistics
| Branch: | Tag: | Revision:
1
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
2
 * full list of contributors). Published under the 2-clause BSD license.
3
 * See license.txt in the OpenLayers distribution or repository for the
4
 * full text of the license. */
5

    
6

    
7
/**
8
 * @requires OpenLayers/Filter.js
9
 */
10

    
11
/**
12
 * Class: OpenLayers.Filter.FeatureId
13
 * This class represents a ogc:FeatureId Filter, as being used for rule-based SLD
14
 * styling
15
 * 
16
 * Inherits from:
17
 * - <OpenLayers.Filter>
18
 */
19
OpenLayers.Filter.FeatureId = OpenLayers.Class(OpenLayers.Filter, {
20

    
21
    /** 
22
     * APIProperty: fids
23
     * {Array(String)} Feature Ids to evaluate this rule against. 
24
     *     To be passed inside the params object.
25
     */
26
    fids: null,
27
    
28
    /** 
29
     * Property: type
30
     * {String} Type to identify this filter.
31
     */
32
    type: "FID",
33
    
34
    /** 
35
     * Constructor: OpenLayers.Filter.FeatureId
36
     * Creates an ogc:FeatureId rule.
37
     *
38
     * Parameters:
39
     * options - {Object} An optional object with properties to set on the
40
     *           rule
41
     * 
42
     * Returns:
43
     * {<OpenLayers.Filter.FeatureId>}
44
     */
45
    initialize: function(options) {
46
        this.fids = [];
47
        OpenLayers.Filter.prototype.initialize.apply(this, [options]);
48
    },
49

    
50
    /**
51
     * APIMethod: evaluate
52
     * evaluates this rule for a specific feature
53
     * 
54
     * Parameters:
55
     * feature - {<OpenLayers.Feature>} feature to apply the rule to.
56
     *           For vector features, the check is run against the fid,
57
     *           for plain features against the id.
58
     * 
59
     * Returns:
60
     * {Boolean} true if the rule applies, false if it does not
61
     */
62
    evaluate: function(feature) {
63
        for (var i=0, len=this.fids.length; i<len; i++) {
64
            var fid = feature.fid || feature.id;
65
            if (fid == this.fids[i]) {
66
                return true;
67
            }
68
        }
69
        return false;
70
    },
71
    
72
    /**
73
     * APIMethod: clone
74
     * Clones this filter.
75
     * 
76
     * Returns:
77
     * {<OpenLayers.Filter.FeatureId>} Clone of this filter.
78
     */
79
    clone: function() {
80
        var filter = new OpenLayers.Filter.FeatureId();
81
        OpenLayers.Util.extend(filter, this);
82
        filter.fids = this.fids.slice();
83
        return filter;
84
    },
85
    
86
    CLASS_NAME: "OpenLayers.Filter.FeatureId"
87
});
(2-2/5)