diff --git a/src/ol/control/control.js b/src/ol/control/control.js index b911651198..c225082dee 100644 --- a/src/ol/control/control.js +++ b/src/ol/control/control.js @@ -48,10 +48,10 @@ ol.control.Control = function(controlOptions) { this.map_ = null; /** - * @private - * @type {?number} + * @protected + * @type {!Array.} */ - this.postrenderListenKey_ = null; + this.listenerKeys = []; if (goog.isDef(controlOptions.map)) { this.setMap(controlOptions.map); @@ -95,9 +95,9 @@ ol.control.Control.prototype.setMap = function(map) { if (!goog.isNull(this.map_)) { goog.dom.removeNode(this.element); } - if (!goog.isNull(this.postrenderListenKey_)) { - goog.events.unlistenByKey(this.postrenderListenKey_); - this.postrenderListenKey_ = null; + if (!goog.array.isEmpty(this.listenerKeys)) { + goog.array.forEach(this.listenerKeys, goog.events.unlistenByKey); + this.listenerKeys.length = 0; } this.map_ = map; if (!goog.isNull(this.map_)) { @@ -105,8 +105,8 @@ ol.control.Control.prototype.setMap = function(map) { this.target_ : map.getOverlayContainer(); goog.dom.appendChild(target, this.element); if (this.handleMapPostrender !== goog.nullFunction) { - this.postrenderListenKey_ = goog.events.listen(map, - ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this); + this.listenerKeys.push(goog.events.listen(map, + ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this)); } } }; diff --git a/src/ol/control/dragboxcontrol.js b/src/ol/control/dragboxcontrol.js index 5fcbc51596..5a70378ef5 100644 --- a/src/ol/control/dragboxcontrol.js +++ b/src/ol/control/dragboxcontrol.js @@ -42,12 +42,6 @@ ol.control.DragBox = function(dragBoxOptions) { */ this.startCoordinate_ = dragBoxOptions.startCoordinate; - /** - * @private - * @type {?number} - */ - this.dragListenKey_ = null; - goog.base(this, { element: element, map: dragBoxOptions.map @@ -61,19 +55,15 @@ goog.inherits(ol.control.DragBox, ol.control.Control); * @inheritDoc */ ol.control.DragBox.prototype.setMap = function(map) { - if (!goog.isNull(this.dragListenKey_)) { - goog.events.unlistenByKey(this.dragListenKey_); - this.dragListenKey_ = null; - } + goog.base(this, 'setMap', map); if (!goog.isNull(map)) { this.startPixel_ = map.getPixelFromCoordinate(this.startCoordinate_); goog.asserts.assert(goog.isDef(this.startPixel_)); goog.style.setPosition(this.element, this.startPixel_); goog.style.setBorderBoxSize(this.element, new ol.Size(0, 0)); - this.dragListenKey_ = goog.events.listen( - map, ol.MapBrowserEvent.EventType.DRAG, this.updateBox_, false, this); + this.listenerKeys.push(goog.events.listen( + map, ol.MapBrowserEvent.EventType.DRAG, this.updateBox_, false, this)); } - goog.base(this, 'setMap', map); }; diff --git a/src/ol/control/mousepositioncontrol.js b/src/ol/control/mousepositioncontrol.js index cb649f6dd1..57f705e16a 100644 --- a/src/ol/control/mousepositioncontrol.js +++ b/src/ol/control/mousepositioncontrol.js @@ -85,12 +85,6 @@ ol.control.MousePosition = function(opt_options) { */ this.lastMouseMovePixel_ = null; - /** - * @private - * @type {Array.} - */ - this.listenerKeys_ = null; - }; goog.inherits(ol.control.MousePosition, ol.control.Control); @@ -137,19 +131,15 @@ ol.control.MousePosition.prototype.handleMouseOut = function(browserEvent) { * @inheritDoc */ ol.control.MousePosition.prototype.setMap = function(map) { - if (!goog.isNull(this.listenerKeys_)) { - goog.array.forEach(this.listenerKeys_, goog.events.unlistenByKey); - this.listenerKeys_ = null; - } goog.base(this, 'setMap', map); if (!goog.isNull(map)) { var viewport = map.getViewport(); - this.listenerKeys_ = [ - goog.events.listen(viewport, goog.events.EventType.MOUSEMOVE, - this.handleMouseMove, false, this), - goog.events.listen(viewport, goog.events.EventType.MOUSEOUT, - this.handleMouseOut, false, this) - ]; + this.listenerKeys.push( + goog.events.listen(viewport, goog.events.EventType.MOUSEMOVE, + this.handleMouseMove, false, this), + goog.events.listen(viewport, goog.events.EventType.MOUSEOUT, + this.handleMouseOut, false, this) + ); } };