@@ -154,10 +154,36 @@ ol.interaction.Select = function(opt_options) {
154
154
this . filter_ = options . filter ? options . filter :
155
155
goog . functions . TRUE ;
156
156
157
+ var featureOverlay = new ol . layer . Vector ( {
158
+ source : new ol . source . Vector ( {
159
+ useSpatialIndex : false ,
160
+ features : options . features ,
161
+ wrapX : options . wrapX
162
+ } ) ,
163
+ style : options . style ? options . style :
164
+ ol . interaction . Select . getDefaultStyleFunction ( ) ,
165
+ updateWhileAnimating : true ,
166
+ updateWhileInteracting : true
167
+ } ) ;
168
+
169
+ /**
170
+ * @private
171
+ * @type {ol.layer.Vector }
172
+ */
173
+ this . featureOverlay_ = featureOverlay ;
174
+
157
175
var layerFilter ;
158
176
if ( options . layers ) {
159
177
if ( goog . isFunction ( options . layers ) ) {
160
- layerFilter = options . layers ;
178
+ layerFilter =
179
+ /**
180
+ * @param {ol.layer.Layer } layer Layer.
181
+ * @return {boolean } Include.
182
+ */
183
+ function ( layer ) {
184
+ goog . asserts . assertFunction ( options . layers ) ;
185
+ return layer === featureOverlay || options . layers ( layer ) ;
186
+ } ;
161
187
} else {
162
188
var layers = options . layers ;
163
189
layerFilter =
@@ -166,7 +192,7 @@ ol.interaction.Select = function(opt_options) {
166
192
* @return {boolean } Include.
167
193
*/
168
194
function ( layer ) {
169
- return ol . array . includes ( layers , layer ) ;
195
+ return layer === featureOverlay || ol . array . includes ( layers , layer ) ;
170
196
} ;
171
197
}
172
198
} else {
@@ -187,22 +213,6 @@ ol.interaction.Select = function(opt_options) {
187
213
*/
188
214
this . featureLayerAssociation_ = { } ;
189
215
190
- /**
191
- * @private
192
- * @type {ol.layer.Vector }
193
- */
194
- this . featureOverlay_ = new ol . layer . Vector ( {
195
- source : new ol . source . Vector ( {
196
- useSpatialIndex : false ,
197
- features : options . features ,
198
- wrapX : options . wrapX
199
- } ) ,
200
- style : options . style ? options . style :
201
- ol . interaction . Select . getDefaultStyleFunction ( ) ,
202
- updateWhileAnimating : true ,
203
- updateWhileInteracting : true
204
- } ) ;
205
-
206
216
var features = this . featureOverlay_ . getSource ( ) . getFeaturesCollection ( ) ;
207
217
goog . events . listen ( features , ol . CollectionEventType . ADD ,
208
218
this . addFeature_ , false , this ) ;
@@ -318,9 +328,11 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
318
328
* @param {ol.layer.Layer } layer Layer.
319
329
*/
320
330
function ( feature , layer ) {
321
- if ( ! ol . array . includes ( features . getArray ( ) , feature ) ) {
331
+ if ( layer !== this . featureOverlay_ ) {
322
332
if ( add || toggle ) {
323
- if ( this . filter_ ( feature , layer ) ) {
333
+ if ( this . filter_ ( feature , layer ) &&
334
+ ! ol . array . includes ( features . getArray ( ) , feature ) &&
335
+ ! ol . array . includes ( selected , feature ) ) {
324
336
selected . push ( feature ) ;
325
337
this . addFeatureLayerAssociation_ ( feature , layer ) ;
326
338
}
0 commit comments