Merge pull request #4574 from WeaveTeam/dragbox-config-pr
Added boxEndCondition to DragBoxOptions to replace the hardcoded chec…
This commit is contained in:
+21
-1
@@ -2361,7 +2361,8 @@ olx.interaction.DragAndDropOptions.prototype.projection;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{className: (string|undefined),
|
* @typedef {{className: (string|undefined),
|
||||||
* condition: (ol.events.ConditionType|undefined)}}
|
* condition: (ol.events.ConditionType|undefined),
|
||||||
|
* boxEndCondition: (ol.interaction.DragBoxEndConditionType|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.interaction.DragBoxOptions;
|
olx.interaction.DragBoxOptions;
|
||||||
@@ -2385,6 +2386,25 @@ olx.interaction.DragBoxOptions.prototype.className;
|
|||||||
olx.interaction.DragBoxOptions.prototype.condition;
|
olx.interaction.DragBoxOptions.prototype.condition;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
* @type {ol.interaction.DragBoxEndConditionType|undefined}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
olx.interaction.DragBoxOptions.prototype.boxEndCondition;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{kinetic: (ol.Kinetic|undefined)}}
|
* @typedef {{kinetic: (ol.Kinetic|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
|
|||||||
@@ -73,6 +73,16 @@ ol.DragBoxEvent = function(type, coordinate, mapBrowserEvent) {
|
|||||||
goog.inherits(ol.DragBoxEvent, goog.events.Event);
|
goog.inherits(ol.DragBoxEvent, goog.events.Event);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that takes a {@link ol.MapBrowserEvent} and two
|
||||||
|
* {@link ol.Pixel}s and returns a `{boolean}`. If the condition is met,
|
||||||
|
* true should be returned.
|
||||||
|
* @typedef {function(ol.MapBrowserEvent, ol.Pixel, ol.Pixel):boolean}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.interaction.DragBoxEndConditionType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -120,10 +130,34 @@ ol.interaction.DragBox = function(opt_options) {
|
|||||||
this.condition_ = options.condition ?
|
this.condition_ = options.condition ?
|
||||||
options.condition : ol.events.condition.always;
|
options.condition : ol.events.condition.always;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.interaction.DragBoxEndConditionType}
|
||||||
|
*/
|
||||||
|
this.boxEndCondition_ = options.boxEndCondition ?
|
||||||
|
options.boxEndCondition : ol.interaction.DragBox.defaultBoxEndCondition;
|
||||||
};
|
};
|
||||||
goog.inherits(ol.interaction.DragBox, ol.interaction.Pointer);
|
goog.inherits(ol.interaction.DragBox, ol.interaction.Pointer);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default condition for determining whether the boxend event
|
||||||
|
* should fire.
|
||||||
|
* @param {ol.MapBrowserEvent} mapBrowserEvent The originating MapBrowserEvent
|
||||||
|
* leading to the box end.
|
||||||
|
* @param {ol.Pixel} startPixel The starting pixel of the box.
|
||||||
|
* @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) {
|
||||||
|
var width = endPixel[0] - startPixel[0];
|
||||||
|
var height = endPixel[1] - startPixel[1];
|
||||||
|
return width * width + height * height >=
|
||||||
|
ol.DRAG_BOX_HYSTERESIS_PIXELS_SQUARED;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||||
* @this {ol.interaction.DragBox}
|
* @this {ol.interaction.DragBox}
|
||||||
@@ -170,11 +204,8 @@ ol.interaction.DragBox.handleUpEvent_ = function(mapBrowserEvent) {
|
|||||||
|
|
||||||
this.box_.setMap(null);
|
this.box_.setMap(null);
|
||||||
|
|
||||||
var deltaX = mapBrowserEvent.pixel[0] - this.startPixel_[0];
|
if (this.boxEndCondition_(mapBrowserEvent,
|
||||||
var deltaY = mapBrowserEvent.pixel[1] - this.startPixel_[1];
|
this.startPixel_, mapBrowserEvent.pixel)) {
|
||||||
|
|
||||||
if (deltaX * deltaX + deltaY * deltaY >=
|
|
||||||
ol.DRAG_BOX_HYSTERESIS_PIXELS_SQUARED) {
|
|
||||||
this.onBoxEnd(mapBrowserEvent);
|
this.onBoxEnd(mapBrowserEvent);
|
||||||
this.dispatchEvent(new ol.DragBoxEvent(ol.DragBoxEventType.BOXEND,
|
this.dispatchEvent(new ol.DragBoxEvent(ol.DragBoxEventType.BOXEND,
|
||||||
mapBrowserEvent.coordinate, mapBrowserEvent));
|
mapBrowserEvent.coordinate, mapBrowserEvent));
|
||||||
|
|||||||
Reference in New Issue
Block a user