Merge pull request #2740 from elemoine/setgetactive
Make interactions activable and deactivable
This commit is contained in:
@@ -34,10 +34,25 @@ ol.interaction.Interaction = function() {
|
|||||||
*/
|
*/
|
||||||
this.map_ = null;
|
this.map_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.active_ = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.interaction.Interaction, ol.Observable);
|
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.
|
* Get the map associated with this interaction.
|
||||||
* @return {ol.Map} Map.
|
* @return {ol.Map} Map.
|
||||||
@@ -57,6 +72,16 @@ ol.interaction.Interaction.prototype.handleMapBrowserEvent =
|
|||||||
goog.abstractMethod;
|
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.
|
* 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
|
* Subclasses may set up event handlers to get notified about changes to
|
||||||
|
|||||||
@@ -858,6 +858,9 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
|
|||||||
if (this.dispatchEvent(mapBrowserEvent) !== false) {
|
if (this.dispatchEvent(mapBrowserEvent) !== false) {
|
||||||
for (i = interactionsArray.length - 1; i >= 0; i--) {
|
for (i = interactionsArray.length - 1; i >= 0; i--) {
|
||||||
var interaction = interactionsArray[i];
|
var interaction = interactionsArray[i];
|
||||||
|
if (!interaction.getActive()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var cont = interaction.handleMapBrowserEvent(mapBrowserEvent);
|
var cont = interaction.handleMapBrowserEvent(mapBrowserEvent);
|
||||||
if (!cont) {
|
if (!cont) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user