Fixed issue with multi option of ol.interaction.Select

This commit is contained in:
simonseyock
2016-09-06 12:35:04 +01:00
committed by simonseyock
parent 51776ed79e
commit 7392db0f57
2 changed files with 16 additions and 11 deletions

View File

@@ -217,14 +217,19 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
return !this.multi_; return !this.multi_;
} }
}, this, this.layerFilter_); }, this, this.layerFilter_);
if (selected.length > 0 && features.getLength() == 1 && features.item(0) == selected[0]) { var i;
// No change; an already selected feature is selected again for (i = features.getLength() - 1; i >= 0; --i) {
selected.length = 0; var feature = features.item(i);
var index = selected.indexOf(feature);
if (index > -1) {
// feature is already selected
selected.splice(index, 1);
} else { } else {
if (features.getLength() !== 0) { features.remove(feature);
deselected = Array.prototype.concat(features.getArray()); deselected.push(feature);
features.clear();
} }
}
if (selected.length !== 0) {
features.extend(selected); features.extend(selected);
} }
} else { } else {
@@ -249,9 +254,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
return !this.multi_; return !this.multi_;
} }
}, this, this.layerFilter_); }, this, this.layerFilter_);
var i; var j;
for (i = deselected.length - 1; i >= 0; --i) { for (j = deselected.length - 1; j >= 0; --j) {
features.remove(deselected[i]); features.remove(deselected[j]);
} }
features.extend(selected); features.extend(selected);
} }

View File

@@ -229,7 +229,7 @@ describe('ol.interaction.Select', function() {
// Select again to make sure the internal layer isn't reported // Select again to make sure the internal layer isn't reported
simulateEvent('singleclick', 10, -20); simulateEvent('singleclick', 10, -20);
expect(listenerSpy.callCount).to.be(2); expect(listenerSpy.callCount).to.be(1);
features = select.getFeatures(); features = select.getFeatures();
expect(features.getLength()).to.equal(4); expect(features.getLength()).to.equal(4);