CK-240: fix multiple select interactions on map

event handlers have to be (de)activated when the interaction is added or removed to the map, not when constructed

added unit test
This commit is contained in:
Geert Premereur
2020-01-08 10:53:00 +01:00
committed by Andreas Hocevar
parent 10c7f08fa4
commit a30a92a963
2 changed files with 57 additions and 5 deletions

View File

@@ -259,9 +259,6 @@ class Select extends Interaction {
* @type {Object<string, import("../layer/Layer.js").default>}
*/
this.featureLayerAssociation_ = {};
this.features_.addEventListener(CollectionEventType.ADD, this.boundAddFeature_);
this.features_.addEventListener(CollectionEventType.REMOVE, this.boundRemoveFeature_);
}
/**
@@ -329,8 +326,13 @@ class Select extends Interaction {
this.features_.forEach(this.restorePreviousStyle_.bind(this));
}
super.setMap(map);
if (map && this.style_) {
this.features_.forEach(this.applySelectedStyle_.bind(this));
if (map) {
this.features_.addEventListener(CollectionEventType.ADD, this.boundAddFeature_);
this.features_.addEventListener(CollectionEventType.REMOVE, this.boundRemoveFeature_);
if (this.style_) {
this.features_.forEach(this.applySelectedStyle_.bind(this));
}
}
if (!map) {
this.features_.removeEventListener(CollectionEventType.ADD, this.boundAddFeature_);