Make layer renderers more stupid
Layer renderers should not be responsible for listening to layer properties change and triggering a render. Layer change events are now forwarded to the map which will trigger a render.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.provide('ol.layer.LayerBase');
|
||||
goog.provide('ol.layer.LayerProperty');
|
||||
goog.provide('ol.layer.LayerState');
|
||||
@@ -59,10 +61,29 @@ ol.layer.LayerBase = function(options) {
|
||||
|
||||
this.setValues(values);
|
||||
|
||||
goog.events.listen(this, [
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.BRIGHTNESS),
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.CONTRAST),
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.HUE),
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.OPACITY),
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.SATURATION),
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.VISIBLE),
|
||||
goog.events.EventType.LOAD
|
||||
],
|
||||
this.handleLayerChange, false, this);
|
||||
|
||||
};
|
||||
goog.inherits(ol.layer.LayerBase, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.layer.LayerBase.prototype.dispatchChangeEvent = function() {
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Brightness.
|
||||
*/
|
||||
@@ -179,6 +200,14 @@ goog.exportProperty(
|
||||
ol.layer.LayerBase.prototype.getVisible);
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.layer.LayerBase.prototype.handleLayerChange = function() {
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Is ready.
|
||||
*/
|
||||
|
||||
@@ -92,11 +92,11 @@ ol.layer.LayerGroup.prototype.handleLayersChanged_ = function(event) {
|
||||
layer = layersArray[i];
|
||||
this.listenerKeys_[goog.getUid(layer).toString()] =
|
||||
goog.events.listen(layer, goog.events.EventType.CHANGE,
|
||||
this.handleLayerChange_, false, this);
|
||||
this.handleLayerChange, false, this);
|
||||
}
|
||||
}
|
||||
|
||||
this.dispatchChangeEvent_();
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
@@ -107,9 +107,9 @@ ol.layer.LayerGroup.prototype.handleLayersChanged_ = function(event) {
|
||||
ol.layer.LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) {
|
||||
var layer = /** @type {ol.layer.LayerBase} */ (collectionEvent.elem);
|
||||
this.listenerKeys_[goog.getUid(layer).toString()] = goog.events.listen(
|
||||
layer, goog.events.EventType.CHANGE, this.handleLayerChange_, false,
|
||||
layer, goog.events.EventType.CHANGE, this.handleLayerChange, false,
|
||||
this);
|
||||
this.dispatchChangeEvent_();
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
@@ -122,23 +122,7 @@ ol.layer.LayerGroup.prototype.handleLayersRemove_ = function(collectionEvent) {
|
||||
var key = goog.getUid(layer).toString();
|
||||
goog.events.unlistenByKey(this.listenerKeys_[key]);
|
||||
delete this.listenerKeys_[key];
|
||||
this.dispatchChangeEvent_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.layer.LayerGroup.prototype.handleLayerChange_ = function() {
|
||||
this.dispatchChangeEvent_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.layer.LayerGroup.prototype.dispatchChangeEvent_ = function() {
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user