~hsiung0911/sahana-eden/test

« back to all changes in this revision

Viewing changes to static/scripts/gis/openlayers/lib/OpenLayers/Strategy/Fixed.js

  • Committer: eliao
  • Date: 2010-08-01 09:56:45 UTC
  • Revision ID: eliao@ibm-l3bw307-20100801095645-gsq9wcmjan0o0tby
This is my change

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
 
2
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 
3
 * full text of the license. */
 
4
 
 
5
/**
 
6
 * @requires OpenLayers/Strategy.js
 
7
 */
 
8
 
 
9
/**
 
10
 * Class: OpenLayers.Strategy.Fixed
 
11
 * A simple strategy that requests features once and never requests new data.
 
12
 *
 
13
 * Inherits from:
 
14
 *  - <OpenLayers.Strategy>
 
15
 */
 
16
OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
 
17
    
 
18
    /**
 
19
     * APIProperty: preload
 
20
     * {Boolean} Load data before layer made visible. Enabling this may result
 
21
     *   in considerable overhead if your application loads many data layers
 
22
     *   that are not visible by default. Default is false.
 
23
     */
 
24
    preload: false,
 
25
 
 
26
    /**
 
27
     * Constructor: OpenLayers.Strategy.Fixed
 
28
     * Create a new Fixed strategy.
 
29
     *
 
30
     * Parameters:
 
31
     * options - {Object} Optional object whose properties will be set on the
 
32
     *     instance.
 
33
     */
 
34
    initialize: function(options) {
 
35
        OpenLayers.Strategy.prototype.initialize.apply(this, [options]);
 
36
    },
 
37
 
 
38
    /**
 
39
     * APIMethod: destroy
 
40
     * Clean up the strategy.
 
41
     */
 
42
    destroy: function() {
 
43
        OpenLayers.Strategy.prototype.destroy.apply(this, arguments);
 
44
    },
 
45
 
 
46
    /**
 
47
     * Method: activate
 
48
     * Activate the strategy: load data or add listener to load when visible
 
49
     *
 
50
     * Returns:
 
51
     * {Boolean} True if the strategy was successfully activated or false if
 
52
     *      the strategy was already active.
 
53
     */
 
54
    activate: function() {
 
55
        if(OpenLayers.Strategy.prototype.activate.apply(this, arguments)) {
 
56
            this.layer.events.on({
 
57
                "refresh": this.load,
 
58
                scope: this
 
59
            });
 
60
            if(this.layer.visibility == true || this.preload) {
 
61
                this.load();
 
62
            } else {
 
63
                this.layer.events.on({
 
64
                    "visibilitychanged": this.load,
 
65
                    scope: this
 
66
                });
 
67
            }
 
68
            return true;
 
69
        }
 
70
        return false;
 
71
    },
 
72
    
 
73
    /**
 
74
     * Method: deactivate
 
75
     * Deactivate the strategy.  Undo what is done in <activate>.
 
76
     * 
 
77
     * Returns:
 
78
     * {Boolean} The strategy was successfully deactivated.
 
79
     */
 
80
    deactivate: function() {
 
81
        var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this);
 
82
        if(deactivated) {
 
83
            this.layer.events.un({
 
84
                "refresh": this.load,
 
85
                "visibilitychanged": this.load,
 
86
                scope: this
 
87
            });
 
88
        }
 
89
        return deactivated;
 
90
    },
 
91
 
 
92
    /**
 
93
     * Method: load
 
94
     * Tells protocol to load data and unhooks the visibilitychanged event
 
95
     *
 
96
     * Parameters:
 
97
     * options - {Object} options to pass to protocol read.
 
98
     */
 
99
    load: function(options) {
 
100
        this.layer.events.triggerEvent("loadstart");
 
101
        this.layer.protocol.read(OpenLayers.Util.applyDefaults({
 
102
            callback: this.merge,
 
103
            filter: this.layer.filter,
 
104
            scope: this
 
105
        }, options));
 
106
        this.layer.events.un({
 
107
            "visibilitychanged": this.load,
 
108
            scope: this
 
109
        });
 
110
    },
 
111
 
 
112
    /**
 
113
     * Method: merge
 
114
     * Add all features to the layer.
 
115
     */
 
116
    merge: function(resp) {
 
117
        this.layer.destroyFeatures();
 
118
        var features = resp.features;
 
119
        if (features && features.length > 0) {
 
120
            var remote = this.layer.projection;
 
121
            var local = this.layer.map.getProjectionObject();
 
122
            if(!local.equals(remote)) {
 
123
                var geom;
 
124
                for(var i=0, len=features.length; i<len; ++i) {
 
125
                    geom = features[i].geometry;
 
126
                    if(geom) {
 
127
                        geom.transform(remote, local);
 
128
                    }
 
129
                }
 
130
            }
 
131
            this.layer.addFeatures(features);
 
132
        }
 
133
        this.layer.events.triggerEvent("loadend");
 
134
    },
 
135
 
 
136
    CLASS_NAME: "OpenLayers.Strategy.Fixed"
 
137
});