Merge pull request #3019 from bjornharrtell/selectmulti
Add option to allow Select interaction logic to select overlapping features
This commit is contained in:
@@ -2519,7 +2519,8 @@ olx.interaction.PointerOptions.prototype.handleUpEvent;
|
||||
* layers: (Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean|undefined),
|
||||
* style: (ol.style.Style|Array.<ol.style.Style>|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.
|
||||
|
||||
@@ -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.<ol.Feature>} */ deselected = [];
|
||||
var /** @type {Array.<ol.Feature>} */ 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.<ol.Feature>} */ deselected = [];
|
||||
var /** @type {Array.<ol.Feature>} */ selected = [];
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
|
||||
Reference in New Issue
Block a user