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_;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user