Making the draw interaction work with pointer events

This is not yet optimized for mobile, and tests need to be
updated.
This commit is contained in:
ahocevar
2014-03-04 22:13:24 +01:00
committed by tsauerwein
parent be1318f133
commit d6880039cc
2 changed files with 34 additions and 20 deletions

View File

@@ -17,7 +17,7 @@ goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.MultiPolygon');
goog.require('ol.geom.Point'); goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon'); goog.require('ol.geom.Polygon');
goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Pointer');
goog.require('ol.source.Vector'); goog.require('ol.source.Vector');
goog.require('ol.style.Circle'); goog.require('ol.style.Circle');
goog.require('ol.style.Fill'); goog.require('ol.style.Fill');
@@ -59,7 +59,7 @@ goog.inherits(ol.DrawEvent, goog.events.Event);
/** /**
* Interaction that allows drawing geometries * Interaction that allows drawing geometries
* @constructor * @constructor
* @extends {ol.interaction.Interaction} * @extends {ol.interaction.Pointer}
* @param {olx.interaction.DrawOptions} options Options. * @param {olx.interaction.DrawOptions} options Options.
* @todo stability experimental * @todo stability experimental
*/ */
@@ -67,6 +67,12 @@ ol.interaction.Draw = function(options) {
goog.base(this); goog.base(this);
/**
* @type {ol.Pixel}
* @private
*/
this.downPx_ = null;
/** /**
* Target source for drawn features. * Target source for drawn features.
* @type {ol.source.Vector} * @type {ol.source.Vector}
@@ -149,8 +155,8 @@ ol.interaction.Draw = function(options) {
this.sketchRawPolygon_ = null; this.sketchRawPolygon_ = null;
/** /**
* Squared tolerance for handling click events. If the squared distance * Squared tolerance for handling up events. If the squared distance
* between a down and click event is greater than this tolerance, click events * between a down and up event is greater than this tolerance, up events
* will not be handled. * will not be handled.
* @type {number} * @type {number}
* @private * @private
@@ -168,7 +174,7 @@ ol.interaction.Draw = function(options) {
}); });
}; };
goog.inherits(ol.interaction.Draw, ol.interaction.Interaction); goog.inherits(ol.interaction.Draw, ol.interaction.Pointer);
/** /**
@@ -250,25 +256,33 @@ ol.interaction.Draw.prototype.handleMapBrowserEvent = function(event) {
return true; return true;
} }
var pass = true; var pass = true;
if (event.type === ol.MapBrowserEvent.EventType.CLICK) { if (event.type === ol.MapBrowserEvent.EventType.POINTERMOVE) {
pass = this.handleClick_(event); pass = this.handlePointerMove_(event);
} else if (event.type === ol.MapBrowserEvent.EventType.MOUSEMOVE) {
pass = this.handleMove_(event);
} else if (event.type === ol.MapBrowserEvent.EventType.DBLCLICK) { } else if (event.type === ol.MapBrowserEvent.EventType.DBLCLICK) {
pass = false; pass = false;
} }
return pass; return (goog.base(this, 'handleMapBrowserEvent', event) && pass);
}; };
/** /**
* Handle click events. * Handle down events.
* @param {ol.MapBrowserEvent} event A click event. * @param {ol.MapBrowserEvent} event A down event.
* @return {boolean} Pass the event to other interactions. * @return {boolean} Pass the event to other interactions.
* @private
*/ */
ol.interaction.Draw.prototype.handleClick_ = function(event) { ol.interaction.Draw.prototype.handlePointerDown = function(event) {
var downPx = event.map.getEventPixel(event.target.getDown()); this.downPx_ = event.pixel;
return true;
};
/**
* Handle up events.
* @param {ol.MapBrowserEvent} event An up event.
* @return {boolean} Pass the event to other interactions.
*/
ol.interaction.Draw.prototype.handlePointerUp = function(event) {
var downPx = this.downPx_;
var clickPx = event.pixel; var clickPx = event.pixel;
var dx = downPx[0] - clickPx[0]; var dx = downPx[0] - clickPx[0];
var dy = downPx[1] - clickPx[1]; var dy = downPx[1] - clickPx[1];
@@ -290,12 +304,12 @@ ol.interaction.Draw.prototype.handleClick_ = function(event) {
/** /**
* Handle mousemove events. * Handle move events.
* @param {ol.MapBrowserEvent} event A mousemove event. * @param {ol.MapBrowserEvent} event A move event.
* @return {boolean} Pass the event to other interactions. * @return {boolean} Pass the event to other interactions.
* @private * @private
*/ */
ol.interaction.Draw.prototype.handleMove_ = function(event) { ol.interaction.Draw.prototype.handlePointerMove_ = function(event) {
if (this.mode_ === ol.interaction.DrawMode.POINT && if (this.mode_ === ol.interaction.DrawMode.POINT &&
goog.isNull(this.finishCoordinate_)) { goog.isNull(this.finishCoordinate_)) {
this.startDrawing_(event); this.startDrawing_(event);

View File

@@ -478,8 +478,8 @@ ol.interaction.Modify.prototype.handleMapBrowserEvent =
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) { mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
this.handlePointerMove_(mapBrowserEvent); this.handlePointerMove_(mapBrowserEvent);
} }
goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent); return (goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent) &&
return !this.modifiable_; !this.modifiable_);
}; };