Make map handle view changes

With the frameState stuff the map renderer need not listen to view changes. The map renderer receives orders from the map. These orders are renderFrame_ calls with frameState objects representing the current state.
This commit is contained in:
Éric Lemoine
2013-01-24 21:40:26 +01:00
parent 0bb31150b0
commit 71a462cd54
3 changed files with 35 additions and 58 deletions

View File

@@ -174,6 +174,12 @@ ol.Map = function(mapOptions) {
*/
this.target_ = mapOptionsInternal.target;
/**
* @private
* @type {?number}
*/
this.viewPropertyListenerKey_ = null;
/**
* @private
* @type {Element}
@@ -277,6 +283,8 @@ ol.Map = function(mapOptions) {
*/
this.tileQueue_ = new ol.TileQueue(goog.bind(this.getTilePriority, this));
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.VIEW),
this.handleViewChanged_, false, this);
this.setValues(mapOptionsInternal.values);
this.handleBrowserWindowResize();
@@ -559,6 +567,32 @@ ol.Map.prototype.handleBrowserWindowResize = function() {
};
/**
* @private
*/
ol.Map.prototype.handleViewPropertyChanged_ = function() {
this.render();
};
/**
* @private
*/
ol.Map.prototype.handleViewChanged_ = function() {
if (!goog.isNull(this.viewPropertyListenerKey_)) {
goog.events.unlistenByKey(this.viewPropertyListenerKey_);
this.viewPropertyListenerKey_ = null;
}
var view = this.getView();
if (goog.isDefAndNotNull(view)) {
this.viewPropertyListenerKey_ = goog.events.listen(
view, ol.ObjectEventType.CHANGED,
this.handleViewPropertyChanged_, false, this);
}
this.render();
};
/**
* @return {boolean} Is defined.
*/