Restore ol.interaction.Select options
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
goog.provide('ol.interaction.Select');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.FeatureOverlay');
|
||||
@@ -113,87 +112,61 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
|
||||
var add = this.addCondition_(mapBrowserEvent);
|
||||
var remove = this.removeCondition_(mapBrowserEvent);
|
||||
var toggle = this.toggleCondition_(mapBrowserEvent);
|
||||
var set = !add && !remove && !toggle;
|
||||
var map = mapBrowserEvent.map;
|
||||
var feature = map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
*/
|
||||
function(feature, layer) {
|
||||
this.addFeature_(feature, add, remove, toggle);
|
||||
return feature;
|
||||
}, this, this.layerFilter_);
|
||||
if (!goog.isDef(feature) && !add && !remove) {
|
||||
this.removeAllFeatures_();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {?ol.Feature|undefined} feature Feature.
|
||||
* @param {boolean} add Add.
|
||||
* @param {boolean} remove Remove.
|
||||
* @param {boolean} toggle Toggle.
|
||||
* @private
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.interaction.Select.prototype.addFeature_ = function(feature, add,
|
||||
remove, toggle) {
|
||||
var features = this.featureOverlay_.getFeatures();
|
||||
var index = -1;
|
||||
var i, ii;
|
||||
if ((!goog.isDef(feature) || goog.isNull(feature)) && !add) {
|
||||
this.removeAllFeatures_();
|
||||
return;
|
||||
}
|
||||
goog.asserts.assertInstanceof(feature, ol.Feature);
|
||||
index = features.getArray().indexOf(feature);
|
||||
if (index == -1) {
|
||||
if (!add && !remove && (features.getLength() > 0)) {
|
||||
for (ii = features.getLength() - 1, i = ii; i >= 0; i--) {
|
||||
if (features.getAt(i) != feature) {
|
||||
this.removeFeature_(/** @type {ol.Feature} */ (features.getAt(i)));
|
||||
}
|
||||
var skippedFeatures = map.getSkippedFeatures();
|
||||
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,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
*/
|
||||
function(feature, layer) {
|
||||
return feature;
|
||||
}, undefined, this.layerFilter_);
|
||||
if (goog.isDef(feature) &&
|
||||
features.getLength() == 1 &&
|
||||
features.getAt(0) == feature) {
|
||||
// No change
|
||||
} else {
|
||||
if (features.getLength() !== 0) {
|
||||
features.forEach(function(feature) {
|
||||
skippedFeatures.remove(feature);
|
||||
});
|
||||
features.clear();
|
||||
}
|
||||
if (goog.isDef(feature)) {
|
||||
features.push(feature);
|
||||
skippedFeatures.push(feature);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (toggle || remove) {
|
||||
this.removeFeature_(/** @type {ol.Feature} */ (features.getAt(index)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (remove) {
|
||||
return;
|
||||
}
|
||||
if (index == -1) {
|
||||
features.push(feature);
|
||||
this.getMap().getSkippedFeatures().push(feature);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @private
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.interaction.Select.prototype.removeFeature_ = function(feature) {
|
||||
this.featureOverlay_.getFeatures().remove(feature);
|
||||
this.getMap().getSkippedFeatures().remove(feature);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.interaction.Select.prototype.removeAllFeatures_ = function() {
|
||||
var i, ii,
|
||||
features = this.featureOverlay_.getFeatures();
|
||||
for (ii = features.getLength() - 1, i = ii; i >= 0; i--) {
|
||||
this.removeFeature_(/** @type {ol.Feature} */ (features.getAt(i)));
|
||||
// Modify the currently selected feature(s).
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
*/
|
||||
function(feature, layer) {
|
||||
var index = goog.array.indexOf(features.getArray(), feature);
|
||||
if (index == -1) {
|
||||
if (add || toggle) {
|
||||
features.push(feature);
|
||||
skippedFeatures.push(feature);
|
||||
}
|
||||
} else {
|
||||
if (remove || toggle) {
|
||||
features.removeAt(index);
|
||||
skippedFeatures.remove(feature);
|
||||
}
|
||||
}
|
||||
}, undefined, this.layerFilter_);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user