From de319b9ae864542dd1355a854373314b5ed000f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 23 Sep 2014 08:52:28 +0200 Subject: [PATCH 1/2] Add ol.interaction.Interaction#setActive and #getActive --- src/ol/interaction/interaction.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ol/interaction/interaction.js b/src/ol/interaction/interaction.js index 11acb63db1..9b91640c2f 100644 --- a/src/ol/interaction/interaction.js +++ b/src/ol/interaction/interaction.js @@ -34,10 +34,25 @@ ol.interaction.Interaction = function() { */ this.map_ = null; + /** + * @private + * @type {boolean} + */ + this.active_ = true; + }; goog.inherits(ol.interaction.Interaction, ol.Observable); +/** + * @return {boolean} `true` if the interaction is active, `false` otherwise. + * @api + */ +ol.interaction.Interaction.prototype.getActive = function() { + return this.active_; +}; + + /** * Get the map associated with this interaction. * @return {ol.Map} Map. @@ -57,6 +72,16 @@ ol.interaction.Interaction.prototype.handleMapBrowserEvent = goog.abstractMethod; +/** + * Activate or deactivate the interaction. + * @param {boolean} active Active. + * @api + */ +ol.interaction.Interaction.prototype.setActive = function(active) { + this.active_ = active; +}; + + /** * Remove the interaction from its current map and attach it to the new map. * Subclasses may set up event handlers to get notified about changes to From 2248d2e012e287ed81c0fc756ab542c6bdc686c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 23 Sep 2014 08:53:00 +0200 Subject: [PATCH 2/2] Skip inactive interactions --- src/ol/map.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ol/map.js b/src/ol/map.js index 3bb5c49755..080d7d39c3 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -858,6 +858,9 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) { if (this.dispatchEvent(mapBrowserEvent) !== false) { for (i = interactionsArray.length - 1; i >= 0; i--) { var interaction = interactionsArray[i]; + if (!interaction.getActive()) { + continue; + } var cont = interaction.handleMapBrowserEvent(mapBrowserEvent); if (!cont) { break;