/
control.js
82 lines (64 loc) · 1.52 KB
/
control.js
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
goog.provide('ol.control.Control');
goog.provide('ol.control.ControlOptions');
goog.require('goog.Disposable');
/**
* @typedef {{element: (Element|undefined),
* map: (ol.Map|undefined),
* target: (Element|undefined)}}
*/
ol.control.ControlOptions;
/**
* @constructor
* @extends {goog.Disposable}
* @param {ol.control.ControlOptions} controlOptions Control options.
*/
ol.control.Control = function(controlOptions) {
goog.base(this);
/**
* @protected
* @type {Element}
*/
this.element = goog.isDef(controlOptions.element) ?
controlOptions.element : null;
/**
* @private
* @type {Element|undefined}
*/
this.target_ = controlOptions.target;
/**
* @private
* @type {ol.Map}
*/
this.map_ = null;
if (goog.isDef(controlOptions.map)) {
this.setMap(controlOptions.map);
}
};
goog.inherits(ol.control.Control, goog.Disposable);
/**
* @inheritDoc
*/
ol.control.Control.prototype.disposeInternal = function() {
goog.dom.removeNode(this.element);
goog.base(this, 'disposeInternal');
};
/**
* @return {ol.Map} Map.
*/
ol.control.Control.prototype.getMap = function() {
return this.map_;
};
/**
* @param {ol.Map} map Map.
*/
ol.control.Control.prototype.setMap = function(map) {
if (!goog.isNull(this.map_)) {
goog.dom.removeNode(this.element);
}
this.map_ = map;
if (!goog.isNull(this.map_)) {
var target = goog.isDef(this.target_) ?
this.target_ : map.getOverlayContainer();
goog.dom.appendChild(target, this.element);
}
};