Exclude unmanaged layers from selection

This commit is contained in:
Andreas Hocevar
2015-11-08 10:25:29 +01:00
parent 1aea2c2b0c
commit d968f32456
2 changed files with 24 additions and 1 deletions

View File

@@ -283,7 +283,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
* @param {ol.layer.Layer} layer Layer.
*/
function(feature, layer) {
if (this.filter_(feature, layer)) {
if (layer && this.filter_(feature, layer)) {
selected.push(feature);
this.addFeatureLayerAssociation_(feature, layer);
return !this.multi_;

View File

@@ -161,6 +161,29 @@ describe('ol.interaction.Select', function() {
describe('filter features using the filter option', function() {
var select;
describe('with unmanaged layers', function() {
it('does not call filter for unmanaged layers', function() {
var spy = sinon.spy();
var select = new ol.interaction.Select({
multi: false,
filter: spy
});
map.addInteraction(select);
var feature = new ol.Feature(
new ol.geom.Polygon([[[0, 0], [0, 40], [40, 40], [40, 0]]]));
var unmanaged = new ol.layer.Vector({
source: new ol.source.Vector({
features: [feature]
})
});
unmanaged.setMap(map);
map.renderSync();
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20);
expect(spy.firstCall.args[0]).to.not.equal(feature);
unmanaged.setMap(null);
});
});
describe('with multi set to true', function() {
it('only selects features that pass the filter', function() {