From 0ec6bc6325fa4918ca63d12c5d0a11dfa57ff4a1 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 27 Mar 2014 19:11:51 +0100 Subject: [PATCH 1/3] Fix jsdoc --- src/ol/interaction/selectinteraction.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 2398b850e8..8f5a96643f 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -132,9 +132,9 @@ ol.interaction.Select.prototype.handleMapBrowserEvent = /** * @param {?ol.Feature|undefined} feature Feature. - * @param {Boolean} add Add - * @param {Boolean} remove Remove - * @param {Boolean} toggle Toggle + * @param {boolean} add Add. + * @param {boolean} remove Remove. + * @param {boolean} toggle Toggle. * @private * @todo stability experimental */ From 15efba8a23a6c012416336369639783c878c0fb4 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 27 Mar 2014 19:46:52 +0100 Subject: [PATCH 2/3] Restore ol.interaction.Select options --- examples/modify-features.js | 3 - src/ol/interaction/selectinteraction.js | 125 ++++++++++-------------- 2 files changed, 49 insertions(+), 79 deletions(-) diff --git a/examples/modify-features.js b/examples/modify-features.js index de41143e24..3b4fd9627a 100644 --- a/examples/modify-features.js +++ b/examples/modify-features.js @@ -1,7 +1,6 @@ goog.require('ol.Collection'); goog.require('ol.Map'); goog.require('ol.View2D'); -goog.require('ol.events.condition'); goog.require('ol.interaction'); goog.require('ol.interaction.Modify'); goog.require('ol.interaction.Select'); @@ -31,8 +30,6 @@ var vector = new ol.layer.Vector({ }); var select = new ol.interaction.Select({ - addCondition: ol.events.condition.shiftKeyOnly, - toggleCondition: ol.events.condition.always, style: new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#3399CC', diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 8f5a96643f..9e133b100d 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -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; }; From f5e272fb3df4c532b36f4d7223c32b79471265fc Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 27 Mar 2014 19:48:28 +0100 Subject: [PATCH 3/3] Remove stray option in modify-features example --- examples/modify-features.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/modify-features.js b/examples/modify-features.js index 3b4fd9627a..0c93c7bc93 100644 --- a/examples/modify-features.js +++ b/examples/modify-features.js @@ -14,7 +14,6 @@ goog.require('ol.style.Style'); var raster = new ol.layer.Tile({ - style: 'Aerial', source: new ol.source.MapQuest({ layer: 'sat' })