Fixed issue with multi option of ol.interaction.Select
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user