Fix select event always reporting as multi select
This commit is contained in:
@@ -198,7 +198,8 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
*/
|
*/
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
selected.push(feature);
|
selected.push(feature);
|
||||||
}, undefined, this.layerFilter_);
|
return !this.multi_;
|
||||||
|
}, this, this.layerFilter_);
|
||||||
if (selected.length > 0 && features.getLength() == 1 &&
|
if (selected.length > 0 && features.getLength() == 1 &&
|
||||||
features.item(0) == selected[0]) {
|
features.item(0) == selected[0]) {
|
||||||
// No change
|
// No change
|
||||||
@@ -208,11 +209,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
deselected = Array.prototype.concat(features.getArray());
|
deselected = Array.prototype.concat(features.getArray());
|
||||||
features.clear();
|
features.clear();
|
||||||
}
|
}
|
||||||
if (this.multi_) {
|
features.extend(selected);
|
||||||
features.extend(selected);
|
|
||||||
} else if (selected.length > 0) {
|
|
||||||
features.push(selected[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Modify the currently selected feature(s).
|
// Modify the currently selected feature(s).
|
||||||
|
|||||||
@@ -89,8 +89,15 @@ describe('ol.interaction.Select', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('select with single-click', 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);
|
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20);
|
||||||
|
|
||||||
|
expect(listenerSpy.callCount).to.be(1);
|
||||||
|
|
||||||
var features = select.getFeatures();
|
var features = select.getFeatures();
|
||||||
expect(features.getLength()).to.equal(1);
|
expect(features.getLength()).to.equal(1);
|
||||||
});
|
});
|
||||||
@@ -107,8 +114,15 @@ describe('ol.interaction.Select', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('select with single-click', 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);
|
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20);
|
||||||
|
|
||||||
|
expect(listenerSpy.callCount).to.be(1);
|
||||||
|
|
||||||
var features = select.getFeatures();
|
var features = select.getFeatures();
|
||||||
expect(features.getLength()).to.equal(2);
|
expect(features.getLength()).to.equal(2);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user