Set control map in 'add' and 'remove' event handler

This commit is contained in:
Frederic Junod
2014-03-06 09:03:38 +01:00
parent 3dc9d296eb
commit f0f2a2d2b0

View File

@@ -382,6 +382,22 @@ ol.Map = function(options) {
control.setMap(this);
}, this);
goog.events.listen(this.controls_, ol.CollectionEventType.ADD,
/**
* @param {ol.CollectionEvent} event Collection event.
*/
function(event) {
event.element.setMap(this);
}, false, this);
goog.events.listen(this.controls_, ol.CollectionEventType.REMOVE,
/**
* @param {ol.CollectionEvent} event Collection event.
*/
function(event) {
event.element.setMap(null);
}, false, this);
this.interactions_.forEach(
/**
* @param {ol.interaction.Interaction} interaction Interaction.
@@ -445,7 +461,6 @@ ol.Map.prototype.addControl = function(control) {
var controls = this.getControls();
goog.asserts.assert(goog.isDef(controls));
controls.push(control);
control.setMap(this);
};
@@ -1058,7 +1073,6 @@ ol.Map.prototype.removeControl = function(control) {
var controls = this.getControls();
goog.asserts.assert(goog.isDef(controls));
if (goog.isDef(controls.remove(control))) {
control.setMap(null);
return control;
}
return undefined;