]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Strategy.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Strategy.js
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  * Class: OpenLayers.Strategy
7  * Abstract vector layer strategy class.  Not to be instantiated directly.  Use
8  *     one of the strategy subclasses instead.
9  */
10 OpenLayers.Strategy = OpenLayers.Class({
11     
12     /**
13      * Property: layer
14      * {<OpenLayers.Layer.Vector>} The layer this strategy belongs to.
15      */
16     layer: null,
17     
18     /**
19      * Property: options
20      * {Object} Any options sent to the constructor.
21      */
22     options: null,
23
24     /** 
25      * Property: active 
26      * {Boolean} The control is active.
27      */
28     active: null,
29
30     /**
31      * Property: autoActivate
32      * {Boolean} The creator of the strategy can set autoActivate to false
33      *      to fully control when the protocol is activated and deactivated.
34      *      Defaults to true.
35      */
36     autoActivate: true,
37
38     /**
39      * Property: autoDestroy
40      * {Boolean} The creator of the strategy can set autoDestroy to false
41      *      to fully control when the strategy is destroyed. Defaults to
42      *      true.
43      */
44     autoDestroy: true,
45
46     /**
47      * Constructor: OpenLayers.Strategy
48      * Abstract class for vector strategies.  Create instances of a subclass.
49      *
50      * Parameters:
51      * options - {Object} Optional object whose properties will be set on the
52      *     instance.
53      */
54     initialize: function(options) {
55         OpenLayers.Util.extend(this, options);
56         this.options = options;
57         // set the active property here, so that user cannot override it
58         this.active = false;
59     },
60     
61     /**
62      * APIMethod: destroy
63      * Clean up the strategy.
64      */
65     destroy: function() {
66         this.deactivate();
67         this.layer = null;
68         this.options = null;
69     },
70
71     /**
72      * Method: setLayer
73      * Called to set the <layer> property.
74      *
75      * Parameters:
76      * {<OpenLayers.Layer.Vector>}
77      */
78     setLayer: function(layer) {
79         this.layer = layer;
80     },
81     
82     /**
83      * Method: activate
84      * Activate the strategy.  Register any listeners, do appropriate setup.
85      *
86      * Returns:
87      * {Boolean} True if the strategy was successfully activated or false if
88      *      the strategy was already active.
89      */
90     activate: function() {
91         if (!this.active) {
92             this.active = true;
93             return true;
94         }
95         return false;
96     },
97     
98     /**
99      * Method: deactivate
100      * Deactivate the strategy.  Unregister any listeners, do appropriate
101      *     tear-down.
102      *
103      * Returns:
104      * {Boolean} True if the strategy was successfully deactivated or false if
105      *      the strategy was already inactive.
106      */
107     deactivate: function() {
108         if (this.active) {
109             this.active = false;
110             return true;
111         }
112         return false;
113     },
114    
115     CLASS_NAME: "OpenLayers.Strategy" 
116 });