diff --git a/examples/select-features.html b/examples/select-features.html index 3b84401fcc..353183ecef 100644 --- a/examples/select-features.html +++ b/examples/select-features.html @@ -35,6 +35,7 @@
Example of using the Select interaction. Choose between Single-click, Click and Hover as the event type for selection in the combobox below. When using Single-click or Click you can hold do Shift key to toggle the feature in the selection.
Note: when Single-click is used double-clicks won't select features. This in contrast to Click, where a double-click will both select the feature and zoom the map (because of the DoubleClickZoom interaction). Note that Single-click is less responsive than Click because of the delay it uses to detect double-clicks.
In this example, a listener is registered for the Select interaction's select event in order to update the selection status below.
See the select-features.js source to see how this is done.
diff --git a/examples/select-features.js b/examples/select-features.js index 0c8cea6882..7adbdff529 100644 --- a/examples/select-features.js +++ b/examples/select-features.js @@ -61,6 +61,11 @@ var changeInteraction = function() { } if (select !== null) { map.addInteraction(select); + select.on('select', function(e) { + $('#status').html(' ' + e.target.getFeatures().getLength() + + ' selected features (last operation selected ' + e.selected.length + + ' and deselected ' + e.deselected.length + ' features)'); + }); } }; diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 0391cce51d..9406c9df65 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -3,6 +3,7 @@ goog.provide('ol.interaction.Select'); goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events'); +goog.require('goog.events.Event'); goog.require('goog.functions'); goog.require('ol.CollectionEventType'); goog.require('ol.Feature'); @@ -13,6 +14,51 @@ goog.require('ol.interaction.Interaction'); goog.require('ol.style.Style'); +/** + * @enum {string} + */ +ol.SelectEventType = { + /** + * Triggered when feature(s) has been (de)selected. + * @event ol.SelectEvent#select + * @api + */ + SELECT: 'select' +}; + + + +/** + * @classdesc + * Events emitted by {@link ol.interaction.Select} instances are instances of + * this type. + * + * @param {string} type The event type. + * @param {Array.