From c556ddd5938a89141f23ff126bed9641c9b2ffd3 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 26 Sep 2013 12:56:49 +0200 Subject: [PATCH 1/3] Skip hidden features for hit detection --- src/ol/renderer/canvas/canvasvectorlayerrenderer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ol/renderer/canvas/canvasvectorlayerrenderer.js b/src/ol/renderer/canvas/canvasvectorlayerrenderer.js index f8aa6fd19f..a7908ed084 100644 --- a/src/ol/renderer/canvas/canvasvectorlayerrenderer.js +++ b/src/ol/renderer/canvas/canvasvectorlayerrenderer.js @@ -14,6 +14,7 @@ goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); goog.require('ol.layer.Vector'); goog.require('ol.layer.VectorLayerEventType'); +goog.require('ol.layer.VectorLayerRenderIntent'); goog.require('ol.renderer.canvas.Layer'); goog.require('ol.renderer.canvas.VectorRenderer'); goog.require('ol.tilegrid.TileGrid'); @@ -271,6 +272,9 @@ ol.renderer.canvas.VectorLayer.prototype.getFeaturesForPixel = halfWidth, halfHeight, uid, coordinates, j; for (var id in candidates) { candidate = candidates[id]; + if (candidate.renderIntent == ol.layer.VectorLayerRenderIntent.HIDDEN) { + continue; + } geom = candidate.getGeometry(); type = geom.getType(); if (type === ol.geom.GeometryType.POINT || From f8e891ff15acbb75723324804fdf8d714fa44f67 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 27 Sep 2013 11:45:15 +0200 Subject: [PATCH 2/3] Making the condition for adding to selection configurable --- src/objectliterals.jsdoc | 7 +++++-- src/ol/interaction/selectinteraction.js | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 289dedd51f..840cbb3584 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -311,9 +311,12 @@ /** * @typedef {Object} ol.interaction.SelectOptions + * @property {ol.interaction.ConditionType|undefined} addCondition A conditional + * modifier (e.g. shift key) that determines if the selection is added to + * the current selection. Default is when holding the shift key only. * @property {ol.interaction.ConditionType|undefined} condition A conditional - * modifier (i.e. Shift key) that determines if the interaction is active - * or not, default is on mouse click only. + * modifier (e.g. shift key) that determines if the interaction is active + * (i.e. selection occurs) or not. Default is on mouse click only. * @property {undefined|function(ol.layer.Layer):boolean} layerFilter Filter * function to restrict selection to a subset of layers. */ diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index ee157b5049..813e6d1e0f 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -28,6 +28,13 @@ ol.interaction.Select = function(opt_options) { this.condition_ = goog.isDef(options.condition) ? options.condition : ol.interaction.condition.clickOnly; + /** + * @private + * @type {ol.interaction.ConditionType} + */ + this.addCondition_ = goog.isDef(options.addCondition) ? + options.addCondition : ol.interaction.condition.shiftKeyOnly; + /** * Mapping between original features and cloned features on selection layers. * @type {Object.<*,Object.<*,ol.Feature>>} @@ -65,7 +72,7 @@ ol.interaction.Select.prototype.handleMapBrowserEvent = if (!goog.isNull(this.layerFilter_)) { layers = goog.array.filter(layers, this.layerFilter_); } - var clear = !ol.interaction.condition.shiftKeyOnly(mapBrowserEvent); + var clear = !this.addCondition_(mapBrowserEvent); var that = this; var select = function(featuresByLayer) { From 6c6f9a3ef599081dcae7f9d4c64e0e5693192b5f Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 27 Sep 2013 12:11:41 +0200 Subject: [PATCH 3/3] Doc improvements Thanks @tschaub for suggesting these. --- src/objectliterals.jsdoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 840cbb3584..5364c0fa17 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -313,10 +313,12 @@ * @typedef {Object} ol.interaction.SelectOptions * @property {ol.interaction.ConditionType|undefined} addCondition A conditional * modifier (e.g. shift key) that determines if the selection is added to - * the current selection. Default is when holding the shift key only. + * the current selection. By default, a shift-click adds to the current + * selection. * @property {ol.interaction.ConditionType|undefined} condition A conditional * modifier (e.g. shift key) that determines if the interaction is active - * (i.e. selection occurs) or not. Default is on mouse click only. + * (i.e. selection occurs) or not. By default, a click with no modifier keys + * toggles the selection. * @property {undefined|function(ol.layer.Layer):boolean} layerFilter Filter * function to restrict selection to a subset of layers. */