From c11e95099c1e2dce890e93087ce01abe69845dec Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 21 Apr 2016 08:36:42 +0200 Subject: [PATCH] Fix feature-layer association on replaced selections --- src/ol/interaction/selectinteraction.js | 11 +---------- test/spec/ol/interaction/selectinteraction.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 4de492e1f7..4cce1aa1b3 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -280,6 +280,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { // Replace the currently selected feature(s) with the feature(s) at the // pixel, or clear the selected feature(s) if there is no feature at // the pixel. + ol.object.clear(this.featureLayerAssociation_); map.forEachFeatureAtPixel(mapBrowserEvent.pixel, /** * @param {ol.Feature|ol.render.Feature} feature Feature. @@ -303,16 +304,6 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { features.clear(); } features.extend(selected); - // Modify object this.featureLayerAssociation_ - if (selected.length === 0) { - ol.object.clear(this.featureLayerAssociation_); - } else { - if (deselected.length > 0) { - deselected.forEach(function(feature) { - this.removeFeatureLayerAssociation_(feature); - }, this); - } - } } } else { // Modify the currently selected feature(s). diff --git a/test/spec/ol/interaction/selectinteraction.test.js b/test/spec/ol/interaction/selectinteraction.test.js index 1da9594b65..3168d78eb2 100644 --- a/test/spec/ol/interaction/selectinteraction.test.js +++ b/test/spec/ol/interaction/selectinteraction.test.js @@ -181,6 +181,16 @@ describe('ol.interaction.Select', function() { var features = select.getFeatures(); expect(features.getLength()).to.equal(4); + expect(select.getLayer(features.item(0))).to.equal(layer); + + // Select again to make sure the internal layer isn't reported + simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20); + + expect(listenerSpy.callCount).to.be(2); + + features = select.getFeatures(); + expect(features.getLength()).to.equal(4); + expect(select.getLayer(features.item(0))).to.equal(layer); }); }); @@ -312,6 +322,8 @@ describe('ol.interaction.Select', function() { interaction.on('select', listenerSpy); simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20); + // Select again to make sure that the internal layer doesn't get reported. + simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20); }); });