diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 7ef21263c6..872dc7f23b 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -154,10 +154,36 @@ ol.interaction.Select = function(opt_options) { this.filter_ = options.filter ? options.filter : goog.functions.TRUE; + var featureOverlay = new ol.layer.Vector({ + source: new ol.source.Vector({ + useSpatialIndex: false, + features: options.features, + wrapX: options.wrapX + }), + style: options.style ? options.style : + ol.interaction.Select.getDefaultStyleFunction(), + updateWhileAnimating: true, + updateWhileInteracting: true + }); + + /** + * @private + * @type {ol.layer.Vector} + */ + this.featureOverlay_ = featureOverlay; + var layerFilter; if (options.layers) { if (goog.isFunction(options.layers)) { - layerFilter = options.layers; + layerFilter = + /** + * @param {ol.layer.Layer} layer Layer. + * @return {boolean} Include. + */ + function(layer) { + goog.asserts.assertFunction(options.layers); + return layer === featureOverlay || options.layers(layer); + }; } else { var layers = options.layers; layerFilter = @@ -166,7 +192,7 @@ ol.interaction.Select = function(opt_options) { * @return {boolean} Include. */ function(layer) { - return ol.array.includes(layers, layer); + return layer === featureOverlay || ol.array.includes(layers, layer); }; } } else { @@ -187,22 +213,6 @@ ol.interaction.Select = function(opt_options) { */ this.featureLayerAssociation_ = {}; - /** - * @private - * @type {ol.layer.Vector} - */ - this.featureOverlay_ = new ol.layer.Vector({ - source: new ol.source.Vector({ - useSpatialIndex: false, - features: options.features, - wrapX: options.wrapX - }), - style: options.style ? options.style : - ol.interaction.Select.getDefaultStyleFunction(), - updateWhileAnimating: true, - updateWhileInteracting: true - }); - var features = this.featureOverlay_.getSource().getFeaturesCollection(); goog.events.listen(features, ol.CollectionEventType.ADD, this.addFeature_, false, this); @@ -318,9 +328,11 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { * @param {ol.layer.Layer} layer Layer. */ function(feature, layer) { - if (!ol.array.includes(features.getArray(), feature)) { + if (layer !== this.featureOverlay_) { if (add || toggle) { - if (this.filter_(feature, layer)) { + if (this.filter_(feature, layer) && + !ol.array.includes(features.getArray(), feature) && + !ol.array.includes(selected, feature)) { selected.push(feature); this.addFeatureLayerAssociation_(feature, layer); }