From 49c2af165abb8e12cb9f3fc9999633e649da7600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Wed, 4 Mar 2015 08:43:30 +0100 Subject: [PATCH] Fix select event always reporting as multi select --- src/ol/interaction/selectinteraction.js | 9 +++------ test/spec/ol/interaction/selectinteraction.test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 9406c9df65..0533a3bf94 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -198,7 +198,8 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { */ function(feature, layer) { selected.push(feature); - }, undefined, this.layerFilter_); + return !this.multi_; + }, this, this.layerFilter_); if (selected.length > 0 && features.getLength() == 1 && features.item(0) == selected[0]) { // No change @@ -208,11 +209,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { deselected = Array.prototype.concat(features.getArray()); features.clear(); } - if (this.multi_) { - features.extend(selected); - } else if (selected.length > 0) { - features.push(selected[0]); - } + features.extend(selected); } } 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 455108028b..df5932c05a 100644 --- a/test/spec/ol/interaction/selectinteraction.test.js +++ b/test/spec/ol/interaction/selectinteraction.test.js @@ -89,8 +89,15 @@ describe('ol.interaction.Select', function() { }); it('select with single-click', function() { + var listenerSpy = sinon.spy(function(e) { + expect(e.selected).to.have.length(1); + }); + select.on('select', listenerSpy); + simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20); + expect(listenerSpy.callCount).to.be(1); + var features = select.getFeatures(); expect(features.getLength()).to.equal(1); }); @@ -107,8 +114,15 @@ describe('ol.interaction.Select', function() { }); it('select with single-click', function() { + var listenerSpy = sinon.spy(function(e) { + expect(e.selected).to.have.length(2); + }); + select.on('select', listenerSpy); + simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20); + expect(listenerSpy.callCount).to.be(1); + var features = select.getFeatures(); expect(features.getLength()).to.equal(2); });