Trigger CHANGE event only when required
For example only when layer is both ready and visible.
This commit is contained in:
@@ -67,11 +67,14 @@ ol.layer.LayerBase = function(options) {
|
|||||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.HUE),
|
ol.Object.getChangeEventType(ol.layer.LayerProperty.HUE),
|
||||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.OPACITY),
|
ol.Object.getChangeEventType(ol.layer.LayerProperty.OPACITY),
|
||||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.SATURATION),
|
ol.Object.getChangeEventType(ol.layer.LayerProperty.SATURATION),
|
||||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.VISIBLE),
|
|
||||||
goog.events.EventType.LOAD
|
goog.events.EventType.LOAD
|
||||||
],
|
],
|
||||||
this.handleLayerChange, false, this);
|
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);
|
goog.inherits(ol.layer.LayerBase, ol.Object);
|
||||||
|
|
||||||
@@ -204,7 +207,19 @@ goog.exportProperty(
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.layer.LayerBase.prototype.handleLayerChange = function() {
|
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();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,24 @@ ol.layer.LayerGroup = function(opt_options) {
|
|||||||
goog.inherits(ol.layer.LayerGroup, ol.layer.LayerBase);
|
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.
|
* @param {goog.events.Event} event Event.
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
Reference in New Issue
Block a user