Merge pull request #1915 from twpayne/select-interaction
Restore select interaction behaviour
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.View2D');
|
goog.require('ol.View2D');
|
||||||
goog.require('ol.events.condition');
|
|
||||||
goog.require('ol.interaction');
|
goog.require('ol.interaction');
|
||||||
goog.require('ol.interaction.Modify');
|
goog.require('ol.interaction.Modify');
|
||||||
goog.require('ol.interaction.Select');
|
goog.require('ol.interaction.Select');
|
||||||
@@ -15,7 +14,6 @@ goog.require('ol.style.Style');
|
|||||||
|
|
||||||
|
|
||||||
var raster = new ol.layer.Tile({
|
var raster = new ol.layer.Tile({
|
||||||
style: 'Aerial',
|
|
||||||
source: new ol.source.MapQuest({
|
source: new ol.source.MapQuest({
|
||||||
layer: 'sat'
|
layer: 'sat'
|
||||||
})
|
})
|
||||||
@@ -31,8 +29,6 @@ var vector = new ol.layer.Vector({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var select = new ol.interaction.Select({
|
var select = new ol.interaction.Select({
|
||||||
addCondition: ol.events.condition.shiftKeyOnly,
|
|
||||||
toggleCondition: ol.events.condition.always,
|
|
||||||
style: new ol.style.Style({
|
style: new ol.style.Style({
|
||||||
stroke: new ol.style.Stroke({
|
stroke: new ol.style.Stroke({
|
||||||
color: '#3399CC',
|
color: '#3399CC',
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
goog.provide('ol.interaction.Select');
|
goog.provide('ol.interaction.Select');
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
|
||||||
goog.require('goog.functions');
|
goog.require('goog.functions');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.FeatureOverlay');
|
goog.require('ol.FeatureOverlay');
|
||||||
@@ -113,87 +112,61 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
|
|||||||
var add = this.addCondition_(mapBrowserEvent);
|
var add = this.addCondition_(mapBrowserEvent);
|
||||||
var remove = this.removeCondition_(mapBrowserEvent);
|
var remove = this.removeCondition_(mapBrowserEvent);
|
||||||
var toggle = this.toggleCondition_(mapBrowserEvent);
|
var toggle = this.toggleCondition_(mapBrowserEvent);
|
||||||
|
var set = !add && !remove && !toggle;
|
||||||
var map = mapBrowserEvent.map;
|
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 features = this.featureOverlay_.getFeatures();
|
||||||
var index = -1;
|
var skippedFeatures = map.getSkippedFeatures();
|
||||||
var i, ii;
|
if (set) {
|
||||||
if ((!goog.isDef(feature) || goog.isNull(feature)) && !add) {
|
// Replace the currently selected feature(s) with the feature at the pixel,
|
||||||
this.removeAllFeatures_();
|
// or clear the selected feature(s) if there is no feature at the pixel.
|
||||||
return;
|
/** @type {ol.Feature|undefined} */
|
||||||
}
|
var feature = map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||||
goog.asserts.assertInstanceof(feature, ol.Feature);
|
/**
|
||||||
index = features.getArray().indexOf(feature);
|
* @param {ol.Feature} feature Feature.
|
||||||
if (index == -1) {
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
if (!add && !remove && (features.getLength() > 0)) {
|
*/
|
||||||
for (ii = features.getLength() - 1, i = ii; i >= 0; i--) {
|
function(feature, layer) {
|
||||||
if (features.getAt(i) != feature) {
|
return feature;
|
||||||
this.removeFeature_(/** @type {ol.Feature} */ (features.getAt(i)));
|
}, 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 {
|
} else {
|
||||||
if (toggle || remove) {
|
// Modify the currently selected feature(s).
|
||||||
this.removeFeature_(/** @type {ol.Feature} */ (features.getAt(index)));
|
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||||
return;
|
/**
|
||||||
}
|
* @param {ol.Feature} feature Feature.
|
||||||
}
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
if (remove) {
|
*/
|
||||||
return;
|
function(feature, layer) {
|
||||||
}
|
var index = goog.array.indexOf(features.getArray(), feature);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
features.push(feature);
|
if (add || toggle) {
|
||||||
this.getMap().getSkippedFeatures().push(feature);
|
features.push(feature);
|
||||||
}
|
skippedFeatures.push(feature);
|
||||||
};
|
}
|
||||||
|
} else {
|
||||||
|
if (remove || toggle) {
|
||||||
/**
|
features.removeAt(index);
|
||||||
* @param {ol.Feature} feature Feature.
|
skippedFeatures.remove(feature);
|
||||||
* @private
|
}
|
||||||
* @todo stability experimental
|
}
|
||||||
*/
|
}, undefined, this.layerFilter_);
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user