From 7ff0247b00b3b948463ed5fad965ff251764e716 Mon Sep 17 00:00:00 2001 From: Andrew Vardeman Date: Thu, 4 Apr 2013 11:03:13 -0500 Subject: [PATCH] Account for the fact that touch devices have no mouse and therefore no last mouse position. When "undo" is invoked in a mobile app, sync the meaningless last-mouse-position point to the last point in the digitized linestring so there is visible feedback that something has been undone. Otherwise the last-mouse-position point is left at the point of the last tap on the map, which is unfortunately the location of the vertex that has just been undone, incorrectly implying that the vertex is still there. --- lib/OpenLayers/Handler/Path.js | 10 ++++++++++ tests/Handler/Path.html | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Handler/Path.js b/lib/OpenLayers/Handler/Path.js index 49ec8ee387..28512a152e 100644 --- a/lib/OpenLayers/Handler/Path.js +++ b/lib/OpenLayers/Handler/Path.js @@ -271,6 +271,16 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { var target = components[index]; var undone = geometry.removeComponent(target); if (undone) { + // On touch devices, set the current ("mouse location") point to + // match the last digitized point. + if (this.touch && index > 0) { + components = geometry.components; // safety + var lastpt = components[index - 1]; + var curptidx = this.getCurrentPointIndex(); + var curpt = components[curptidx]; + curpt.x = lastpt.x; + curpt.y = lastpt.y; + } if (!this.redoStack) { this.redoStack = []; } diff --git a/tests/Handler/Path.html b/tests/Handler/Path.html index 66548d624a..8351eea267 100644 --- a/tests/Handler/Path.html +++ b/tests/Handler/Path.html @@ -601,6 +601,12 @@ handler.mousedown({type: "mousedown", xy: px}); handler.mouseup({type: "mouseup", xy: px}); } + function userTap(handler, x, y) { + var px = new OpenLayers.Pixel(x, y); + handler.touchstart({xy: px}); + handler.touchmove({xy: px}); + handler.touchend({}); + } /** * Editing method tests: insertXY, insertDeltaXY, insertDirectionXY, @@ -720,7 +726,7 @@ } function test_undoredo1(t) { - t.plan(4); + t.plan(5); var obj = editingMethodsSetup(); var map = obj.map; var handler = obj.handler; @@ -747,6 +753,17 @@ handler.redo(); t.geom_eq(original, handler.line.geometry, "one redo undoes one undo"); + // add point via touch + userTap(handler, 10, 50); + handler.undo(); + currentLen = handler.line.geometry.components.length; + t.geom_eq( + handler.line.geometry.components[currentLen-1], + handler.line.geometry.components[currentLen-2], + "current point (mouse position) is set to the last digitized " + + "point after undo on touch devices" + ); + // cleanup map.destroy(); }