diff --git a/src/ol/control/control.js b/src/ol/control/control.js index f2912d0c0f..4ebab38345 100644 --- a/src/ol/control/control.js +++ b/src/ol/control/control.js @@ -30,12 +30,10 @@ ol.control.Control = function(options) { /** * @private - * @type {Element|undefined} + * @type {?Element} */ - this.target_ = goog.isDef(options.target) ? (goog.isString(options.target) ? - goog.dom.getElement(options.target) !== null ? - goog.dom.getElement(options.target) : undefined : options.target) : - undefined; + this.target_ = goog.isDef(options.target) ? + goog.dom.getElement(options.target) : null; /** * @private @@ -98,7 +96,7 @@ ol.control.Control.prototype.setMap = function(map) { } this.map_ = map; if (!goog.isNull(this.map_)) { - var target = goog.isDef(this.target_) ? + var target = !goog.isNull(this.target_) ? this.target_ : map.getOverlayContainerStopEvent(); goog.dom.appendChild(target, this.element); if (this.handleMapPostrender !== goog.nullFunction) { diff --git a/test/spec/ol/control/control.test.js b/test/spec/ol/control/control.test.js index 2b988076d2..22a555c134 100644 --- a/test/spec/ol/control/control.test.js +++ b/test/spec/ol/control/control.test.js @@ -42,7 +42,7 @@ describe('ol.control.Control\'s target', function() { }); it('ignores non-existing target id', function() { var ctrl = new ol.control.Control({target: 'doesnotexist'}); - expect(ctrl.target_).to.equal(undefined); + expect(ctrl.target_).to.equal(null); goog.dispose(ctrl); }); });