Merge pull request #3139 from elemoine/control-setmap

Add ol.control.Control#setTarget
This commit is contained in:
Éric Lemoine
2015-01-16 11:16:30 +01:00

View File

@@ -51,8 +51,7 @@ ol.control.Control = function(options) {
* @private
* @type {Element}
*/
this.target_ = goog.isDef(options.target) ?
goog.dom.getElement(options.target) : null;
this.target_ = null;
/**
* @private
@@ -71,6 +70,10 @@ ol.control.Control = function(options) {
*/
this.render = goog.isDef(options.render) ? options.render : goog.nullFunction;
if (goog.isDef(options.target)) {
this.setTarget(options.target);
}
};
goog.inherits(ol.control.Control, ol.Object);
@@ -121,3 +124,17 @@ ol.control.Control.prototype.setMap = function(map) {
map.render();
}
};
/**
* This function is used to set a target element for the control. It has no
* effect if it is called after the control has been added to the map (i.e.
* after `setMap` is called on the control). If no `target` is set in the
* options passed to the control constructor and if `setTarget` is not called
* then the control is added to the map's overlay container.
* @param {Element|string} target Target.
* @api
*/
ol.control.Control.prototype.setTarget = function(target) {
this.target_ = goog.dom.getElement(target);
};