Merge pull request #1137 from fredj/dragbox_condition

Add new condition param to ol.control.DragBox
This commit is contained in:
Frédéric Junod
2013-10-17 23:48:34 -07:00
+13 -1
View File
@@ -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,6 +81,7 @@ ol.control.DragBox.prototype.setMap = function(map) {
* @private
*/
ol.control.DragBox.prototype.updateBox_ = function(mapBrowserEvent) {
if (this.condition_(mapBrowserEvent)) {
var map = this.getMap();
var coordinate = mapBrowserEvent.getCoordinate();
goog.asserts.assert(goog.isDef(coordinate));
@@ -81,4 +92,5 @@ ol.control.DragBox.prototype.updateBox_ = function(mapBrowserEvent) {
goog.style.setBorderBoxSize(this.element, new goog.math.Size(
Math.abs(currentPixel[0] - this.startPixel_[0]),
Math.abs(currentPixel[1] - this.startPixel_[1])));
}
};