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_;
}
}, this, this.layerFilter_);
if (selected.length > 0 && features.getLength() == 1 && features.item(0) == selected[0]) {
// No change; an already selected feature is selected again
selected.length = 0;
var i;
for (i = features.getLength() - 1; i >= 0; --i) {
var feature = features.item(i);
var index = selected.indexOf(feature);
if (index > -1) {
// feature is already selected
selected.splice(index, 1);
} else {
if (features.getLength() !== 0) {
deselected = Array.prototype.concat(features.getArray());
features.clear();
features.remove(feature);
deselected.push(feature);
}
}
if (selected.length !== 0) {
features.extend(selected);
}
} else {
@@ -249,9 +254,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
return !this.multi_;
}
}, this, this.layerFilter_);
var i;
for (i = deselected.length - 1; i >= 0; --i) {
features.remove(deselected[i]);
var j;
for (j = deselected.length - 1; j >= 0; --j) {
features.remove(deselected[j]);
}
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
simulateEvent('singleclick', 10, -20);
expect(listenerSpy.callCount).to.be(2);
expect(listenerSpy.callCount).to.be(1);
features = select.getFeatures();
expect(features.getLength()).to.equal(4);