Merge pull request #3019 from bjornharrtell/selectmulti
Add option to allow Select interaction logic to select overlapping features
This commit is contained in:
+11
-1
@@ -2519,7 +2519,8 @@ olx.interaction.PointerOptions.prototype.handleUpEvent;
|
|||||||
* layers: (Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean|undefined),
|
* layers: (Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean|undefined),
|
||||||
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
|
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
|
||||||
* removeCondition: (ol.events.ConditionType|undefined),
|
* removeCondition: (ol.events.ConditionType|undefined),
|
||||||
* toggleCondition: (ol.events.ConditionType|undefined)}}
|
* toggleCondition: (ol.events.ConditionType|undefined),
|
||||||
|
* multi: (boolean|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.interaction.SelectOptions;
|
olx.interaction.SelectOptions;
|
||||||
@@ -2596,6 +2597,15 @@ olx.interaction.SelectOptions.prototype.removeCondition;
|
|||||||
*/
|
*/
|
||||||
olx.interaction.SelectOptions.prototype.toggleCondition;
|
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.
|
* Namespace.
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ ol.interaction.Select = function(opt_options) {
|
|||||||
this.toggleCondition_ = goog.isDef(options.toggleCondition) ?
|
this.toggleCondition_ = goog.isDef(options.toggleCondition) ?
|
||||||
options.toggleCondition : ol.events.condition.shiftKeyOnly;
|
options.toggleCondition : ol.events.condition.shiftKeyOnly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.multi_ = goog.isDef(options.multi) ? options.multi : false;
|
||||||
|
|
||||||
var layerFilter;
|
var layerFilter;
|
||||||
if (goog.isDef(options.layers)) {
|
if (goog.isDef(options.layers)) {
|
||||||
if (goog.isFunction(options.layers)) {
|
if (goog.isFunction(options.layers)) {
|
||||||
@@ -132,34 +138,36 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
var set = !add && !remove && !toggle;
|
var set = !add && !remove && !toggle;
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
var features = this.featureOverlay_.getFeatures();
|
var features = this.featureOverlay_.getFeatures();
|
||||||
|
var /** @type {Array.<ol.Feature>} */ deselected = [];
|
||||||
|
var /** @type {Array.<ol.Feature>} */ selected = [];
|
||||||
if (set) {
|
if (set) {
|
||||||
// Replace the currently selected feature(s) with the feature at the pixel,
|
// Replace the currently selected feature(s) with the feature(s) at the
|
||||||
// or clear the selected feature(s) if there is no feature at the pixel.
|
// pixel, or clear the selected feature(s) if there is no feature at
|
||||||
/** @type {ol.Feature|undefined} */
|
// the pixel.
|
||||||
var feature = map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @param {ol.layer.Layer} layer Layer.
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
*/
|
*/
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
return feature;
|
selected.push(feature);
|
||||||
}, undefined, this.layerFilter_);
|
}, undefined, this.layerFilter_);
|
||||||
if (goog.isDef(feature) &&
|
if (selected.length > 0 &&
|
||||||
features.getLength() == 1 &&
|
features.getLength() == 1 &&
|
||||||
features.item(0) == feature) {
|
features.item(0) == selected[selected.length - 1]) {
|
||||||
// No change
|
// No change
|
||||||
} else {
|
} else {
|
||||||
if (features.getLength() !== 0) {
|
if (features.getLength() !== 0) {
|
||||||
features.clear();
|
features.clear();
|
||||||
}
|
}
|
||||||
if (goog.isDef(feature)) {
|
if (this.multi_) {
|
||||||
features.push(feature);
|
features.extend(selected);
|
||||||
|
} else if (selected.length > 0) {
|
||||||
|
features.push(selected[selected.length - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Modify the currently selected feature(s).
|
// Modify the currently selected feature(s).
|
||||||
var /** @type {Array.<ol.Feature>} */ deselected = [];
|
|
||||||
var /** @type {Array.<ol.Feature>} */ selected = [];
|
|
||||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
|||||||
Reference in New Issue
Block a user