From 8f17628190b603f243c81e04fc2efb518be49800 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 5 Feb 2013 19:09:22 -0500 Subject: [PATCH] Support nudging while moving ways. Fixes #533 --- js/id/modes/move_way.js | 42 ++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/js/id/modes/move_way.js b/js/id/modes/move_way.js index 986eef5bd..e21dded78 100644 --- a/js/id/modes/move_way.js +++ b/js/id/modes/move_way.js @@ -6,7 +6,8 @@ iD.modes.MoveWay = function(context, wayId) { var keybinding = d3.keybinding('move-way'); mode.enter = function() { - var origin = point(), + var origin = context.map().mouseCoordinates(), + nudgeInterval, annotation = t('operations.move.annotation.' + context.geometry(wayId)); // If intiated via keyboard @@ -16,17 +17,44 @@ iD.modes.MoveWay = function(context, wayId) { iD.actions.Noop(), annotation); + function edge(point, size) { + var pad = [30, 100, 30, 100]; + if (point[0] > size[0] - pad[0]) return [-10, 0]; + else if (point[0] < pad[2]) return [10, 0]; + else if (point[1] > size[1] - pad[1]) return [0, -10]; + else if (point[1] < pad[3]) return [0, 10]; + return null; + } + + function startNudge(nudge) { + if (nudgeInterval) window.clearInterval(nudgeInterval); + nudgeInterval = window.setInterval(function() { + context.map().pan(nudge).redraw(); + }, 50); + } + + function stopNudge() { + if (nudgeInterval) window.clearInterval(nudgeInterval); + nudgeInterval = null; + } + function point() { - return d3.mouse(context.surface().node()); + return d3.mouse(context.map().surface.node()); } function move() { - var p = point(), - delta = origin ? - [p[0] - origin[0], p[1] - origin[1]] : - [0, 0]; + var p = point(); - origin = p; + var delta = origin ? + [p[0] - context.projection(origin)[0], + p[1] - context.projection(origin)[1]] : + [0, 0]; + + var nudge = edge(p, context.map().size()); + if (nudge) startNudge(nudge); + else stopNudge(); + + origin = context.map().mouseCoordinates(); context.replace( iD.actions.MoveWay(wayId, delta, context.projection),