Visual feedback for removeLastPoint() on touch devices

This commit is contained in:
Andreas Hocevar
2020-10-29 22:06:51 +01:00
parent 23a544aa30
commit 48f357d518
+22 -2
View File
@@ -215,6 +215,13 @@ class Draw extends PointerInteraction {
*/ */
this.lastDragTime_; this.lastDragTime_;
/**
* Pointer type of the last pointermove event
* @type {string}
* @private
*/
this.pointerType_;
/** /**
* @type {boolean} * @type {boolean}
* @private * @private
@@ -535,7 +542,7 @@ class Draw extends PointerInteraction {
event.type === MapBrowserEventType.POINTERDOWN event.type === MapBrowserEventType.POINTERDOWN
) { ) {
pass = false; pass = false;
} else if (move && this.getPointerCount() === 1) { } else if (move && this.getPointerCount() < 2) {
pass = event.type === MapBrowserEventType.POINTERMOVE; pass = event.type === MapBrowserEventType.POINTERMOVE;
if (pass && this.freehand_) { if (pass && this.freehand_) {
this.handlePointerMove_(event); this.handlePointerMove_(event);
@@ -646,6 +653,7 @@ class Draw extends PointerInteraction {
* @private * @private
*/ */
handlePointerMove_(event) { handlePointerMove_(event) {
this.pointerType_ = event.originalEvent.pointerType;
if ( if (
this.downPx_ && this.downPx_ &&
((!this.freehand_ && this.shouldHandle_) || ((!this.freehand_ && this.shouldHandle_) ||
@@ -887,14 +895,26 @@ class Draw extends PointerInteraction {
if (this.mode_ === Mode.LINE_STRING) { if (this.mode_ === Mode.LINE_STRING) {
coordinates = /** @type {LineCoordType} */ (this.sketchCoords_); coordinates = /** @type {LineCoordType} */ (this.sketchCoords_);
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
this.geometryFunction_(coordinates, geometry, projection);
if (coordinates.length >= 2) { if (coordinates.length >= 2) {
this.finishCoordinate_ = coordinates[coordinates.length - 2].slice(); this.finishCoordinate_ = coordinates[coordinates.length - 2].slice();
if (this.pointerType_ !== 'mouse') {
const finishCoordinate = this.finishCoordinate_.slice();
coordinates.pop();
coordinates.push(finishCoordinate);
this.sketchPoint_.setGeometry(new Point(finishCoordinate));
}
} }
this.geometryFunction_(coordinates, geometry, projection);
} else if (this.mode_ === Mode.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
sketchLineGeom = this.sketchLine_.getGeometry(); sketchLineGeom = this.sketchLine_.getGeometry();
if (this.pointerType_ !== 'mouse') {
const finishCoordinate = coordinates[coordinates.length - 2].slice();
coordinates.pop();
coordinates.push(finishCoordinate);
this.sketchPoint_.setGeometry(new Point(finishCoordinate));
}
sketchLineGeom.setCoordinates(coordinates); sketchLineGeom.setCoordinates(coordinates);
this.geometryFunction_(this.sketchCoords_, geometry, projection); this.geometryFunction_(this.sketchCoords_, geometry, projection);
} }