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:
Bruno Binet
2013-08-07 15:55:54 +02:00
parent a13d4bdded
commit 46ea218d0f
4 changed files with 34 additions and 140 deletions

View File

@@ -1,19 +1,13 @@
goog.provide('ol.renderer.Layer');
goog.require('goog.Disposable');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.Attribution');
goog.require('ol.Coordinate');
goog.require('ol.FrameState');
goog.require('ol.Image');
goog.require('ol.ImageState');
goog.require('ol.Object');
goog.require('ol.Tile');
goog.require('ol.TileRange');
goog.require('ol.TileState');
goog.require('ol.layer.Layer');
goog.require('ol.layer.LayerProperty');
goog.require('ol.layer.LayerState');
goog.require('ol.source.Source');
goog.require('ol.source.TileSource');
@@ -42,32 +36,6 @@ ol.renderer.Layer = function(mapRenderer, layer) {
*/
this.layer_ = layer;
goog.events.listen(this.layer_,
ol.Object.getChangeEventType(ol.layer.LayerProperty.BRIGHTNESS),
this.handleLayerBrightnessChange, false, this);
goog.events.listen(this.layer_,
ol.Object.getChangeEventType(ol.layer.LayerProperty.CONTRAST),
this.handleLayerContrastChange, false, this);
goog.events.listen(this.layer_,
ol.Object.getChangeEventType(ol.layer.LayerProperty.HUE),
this.handleLayerHueChange, false, this);
goog.events.listen(this.layer_, goog.events.EventType.LOAD,
this.handleLayerLoad, false, this);
goog.events.listen(this.layer_,
ol.Object.getChangeEventType(ol.layer.LayerProperty.OPACITY),
this.handleLayerOpacityChange, false, this);
goog.events.listen(this.layer_,
ol.Object.getChangeEventType(ol.layer.LayerProperty.SATURATION),
this.handleLayerSaturationChange, false, this);
goog.events.listen(this.layer_,
ol.Object.getChangeEventType(ol.layer.LayerProperty.VISIBLE),
this.handleLayerVisibleChange, false, this);
};
goog.inherits(ol.renderer.Layer, goog.Disposable);
@@ -120,24 +88,6 @@ ol.renderer.Layer.prototype.getMapRenderer = function() {
};
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerBrightnessChange = goog.nullFunction;
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerContrastChange = goog.nullFunction;
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerHueChange = goog.nullFunction;
/**
* Handle changes in image state.
* @param {goog.events.Event} event Image change event.
@@ -151,39 +101,6 @@ ol.renderer.Layer.prototype.handleImageChange = function(event) {
};
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerLoad = function() {
this.renderIfReadyAndVisible();
};
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerOpacityChange = function() {
this.renderIfReadyAndVisible();
};
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerSaturationChange = goog.nullFunction;
/**
* @protected
*/
ol.renderer.Layer.prototype.handleLayerVisibleChange = function() {
var layer = this.getLayer();
if (layer.isReady()) {
this.getMap().render();
}
};
/**
* @param {ol.FrameState} frameState Frame state.
* @param {ol.layer.LayerState} layerState Layer state.