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:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -84,15 +84,6 @@ ol.renderer.canvas.Map.prototype.handleBackgroundColorChanged = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.canvas.Map.prototype.handleViewPropertyChanged = function() {
|
||||
goog.base(this, 'handleViewPropertyChanged');
|
||||
this.getMap().render();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.events.Event} event Event.
|
||||
* @protected
|
||||
@@ -111,15 +102,6 @@ ol.renderer.canvas.Map.prototype.handleSizeChanged = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.canvas.Map.prototype.handleViewChanged = function() {
|
||||
goog.base(this, 'handleViewChanged');
|
||||
this.getMap().render();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -47,12 +47,6 @@ ol.renderer.Map = function(container, map) {
|
||||
this.layersListenerKeys_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?number}
|
||||
*/
|
||||
this.viewPropertyListenerKey_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
@@ -68,11 +62,7 @@ ol.renderer.Map = function(container, map) {
|
||||
|
||||
goog.events.listen(
|
||||
map, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
|
||||
this.handleSizeChanged, false, this),
|
||||
|
||||
goog.events.listen(
|
||||
map, ol.Object.getChangedEventType(ol.MapProperty.VIEW),
|
||||
this.handleViewChanged, false, this)
|
||||
this.handleSizeChanged, false, this)
|
||||
];
|
||||
|
||||
};
|
||||
@@ -137,9 +127,6 @@ ol.renderer.Map.prototype.disposeInternal = function() {
|
||||
goog.dispose(layerRenderer);
|
||||
});
|
||||
goog.array.forEach(this.mapListenerKeys_, goog.events.unlistenByKey);
|
||||
if (!goog.isNull(this.viewPropertyListenerKey_)) {
|
||||
goog.events.unlistenByKey(this.viewPropertyListenerKey_);
|
||||
}
|
||||
if (!goog.isNull(this.layersListenerKeys_)) {
|
||||
goog.array.forEach(this.layersListenerKeys_, goog.events.unlistenByKey);
|
||||
}
|
||||
@@ -223,14 +210,6 @@ ol.renderer.Map.prototype.handleLayersRemove = function(collectionEvent) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.Map.prototype.handleViewPropertyChanged = function() {
|
||||
this.getMap().render();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
@@ -239,24 +218,6 @@ ol.renderer.Map.prototype.handleSizeChanged = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.Map.prototype.handleViewChanged = function() {
|
||||
if (!goog.isNull(this.viewPropertyListenerKey_)) {
|
||||
goog.events.unlistenByKey(this.viewPropertyListenerKey_);
|
||||
this.viewPropertyListenerKey_ = null;
|
||||
}
|
||||
var view = this.getMap().getView();
|
||||
if (goog.isDefAndNotNull(view)) {
|
||||
this.viewPropertyListenerKey_ = goog.events.listen(
|
||||
view, ol.ObjectEventType.CHANGED,
|
||||
this.handleViewPropertyChanged, false, this);
|
||||
}
|
||||
this.getMap().render();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
* @protected
|
||||
|
||||
Reference in New Issue
Block a user