Support nudging while moving ways. Fixes #533

This commit is contained in:
Tom MacWright
2013-02-05 19:09:22 -05:00
parent 356fd6edd5
commit 8f17628190

View File

@@ -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),