Move postrender event listening into base class

This commit is contained in:
Tom Payne
2013-04-05 20:33:50 +02:00
parent da1e5aadd3
commit 06bcab8374
6 changed files with 31 additions and 118 deletions

View File

@@ -2,6 +2,9 @@ goog.provide('ol.control.Control');
goog.provide('ol.control.ControlOptions');
goog.require('goog.Disposable');
goog.require('goog.events');
goog.require('ol.MapEvent');
goog.require('ol.MapEventType');
/**
@@ -44,6 +47,12 @@ ol.control.Control = function(controlOptions) {
*/
this.map_ = null;
/**
* @private
* @type {?number}
*/
this.postrenderListenKey_ = null;
if (goog.isDef(controlOptions.map)) {
this.setMap(controlOptions.map);
}
@@ -69,6 +78,12 @@ ol.control.Control.prototype.getMap = function() {
};
/**
* @param {ol.MapEvent} mapEvent Map event.
*/
ol.control.Control.prototype.handleMapPostrender = goog.nullFunction;
/**
* Removes the control from its current map and attaches it to the new map.
* Subtypes might also wish set up event handlers to get notified about changes
@@ -80,10 +95,18 @@ 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;
}
this.map_ = map;
if (!goog.isNull(this.map_)) {
var target = goog.isDef(this.target_) ?
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);
}
}
};