Implement new control architecture
This commit is contained in:
@@ -1,38 +1,73 @@
|
||||
goog.provide('ol.control.Control');
|
||||
goog.provide('ol.control.ControlOptions');
|
||||
|
||||
goog.require('goog.Disposable');
|
||||
goog.require('ol.Map');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{element: (Element|undefined),
|
||||
* map: (ol.Map|undefined),
|
||||
* target: (Element|undefined)}}
|
||||
*/
|
||||
ol.control.ControlOptions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {goog.Disposable}
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {ol.control.ControlOptions} controlOptions Control options.
|
||||
*/
|
||||
ol.control.Control = function(map) {
|
||||
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_ = map;
|
||||
this.map_ = null;
|
||||
|
||||
if (goog.isDef(controlOptions.map)) {
|
||||
this.setMap(controlOptions.map);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Control, goog.Disposable);
|
||||
|
||||
|
||||
/**
|
||||
* @return {Element} Element.
|
||||
*/
|
||||
ol.control.Control.prototype.getElement = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @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.getViewport();
|
||||
goog.dom.appendChild(target, this.element);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user