From 5c6c555b62e8eb0b50ad4f7b283a44136ad17955 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 7 Apr 2017 15:31:59 +0200 Subject: [PATCH] Remove ol.DRAG_BOX_HYSTERESIS_PIXELS define and add option --- externs/olx.js | 23 ++++++++++++----------- src/ol/index.js | 6 ------ src/ol/interaction/dragbox.js | 21 ++++++++------------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 9c4bccc627..6317e51f55 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -2550,6 +2550,7 @@ olx.interaction.DragAndDropOptions.prototype.target; /** * @typedef {{className: (string|undefined), * condition: (ol.EventsConditionType|undefined), + * minArea: (number|undefined), * boxEndCondition: (ol.DragBoxEndConditionType|undefined)}} */ olx.interaction.DragBoxOptions; @@ -2573,19 +2574,19 @@ olx.interaction.DragBoxOptions.prototype.className; olx.interaction.DragBoxOptions.prototype.condition; +/** + * The minimum area of the box in pixel, this value is used by the default + * `boxEndCondition` function. Default is `64`. + * @type {number|undefined} + * @api + */ +olx.interaction.DragBoxOptions.prototype.minArea; + + /** * A function that takes a {@link ol.MapBrowserEvent} and two - * {@link ol.Pixel}s to indicate whether a boxend event should be fired. - * Default is: - * ```js - * function(mapBrowserEvent, - * startPixel, endPixel) { - * var width = endPixel[0] - startPixel[0]; - * var height = endPixel[1] - startPixel[1]; - * return width * width + height * height >= - * ol.DRAG_BOX_HYSTERESIS_PIXELS_SQUARED; - * } - * ``` + * {@link ol.Pixel}s to indicate whether a `boxend` event should be fired. + * Default is `true` if the area of the box is bigger than the `minArea` option. * @type {ol.DragBoxEndConditionType|undefined} * @api */ diff --git a/src/ol/index.js b/src/ol/index.js index 689c5c97a5..a210863de8 100644 --- a/src/ol/index.js +++ b/src/ol/index.js @@ -47,12 +47,6 @@ ol.DEFAULT_TILE_SIZE = 256; ol.DEFAULT_WMS_VERSION = '1.3.0'; -/** - * @define {number} Hysteresis pixels. - */ -ol.DRAG_BOX_HYSTERESIS_PIXELS = 8; - - /** * @define {boolean} Enable the Canvas renderer. Default is `true`. Setting * this to false at compile time in advanced mode removes all code diff --git a/src/ol/interaction/dragbox.js b/src/ol/interaction/dragbox.js index 90b67d70cf..6883dfa73f 100644 --- a/src/ol/interaction/dragbox.js +++ b/src/ol/interaction/dragbox.js @@ -8,15 +8,6 @@ goog.require('ol.interaction.Pointer'); goog.require('ol.render.Box'); -/** - * @const - * @type {number} - */ -ol.DRAG_BOX_HYSTERESIS_PIXELS_SQUARED = - ol.DRAG_BOX_HYSTERESIS_PIXELS * - ol.DRAG_BOX_HYSTERESIS_PIXELS; - - /** * @classdesc * Allows the user to draw a vector box by clicking and dragging on the map, @@ -50,6 +41,12 @@ ol.interaction.DragBox = function(opt_options) { */ this.box_ = new ol.render.Box(options.className || 'ol-dragbox'); + /** + * @type {number} + * @private + */ + this.minArea_ = options.minArea !== undefined ? options.minArea : 64; + /** * @type {ol.Pixel} * @private @@ -82,12 +79,10 @@ ol.inherits(ol.interaction.DragBox, ol.interaction.Pointer); * @param {ol.Pixel} endPixel The end pixel of the box. * @return {boolean} Whether or not the boxend condition should be fired. */ -ol.interaction.DragBox.defaultBoxEndCondition = function(mapBrowserEvent, - startPixel, endPixel) { +ol.interaction.DragBox.defaultBoxEndCondition = function(mapBrowserEvent, startPixel, endPixel) { var width = endPixel[0] - startPixel[0]; var height = endPixel[1] - startPixel[1]; - return width * width + height * height >= - ol.DRAG_BOX_HYSTERESIS_PIXELS_SQUARED; + return width * width + height * height >= this.minArea_; };