Control.js
3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt
* for the full text of the license. */
/**
* @class
*/
OpenLayers.Control = OpenLayers.Class.create();
OpenLayers.Control.TYPE_BUTTON = 1;
OpenLayers.Control.TYPE_TOGGLE = 2;
OpenLayers.Control.TYPE_TOOL = 3;
OpenLayers.Control.prototype = {
/** @type String */
id: null,
/** this gets set in the addControl() function in OpenLayers.Map
* @type OpenLayers.Map */
map: null,
/** @type DOMElement */
div: null,
/**
* Controls can have a 'type'. The type determines the type of interactions
* which are possible with them when they are placed into a toolbar.
* @type OpenLayers.Control.TYPES
*/
type: null,
/** This property is used for CSS related to the drawing of the Control.
* @type string
*/
displayClass: "",
/**
* @type boolean
*/
active: null,
/**
* @type OpenLayers.Handler
*/
handler: null,
/**
* @constructor
*
* @param {Object} options
*/
initialize: function (options) {
// We do this before the extend so that instances can override
// className in options.
this.displayClass = this.CLASS_NAME.replace("OpenLayers.", "ol").replace(".","");
OpenLayers.Util.extend(this, options);
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
},
/**
*
*/
destroy: function () {
// eliminate circular references
if (this.handler) {
this.handler.destroy();
}
this.map = null;
},
/** Set the map property for the control. This is done through an accessor
* so that subclasses can override this and take special action once
* they have their map variable set.
*
* @param {OpenLayers.Map} map
*/
setMap: function(map) {
this.map = map;
if (this.handler) {
this.handler.setMap(map);
}
},
/**
* @param {OpenLayers.Pixel} px
*
* @returns A reference to the DIV DOMElement containing the control
* @type DOMElement
*/
draw: function (px) {
if (this.div == null) {
this.div = OpenLayers.Util.createDiv();
this.div.id = this.id;
this.div.className = this.displayClass;
}
if (px != null) {
this.position = px.clone();
}
this.moveTo(this.position);
return this.div;
},
/**
* @param {OpenLayers.Pixel} px
*/
moveTo: function (px) {
if ((px != null) && (this.div != null)) {
this.div.style.left = px.x + "px";
this.div.style.top = px.y + "px";
}
},
/**
* @type boolean
*/
activate: function () {
if (this.active) {
return false;
}
if (this.handler) {
this.handler.activate();
}
this.active = true;
return true;
},
/**
* @type boolean
*/
deactivate: function () {
if (this.active) {
if (this.handler) {
this.handler.deactivate();
}
this.active = false;
return true;
}
return false;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Control"
};