Merge pull request #1137 from fredj/dragbox_condition
Add new condition param to ol.control.DragBox
This commit is contained in:
@@ -11,10 +11,13 @@ goog.require('ol.MapBrowserEvent');
|
|||||||
goog.require('ol.MapBrowserEvent.EventType');
|
goog.require('ol.MapBrowserEvent.EventType');
|
||||||
goog.require('ol.Pixel');
|
goog.require('ol.Pixel');
|
||||||
goog.require('ol.control.Control');
|
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;
|
ol.control.DragBoxOptions;
|
||||||
|
|
||||||
@@ -29,6 +32,13 @@ ol.control.DragBox = function(options) {
|
|||||||
|
|
||||||
var element = goog.dom.createDom(goog.dom.TagName.DIV, 'ol-dragbox');
|
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}
|
* @type {ol.Pixel|undefined}
|
||||||
* @private
|
* @private
|
||||||
@@ -71,14 +81,16 @@ ol.control.DragBox.prototype.setMap = function(map) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.control.DragBox.prototype.updateBox_ = function(mapBrowserEvent) {
|
ol.control.DragBox.prototype.updateBox_ = function(mapBrowserEvent) {
|
||||||
var map = this.getMap();
|
if (this.condition_(mapBrowserEvent)) {
|
||||||
var coordinate = mapBrowserEvent.getCoordinate();
|
var map = this.getMap();
|
||||||
goog.asserts.assert(goog.isDef(coordinate));
|
var coordinate = mapBrowserEvent.getCoordinate();
|
||||||
var currentPixel = map.getPixelFromCoordinate(coordinate);
|
goog.asserts.assert(goog.isDef(coordinate));
|
||||||
goog.style.setPosition(this.element,
|
var currentPixel = map.getPixelFromCoordinate(coordinate);
|
||||||
Math.min(currentPixel[0], this.startPixel_[0]),
|
goog.style.setPosition(this.element,
|
||||||
Math.min(currentPixel[1], this.startPixel_[1]));
|
Math.min(currentPixel[0], this.startPixel_[0]),
|
||||||
goog.style.setBorderBoxSize(this.element, new goog.math.Size(
|
Math.min(currentPixel[1], this.startPixel_[1]));
|
||||||
Math.abs(currentPixel[0] - this.startPixel_[0]),
|
goog.style.setBorderBoxSize(this.element, new goog.math.Size(
|
||||||
Math.abs(currentPixel[1] - this.startPixel_[1])));
|
Math.abs(currentPixel[0] - this.startPixel_[0]),
|
||||||
|
Math.abs(currentPixel[1] - this.startPixel_[1])));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user