Merge pull request #1348 from tschaub/beforechange

Add `ol.ObjectEvent` for changes to `ol.Object` properties.  Previously, `ol.Object` dispatched instances of `goog.events.Event` with type `change`.  Now `ol.ObjectEvent` instances will be dispatched on property changes.  The events include a `getKey` method to get the name of the property being changed.  The `beforepropertychange` type event is fired before a property value changes, and the `propertychange` type event fires after the property value changes.
This commit is contained in:
Tim Schaub
2013-12-13 07:28:36 -08:00
9 changed files with 334 additions and 34 deletions

View File

@@ -39,6 +39,7 @@ goog.require('ol.MapBrowserEventHandler');
goog.require('ol.MapEvent');
goog.require('ol.MapEventType');
goog.require('ol.Object');
goog.require('ol.ObjectEvent');
goog.require('ol.ObjectEventType');
goog.require('ol.Pixel');
goog.require('ol.PostRenderFunction');
@@ -208,9 +209,9 @@ ol.Map = function(options) {
/**
* @private
* @type {goog.events.Key}
* @type {Array.<goog.events.Key>}
*/
this.layerGroupPropertyListenerKey_ = null;
this.layerGroupPropertyListenerKeys_ = null;
/**
* @private
@@ -888,7 +889,7 @@ ol.Map.prototype.handleViewChanged_ = function() {
var view = this.getView();
if (goog.isDefAndNotNull(view)) {
this.viewPropertyListenerKey_ = goog.events.listen(
view, ol.ObjectEventType.CHANGE,
view, ol.ObjectEventType.PROPERTYCHANGE,
this.handleViewPropertyChanged_, false, this);
}
this.render();
@@ -899,7 +900,18 @@ ol.Map.prototype.handleViewChanged_ = function() {
* @param {goog.events.Event} event Event.
* @private
*/
ol.Map.prototype.handleLayerGroupMemberChanged_ = function(event) {
goog.asserts.assertInstanceof(event, goog.events.Event);
this.render();
};
/**
* @param {ol.ObjectEvent} event Event.
* @private
*/
ol.Map.prototype.handleLayerGroupPropertyChanged_ = function(event) {
goog.asserts.assertInstanceof(event, ol.ObjectEvent);
this.render();
};
@@ -908,15 +920,23 @@ ol.Map.prototype.handleLayerGroupPropertyChanged_ = function(event) {
* @private
*/
ol.Map.prototype.handleLayerGroupChanged_ = function() {
if (!goog.isNull(this.layerGroupPropertyListenerKey_)) {
goog.events.unlistenByKey(this.layerGroupPropertyListenerKey_);
this.layerGroupPropertyListenerKey_ = null;
if (!goog.isNull(this.layerGroupPropertyListenerKeys_)) {
var length = this.layerGroupPropertyListenerKeys_.length;
for (var i = 0; i < length; ++i) {
goog.events.unlistenByKey(this.layerGroupPropertyListenerKeys_[i]);
}
this.layerGroupPropertyListenerKeys_ = null;
}
var layerGroup = this.getLayerGroup();
if (goog.isDefAndNotNull(layerGroup)) {
this.layerGroupPropertyListenerKey_ = goog.events.listen(
layerGroup, ol.ObjectEventType.CHANGE,
this.handleLayerGroupPropertyChanged_, false, this);
this.layerGroupPropertyListenerKeys_ = [
goog.events.listen(
layerGroup, ol.ObjectEventType.PROPERTYCHANGE,
this.handleLayerGroupPropertyChanged_, false, this),
goog.events.listen(
layerGroup, goog.events.EventType.CHANGE,
this.handleLayerGroupMemberChanged_, false, this)
];
}
this.render();
};