Add new condition param to ol.control.DragBox

This commit is contained in:
Frederic Junod
2013-10-17 07:39:49 +02:00
parent 33f426fd85
commit ade9984872

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,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])));
}
};