From 8f8027c33a3d4c7387c52aa7bd17112060d1d331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Mon, 12 Jul 2021 13:49:08 +0200 Subject: [PATCH] Fix adding controls with map config If a control like ol.control.Bar adds sub controls when added to a map it fails during map creating because the listeners are added after the control was added to the map. --- src/ol/PluggableMap.js | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 72547772d3..a7da6c0dde 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -383,16 +383,6 @@ class PluggableMap extends BaseObject { // is "defined" already. this.setProperties(optionsInternal.values); - this.controls.forEach( - /** - * @param {import("./control/Control.js").default} control Control. - * @this {PluggableMap} - */ - function (control) { - control.setMap(this); - }.bind(this) - ); - this.controls.addEventListener( CollectionEventType.ADD, /** @@ -413,16 +403,6 @@ class PluggableMap extends BaseObject { }.bind(this) ); - this.interactions.forEach( - /** - * @param {import("./interaction/Interaction.js").default} interaction Interaction. - * @this {PluggableMap} - */ - function (interaction) { - interaction.setMap(this); - }.bind(this) - ); - this.interactions.addEventListener( CollectionEventType.ADD, /** @@ -443,8 +423,6 @@ class PluggableMap extends BaseObject { }.bind(this) ); - this.overlays_.forEach(this.addOverlayInternal_.bind(this)); - this.overlays_.addEventListener( CollectionEventType.ADD, /** @@ -473,6 +451,28 @@ class PluggableMap extends BaseObject { event.element.setMap(null); }.bind(this) ); + + this.controls.forEach( + /** + * @param {import("./control/Control.js").default} control Control. + * @this {PluggableMap} + */ + function (control) { + control.setMap(this); + }.bind(this) + ); + + this.interactions.forEach( + /** + * @param {import("./interaction/Interaction.js").default} interaction Interaction. + * @this {PluggableMap} + */ + function (interaction) { + interaction.setMap(this); + }.bind(this) + ); + + this.overlays_.forEach(this.addOverlayInternal_.bind(this)); } /**