Merge pull request #1806 from fredj/overlays-events
Set map in 'add' and 'remove' event handler
This commit is contained in:
@@ -30,6 +30,7 @@ goog.require('goog.style');
|
||||
goog.require('goog.vec.Mat4');
|
||||
goog.require('ol.BrowserFeature');
|
||||
goog.require('ol.Collection');
|
||||
goog.require('ol.CollectionEventType');
|
||||
goog.require('ol.FrameState');
|
||||
goog.require('ol.IView');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
@@ -381,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.
|
||||
@@ -390,6 +407,22 @@ ol.Map = function(options) {
|
||||
interaction.setMap(this);
|
||||
}, this);
|
||||
|
||||
goog.events.listen(this.interactions_, ol.CollectionEventType.ADD,
|
||||
/**
|
||||
* @param {ol.CollectionEvent} event Collection event.
|
||||
*/
|
||||
function(event) {
|
||||
event.element.setMap(this);
|
||||
}, false, this);
|
||||
|
||||
goog.events.listen(this.interactions_, ol.CollectionEventType.REMOVE,
|
||||
/**
|
||||
* @param {ol.CollectionEvent} event Collection event.
|
||||
*/
|
||||
function(event) {
|
||||
event.element.setMap(null);
|
||||
}, false, this);
|
||||
|
||||
this.overlays_.forEach(
|
||||
/**
|
||||
* @param {ol.Overlay} overlay Overlay.
|
||||
@@ -399,6 +432,22 @@ ol.Map = function(options) {
|
||||
overlay.setMap(this);
|
||||
}, this);
|
||||
|
||||
goog.events.listen(this.overlays_, ol.CollectionEventType.ADD,
|
||||
/**
|
||||
* @param {ol.CollectionEvent} event Collection event.
|
||||
*/
|
||||
function(event) {
|
||||
event.element.setMap(this);
|
||||
}, false, this);
|
||||
|
||||
goog.events.listen(this.overlays_, ol.CollectionEventType.REMOVE,
|
||||
/**
|
||||
* @param {ol.CollectionEvent} event Collection event.
|
||||
*/
|
||||
function(event) {
|
||||
event.element.setMap(null);
|
||||
}, false, this);
|
||||
|
||||
};
|
||||
goog.inherits(ol.Map, ol.Object);
|
||||
|
||||
@@ -412,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);
|
||||
};
|
||||
|
||||
|
||||
@@ -424,7 +472,6 @@ ol.Map.prototype.addInteraction = function(interaction) {
|
||||
var interactions = this.getInteractions();
|
||||
goog.asserts.assert(goog.isDef(interactions));
|
||||
interactions.push(interaction);
|
||||
interaction.setMap(this);
|
||||
};
|
||||
|
||||
|
||||
@@ -449,7 +496,6 @@ ol.Map.prototype.addOverlay = function(overlay) {
|
||||
var overlays = this.getOverlays();
|
||||
goog.asserts.assert(goog.isDef(overlays));
|
||||
overlays.push(overlay);
|
||||
overlay.setMap(this);
|
||||
};
|
||||
|
||||
|
||||
@@ -1027,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;
|
||||
@@ -1045,7 +1090,6 @@ ol.Map.prototype.removeInteraction = function(interaction) {
|
||||
var interactions = this.getInteractions();
|
||||
goog.asserts.assert(goog.isDef(interactions));
|
||||
if (goog.isDef(interactions.remove(interaction))) {
|
||||
interaction.setMap(null);
|
||||
removed = interaction;
|
||||
}
|
||||
return removed;
|
||||
@@ -1077,7 +1121,6 @@ ol.Map.prototype.removeOverlay = function(overlay) {
|
||||
var overlays = this.getOverlays();
|
||||
goog.asserts.assert(goog.isDef(overlays));
|
||||
if (goog.isDef(overlays.remove(overlay))) {
|
||||
overlay.setMap(null);
|
||||
return overlay;
|
||||
}
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user