Add click tolerance to allow dragging while drawing

This commit is contained in:
Tim Schaub
2013-11-11 14:35:47 -07:00
parent 2f07433593
commit 62b44f3c73
+19 -1
View File
@@ -78,6 +78,15 @@ ol.interaction.Draw = function(options) {
*/ */
this.sketchPoint_ = null; this.sketchPoint_ = null;
/**
* Squared tolerance for handling click events. If the squared distance
* between a down and click event is greater than this tolerance, click events
* will not be handled.
* @type {number}
* @private
*/
this.squaredClickTolerance_ = 4;
}; };
goog.inherits(ol.interaction.Draw, ol.interaction.Interaction); goog.inherits(ol.interaction.Draw, ol.interaction.Interaction);
@@ -138,6 +147,13 @@ ol.interaction.Draw.prototype.handleMapBrowserEvent = function(event) {
* @private * @private
*/ */
ol.interaction.Draw.prototype.handleClick_ = function(event) { ol.interaction.Draw.prototype.handleClick_ = function(event) {
var downPx = event.map.getEventPixel(event.target.getDown());
var clickPx = event.getPixel();
var dx = downPx[0] - clickPx[0];
var dy = downPx[1] - clickPx[1];
var squaredDistance = dx * dx + dy * dy;
var pass = true;
if (squaredDistance <= this.squaredClickTolerance_) {
if (goog.isNull(this.finishCoordinate_)) { if (goog.isNull(this.finishCoordinate_)) {
this.startDrawing_(event); this.startDrawing_(event);
} else if (this.mode_ === ol.interaction.DrawMode.POINT || } else if (this.mode_ === ol.interaction.DrawMode.POINT ||
@@ -146,7 +162,9 @@ ol.interaction.Draw.prototype.handleClick_ = function(event) {
} else { } else {
this.addToDrawing_(event); this.addToDrawing_(event);
} }
return false; pass = false;
}
return pass;
}; };