Simpler type for ol.events.Key

Instead of having `ol.events.Key` be a listener object or an array of listener objects, it should be less error prone to have it just be a single listener object.

To avoid using too many functions with multiple return types, the `ol.events.*` functions for registering and unregistering listeners no longer accept an array of event types (and only a single key is returned when registering).

To make it convenient for users to register multiple listeners at once, the `observable.on()` method accepts an array of event types.  Internally in the library, we should use the less risky `ol.events.listen()`.
This commit is contained in:
Tim Schaub
2016-02-02 12:20:18 -07:00
committed by Andreas Hocevar
parent 78f44dcc8a
commit f10c90bdba
15 changed files with 173 additions and 108 deletions

View File

@@ -83,10 +83,12 @@ ol.layer.Heatmap = function(opt_options) {
this.setRadius(options.radius !== undefined ? options.radius : 8);
ol.events.listen(this, [
ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.BLUR),
ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.RADIUS)
], this.handleStyleChanged_, this);
ol.events.listen(this,
ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.BLUR),
this.handleStyleChanged_, this);
ol.events.listen(this,
ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.RADIUS),
this.handleStyleChanged_, this);
this.handleStyleChanged_();

View File

@@ -41,19 +41,19 @@ ol.layer.Layer = function(options) {
/**
* @private
* @type {ol.events.Key}
* @type {?ol.events.Key}
*/
this.mapPrecomposeKey_ = null;
/**
* @private
* @type {ol.events.Key}
* @type {?ol.events.Key}
*/
this.mapRenderKey_ = null;
/**
* @private
* @type {ol.events.Key}
* @type {?ol.events.Key}
*/
this.sourceChangeKey_ = null;
@@ -164,13 +164,17 @@ ol.layer.Layer.prototype.handleSourcePropertyChange_ = function() {
* @api
*/
ol.layer.Layer.prototype.setMap = function(map) {
ol.events.unlistenByKey(this.mapPrecomposeKey_);
this.mapPrecomposeKey_ = null;
if (this.mapPrecomposeKey_) {
ol.events.unlistenByKey(this.mapPrecomposeKey_);
this.mapPrecomposeKey_ = null;
}
if (!map) {
this.changed();
}
ol.events.unlistenByKey(this.mapRenderKey_);
this.mapRenderKey_ = null;
if (this.mapRenderKey_) {
ol.events.unlistenByKey(this.mapRenderKey_);
this.mapRenderKey_ = null;
}
if (map) {
this.mapPrecomposeKey_ = ol.events.listen(
map, ol.render.EventType.PRECOMPOSE, function(evt) {