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
+3 -31
View File
@@ -10,7 +10,6 @@ goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.fx.Dragger');
goog.require('goog.style');
goog.require('ol.MapEventType');
goog.require('ol.control.Control');
goog.require('ol.css');
@@ -74,12 +73,6 @@ ol.control.ZoomSlider = function(zoomSliderOptions) {
*/
this.direction_ = ol.control.ZoomSlider.direction.VERTICAL;
/**
* @private
* @type {Array.<?number>}
*/
this.mapListenerKeys_ = null;
/**
* @private
* @type {Array.<?number>}
@@ -157,31 +150,11 @@ ol.control.ZoomSlider.DEFAULT_MAX_RESOLUTION = 156543.0339;
ol.control.ZoomSlider.prototype.setMap = function(map) {
goog.base(this, 'setMap', map);
this.currentResolution_ = map.getView().getResolution();
this.initMapEventListeners_();
this.initSlider_();
this.positionThumbForResolution_(this.currentResolution_);
};
/**
* Initializes the event listeners for map events.
*
* @private
*/
ol.control.ZoomSlider.prototype.initMapEventListeners_ = function() {
if (!goog.isNull(this.mapListenerKeys_)) {
goog.array.forEach(this.mapListenerKeys_, goog.events.unlistenByKey);
this.mapListenerKeys_ = null;
}
if (!goog.isNull(this.getMap())) {
this.mapListenerKeys_ = [
goog.events.listen(this.getMap(), ol.MapEventType.POSTRENDER,
this.handleMapPostRender_, undefined, this)
];
}
};
/**
* Initializes the slider element. This will determine and set this controls
* direction_ and also constrain the dragging of the thumb to always be within
@@ -217,11 +190,10 @@ ol.control.ZoomSlider.prototype.initSlider_ = function() {
/**
* @param {ol.MapEvent} mapEvtObj The ol.MapEvent object.
* @private
* @inheritDoc
*/
ol.control.ZoomSlider.prototype.handleMapPostRender_ = function(mapEvtObj) {
var res = mapEvtObj.frameState.view2DState.resolution;
ol.control.ZoomSlider.prototype.handleMapPostrender = function(mapEvent) {
var res = mapEvent.frameState.view2DState.resolution;
if (res !== this.currentResolution_) {
this.currentResolution_ = res;
this.positionThumbForResolution_(res);