Merge pull request #12506 from M393/fix-ol-ext-bar
Fix adding controls with map config
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Control from '../../../../src/ol/control/Control.js';
|
||||
import DoubleClickZoom from '../../../../src/ol/interaction/DoubleClickZoom.js';
|
||||
import DragPan from '../../../../src/ol/interaction/DragPan.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
@@ -66,6 +67,35 @@ describe('ol.Map', function () {
|
||||
const containerStop = map.getOverlayContainerStopEvent();
|
||||
expect(containerStop.className).to.be('ol-overlaycontainer-stopevent');
|
||||
});
|
||||
|
||||
it('calls setMap for controls added by other controls', function () {
|
||||
let subSetMapCalled = false;
|
||||
class SubControl extends Control {
|
||||
setMap(map) {
|
||||
super.setMap(map);
|
||||
subSetMapCalled = true;
|
||||
}
|
||||
}
|
||||
class MainControl extends Control {
|
||||
setMap(map) {
|
||||
super.setMap(map);
|
||||
map.addControl(
|
||||
new SubControl({
|
||||
element: document.createElement('div'),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
new Map({
|
||||
target: document.createElement('div'),
|
||||
controls: [
|
||||
new MainControl({
|
||||
element: document.createElement('div'),
|
||||
}),
|
||||
],
|
||||
});
|
||||
expect(subSetMapCalled).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addLayer()', function () {
|
||||
|
||||
Reference in New Issue
Block a user