Set control map in 'add' and 'remove' event handler
This commit is contained in:
+16
-2
@@ -382,6 +382,22 @@ ol.Map = function(options) {
|
|||||||
control.setMap(this);
|
control.setMap(this);
|
||||||
}, 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(
|
this.interactions_.forEach(
|
||||||
/**
|
/**
|
||||||
* @param {ol.interaction.Interaction} interaction Interaction.
|
* @param {ol.interaction.Interaction} interaction Interaction.
|
||||||
@@ -445,7 +461,6 @@ ol.Map.prototype.addControl = function(control) {
|
|||||||
var controls = this.getControls();
|
var controls = this.getControls();
|
||||||
goog.asserts.assert(goog.isDef(controls));
|
goog.asserts.assert(goog.isDef(controls));
|
||||||
controls.push(control);
|
controls.push(control);
|
||||||
control.setMap(this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1058,7 +1073,6 @@ ol.Map.prototype.removeControl = function(control) {
|
|||||||
var controls = this.getControls();
|
var controls = this.getControls();
|
||||||
goog.asserts.assert(goog.isDef(controls));
|
goog.asserts.assert(goog.isDef(controls));
|
||||||
if (goog.isDef(controls.remove(control))) {
|
if (goog.isDef(controls.remove(control))) {
|
||||||
control.setMap(null);
|
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user