diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index a14e0bf9a7..e4c28fab07 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -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_; diff --git a/test/spec/ol/interaction/selectinteraction.test.js b/test/spec/ol/interaction/selectinteraction.test.js index c6f6fd6e87..89530aa4ff 100644 --- a/test/spec/ol/interaction/selectinteraction.test.js +++ b/test/spec/ol/interaction/selectinteraction.test.js @@ -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() {