From ade99848722e3abae5a67941998ae9615d87ab0d Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 17 Oct 2013 07:39:49 +0200 Subject: [PATCH] Add new condition param to ol.control.DragBox --- src/ol/control/dragboxcontrol.js | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ol/control/dragboxcontrol.js b/src/ol/control/dragboxcontrol.js index a6a405b5a1..18bf8ad5c9 100644 --- a/src/ol/control/dragboxcontrol.js +++ b/src/ol/control/dragboxcontrol.js @@ -11,10 +11,13 @@ goog.require('ol.MapBrowserEvent'); goog.require('ol.MapBrowserEvent.EventType'); goog.require('ol.Pixel'); goog.require('ol.control.Control'); +goog.require('ol.interaction.ConditionType'); +goog.require('ol.interaction.condition'); /** - * @typedef {{startCoordinate: ol.Coordinate}} + * @typedef {{startCoordinate: ol.Coordinate, + * condition: (ol.interaction.ConditionType|undefined)}} */ ol.control.DragBoxOptions; @@ -29,6 +32,13 @@ ol.control.DragBox = function(options) { var element = goog.dom.createDom(goog.dom.TagName.DIV, 'ol-dragbox'); + /** + * @private + * @type {ol.interaction.ConditionType} + */ + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.always; + /** * @type {ol.Pixel|undefined} * @private @@ -71,14 +81,16 @@ ol.control.DragBox.prototype.setMap = function(map) { * @private */ ol.control.DragBox.prototype.updateBox_ = function(mapBrowserEvent) { - var map = this.getMap(); - var coordinate = mapBrowserEvent.getCoordinate(); - goog.asserts.assert(goog.isDef(coordinate)); - var currentPixel = map.getPixelFromCoordinate(coordinate); - goog.style.setPosition(this.element, - Math.min(currentPixel[0], this.startPixel_[0]), - Math.min(currentPixel[1], this.startPixel_[1])); - goog.style.setBorderBoxSize(this.element, new goog.math.Size( - Math.abs(currentPixel[0] - this.startPixel_[0]), - Math.abs(currentPixel[1] - this.startPixel_[1]))); + if (this.condition_(mapBrowserEvent)) { + var map = this.getMap(); + var coordinate = mapBrowserEvent.getCoordinate(); + goog.asserts.assert(goog.isDef(coordinate)); + var currentPixel = map.getPixelFromCoordinate(coordinate); + goog.style.setPosition(this.element, + Math.min(currentPixel[0], this.startPixel_[0]), + Math.min(currentPixel[1], this.startPixel_[1])); + goog.style.setBorderBoxSize(this.element, new goog.math.Size( + Math.abs(currentPixel[0] - this.startPixel_[0]), + Math.abs(currentPixel[1] - this.startPixel_[1]))); + } };