diff --git a/externs/olx.js b/externs/olx.js index 4e5fcedb2a..006846ed1a 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -2779,6 +2779,7 @@ olx.interaction.PointerOptions.prototype.handleUpEvent; * removeCondition: (ol.events.ConditionType|undefined), * toggleCondition: (ol.events.ConditionType|undefined), * multi: (boolean|undefined), + * features: (ol.Collection.|undefined), * filter: (ol.interaction.SelectFilterFunction|undefined), * wrapX: (boolean|undefined)}} * @api @@ -2869,6 +2870,17 @@ olx.interaction.SelectOptions.prototype.toggleCondition; olx.interaction.SelectOptions.prototype.multi; +/** + * Collection where the interaction will place selected features. Optional. If + * not set the interaction will create a collection. In any case the collection + * used by the interaction is returnd by + * {@link ol.interaction.Select#getFeatures}. + * @type {ol.Collection.} + * @api + */ +olx.interaction.SelectOptions.prototype.features; + + /** * A function that takes an {@link ol.Feature} and an {@link ol.layer.Layer} and * returns `true` if the feature may be selected or `false` otherwise. diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 48acc210f9..a2b5d49628 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -180,6 +180,7 @@ ol.interaction.Select = function(opt_options) { this.featureOverlay_ = new ol.layer.Vector({ source: new ol.source.Vector({ useSpatialIndex: false, + features: options.features, wrapX: options.wrapX }), style: goog.isDef(options.style) ? options.style : diff --git a/test/spec/ol/interaction/selectinteraction.test.js b/test/spec/ol/interaction/selectinteraction.test.js index 50a05ac798..af3b98a8da 100644 --- a/test/spec/ol/interaction/selectinteraction.test.js +++ b/test/spec/ol/interaction/selectinteraction.test.js @@ -98,6 +98,16 @@ describe('ol.interaction.Select', function() { expect(select).to.be.a(ol.interaction.Interaction); }); + describe('user-provided collection', function() { + + it('uses the user-provided collection', function() { + var features = new ol.Collection(); + var select = new ol.interaction.Select({features: features}); + expect(select.getFeatures()).to.be(features); + }); + + }); + }); describe('selecting a polygon', function() { @@ -269,6 +279,7 @@ goog.require('goog.dispose'); goog.require('goog.events'); goog.require('goog.events.BrowserEvent'); goog.require('goog.style'); +goog.require('ol.Collection'); goog.require('ol.Feature'); goog.require('ol.Map'); goog.require('ol.MapBrowserEvent.EventType');