Use a ol.interaction.condition in ol.interaction.Select

This commit is contained in:
Frederic Junod
2013-08-28 15:33:15 +02:00
committed by ahocevar
parent bb93a86528
commit 89bdd3bc2c
3 changed files with 23 additions and 5 deletions

View File

@@ -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.
*/

View File

@@ -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.

View File

@@ -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);