diff --git a/externs/olx.js b/externs/olx.js index 87b068594c..c00a799af6 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -2519,7 +2519,8 @@ olx.interaction.PointerOptions.prototype.handleUpEvent; * layers: (Array.|function(ol.layer.Layer): boolean|undefined), * style: (ol.style.Style|Array.|ol.style.StyleFunction|undefined), * removeCondition: (ol.events.ConditionType|undefined), - * toggleCondition: (ol.events.ConditionType|undefined)}} + * toggleCondition: (ol.events.ConditionType|undefined), + * multi: (boolean|undefined)}} * @api */ olx.interaction.SelectOptions; @@ -2596,6 +2597,15 @@ olx.interaction.SelectOptions.prototype.removeCondition; */ olx.interaction.SelectOptions.prototype.toggleCondition; +/** + * A boolean that determines if the default behaviour should select only + * single features or all (overlapping) features at the clicked map + * position. Default is false i.e single select + * @type {boolean|undefined} + * @api + */ +olx.interaction.SelectOptions.prototype.multi; + /** * Namespace. diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 2da26fd587..9a995a0d78 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -62,6 +62,12 @@ ol.interaction.Select = function(opt_options) { this.toggleCondition_ = goog.isDef(options.toggleCondition) ? options.toggleCondition : ol.events.condition.shiftKeyOnly; + /** + * @private + * @type {boolean} + */ + this.multi_ = goog.isDef(options.multi) ? options.multi : false; + var layerFilter; if (goog.isDef(options.layers)) { if (goog.isFunction(options.layers)) { @@ -132,34 +138,36 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { var set = !add && !remove && !toggle; var map = mapBrowserEvent.map; var features = this.featureOverlay_.getFeatures(); + var /** @type {Array.} */ deselected = []; + var /** @type {Array.} */ selected = []; if (set) { - // Replace the currently selected feature(s) with the feature at the pixel, - // or clear the selected feature(s) if there is no feature at the pixel. - /** @type {ol.Feature|undefined} */ - var feature = map.forEachFeatureAtPixel(mapBrowserEvent.pixel, + // Replace the currently selected feature(s) with the feature(s) at the + // pixel, or clear the selected feature(s) if there is no feature at + // the pixel. + map.forEachFeatureAtPixel(mapBrowserEvent.pixel, /** * @param {ol.Feature} feature Feature. * @param {ol.layer.Layer} layer Layer. */ function(feature, layer) { - return feature; + selected.push(feature); }, undefined, this.layerFilter_); - if (goog.isDef(feature) && + if (selected.length > 0 && features.getLength() == 1 && - features.item(0) == feature) { + features.item(0) == selected[selected.length - 1]) { // No change } else { if (features.getLength() !== 0) { features.clear(); } - if (goog.isDef(feature)) { - features.push(feature); + if (this.multi_) { + features.extend(selected); + } else if (selected.length > 0) { + features.push(selected[selected.length - 1]); } } } else { // Modify the currently selected feature(s). - var /** @type {Array.} */ deselected = []; - var /** @type {Array.} */ selected = []; map.forEachFeatureAtPixel(mapBrowserEvent.pixel, /** * @param {ol.Feature} feature Feature.