Merge pull request #1173 from tschaub/map-interaction

Give interactions a reference to their map.
This commit is contained in:
Tim Schaub
2013-11-01 15:30:19 -07:00
4 changed files with 162 additions and 0 deletions

View File

@@ -356,6 +356,14 @@ ol.Map = function(options) {
control.setMap(this);
}, this);
this.interactions_.forEach(
/**
* @param {ol.interaction.Interaction} interaction Interaction.
*/
function(interaction) {
interaction.setMap(this);
}, this);
this.overlays_.forEach(
/**
* @param {ol.Overlay} overlay Overlay.
@@ -381,6 +389,18 @@ ol.Map.prototype.addControl = function(control) {
};
/**
* Add the given interaction to the map.
* @param {ol.interaction.Interaction} interaction Interaction to add.
*/
ol.Map.prototype.addInteraction = function(interaction) {
var interactions = this.getInteractions();
goog.asserts.assert(goog.isDef(interactions));
interactions.push(interaction);
interaction.setMap(this);
};
/**
* Adds the given layer to the top of this map.
* @param {ol.layer.Base} layer Layer.
@@ -959,6 +979,24 @@ ol.Map.prototype.removeControl = function(control) {
};
/**
* Remove the given interaction from the map.
* @param {ol.interaction.Interaction} interaction Interaction to remove.
* @return {ol.interaction.Interaction|undefined} The removed interaction (or
* undefined if the interaction was not found).
*/
ol.Map.prototype.removeInteraction = function(interaction) {
var removed;
var interactions = this.getInteractions();
goog.asserts.assert(goog.isDef(interactions));
if (goog.isDef(interactions.remove(interaction))) {
interaction.setMap(null);
removed = interaction;
}
return removed;
};
/**
* Removes the given layer from the map.
* @param {ol.layer.Base} layer Layer.