diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 239ecf8a23..8b94acbd1f 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -244,7 +244,7 @@ /** * @typedef {Object} ol.interaction.DragPanOptions * @property {ol.Kinetic|undefined} kinetic Kinetic. - * @property {ol.interaction.ConditionType|undefined} condition Conditon. + * @property {ol.interaction.ConditionType|undefined} condition Condition. */ /** @@ -297,6 +297,7 @@ /** * @typedef {Object} ol.interaction.SelectOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. * @property {undefined|function(ol.layer.Layer):boolean} layerFilter Filter * function to restrict selection to a subset of layers. */ diff --git a/src/ol/interaction/condition.js b/src/ol/interaction/condition.js index 78719a8c89..78f5d4fb11 100644 --- a/src/ol/interaction/condition.js +++ b/src/ol/interaction/condition.js @@ -1,7 +1,7 @@ goog.provide('ol.interaction.ConditionType'); goog.provide('ol.interaction.condition'); -goog.require('goog.dom.TagName'); +goog.require('goog.events.EventType'); goog.require('goog.functions'); @@ -42,6 +42,15 @@ ol.interaction.condition.altShiftKeysOnly = function(browserEvent) { ol.interaction.condition.always = goog.functions.TRUE; +/** + * @param {goog.events.BrowserEvent} browserEvent Browser event. + * @return {boolean} True if only the shift key is pressed. + */ +ol.interaction.condition.clickEventOnly = function(browserEvent) { + return browserEvent.type == goog.events.EventType.CLICK; +}; + + /** * @param {goog.events.BrowserEvent} browserEvent Browser event. * @return {boolean} True if only the no modifier keys are pressed. diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index f86af24bd6..095f271ee1 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -4,7 +4,7 @@ goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.events.EventType'); -goog.require('ol.MapBrowserEvent.EventType'); +goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.condition'); goog.require('ol.layer.Vector'); @@ -31,6 +31,13 @@ ol.interaction.SelectEventObject; ol.interaction.Select = function(opt_options) { var options = goog.isDef(opt_options) ? opt_options : {}; + /** + * @private + * @type {ol.interaction.ConditionType} + */ + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.clickEventOnly; + /** * Mapping between original features and cloned features on selection layers. * @type {Object.<*,Object.<*,ol.Feature>>} @@ -76,13 +83,14 @@ ol.interaction.Select.prototype.disposeInternal = function() { * @inheritDoc. */ ol.interaction.Select.prototype.handleMapBrowserEvent = function(evt) { - if (evt.type === ol.MapBrowserEvent.EventType.CLICK) { + var browserEvent = evt.browserEvent; + if (this.condition_(browserEvent)) { var map = evt.map; var layers = map.getLayerGroup().getLayersArray(); if (!goog.isNull(this.layerFilter_)) { layers = goog.array.filter(layers, this.layerFilter_); } - var clear = !ol.interaction.condition.shiftKeyOnly(evt.browserEvent); + var clear = !ol.interaction.condition.shiftKeyOnly(browserEvent); var select = function(featuresByLayer) { this.select(map, featuresByLayer, layers, clear);