Trigger CHANGE event only when required

For example only when layer is both ready and visible.
This commit is contained in:
Bruno Binet
2013-08-12 11:51:42 +02:00
parent 8b435059f7
commit 88da6da3a7
2 changed files with 35 additions and 2 deletions

View File

@@ -67,11 +67,14 @@ ol.layer.LayerBase = function(options) {
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.events.listen(this,
ol.Object.getChangeEventType(ol.layer.LayerProperty.VISIBLE),
this.handleLayerVisibleChange, false, this);
};
goog.inherits(ol.layer.LayerBase, ol.Object);
@@ -204,7 +207,19 @@ goog.exportProperty(
* @protected
*/
ol.layer.LayerBase.prototype.handleLayerChange = function() {
this.dispatchChangeEvent();
if (this.getVisible() && this.isReady()) {
this.dispatchChangeEvent();
}
};
/**
* @protected
*/
ol.layer.LayerBase.prototype.handleLayerVisibleChange = function() {
if (this.isReady()) {
this.dispatchChangeEvent();
}
};

View File

@@ -66,6 +66,24 @@ ol.layer.LayerGroup = function(opt_options) {
goog.inherits(ol.layer.LayerGroup, ol.layer.LayerBase);
/**
* @inheritDoc
*/
ol.layer.LayerGroup.prototype.handleLayerChange = function() {
if (this.getVisible()) {
this.dispatchChangeEvent();
}
};
/**
* @inheritDoc
*/
ol.layer.LayerGroup.prototype.handleLayerVisibleChange = function() {
this.dispatchChangeEvent();
};
/**
* @param {goog.events.Event} event Event.
* @private