mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 01:33:03 +00:00
Stop nudge when exiting move mode (fixes #1766)
This commit is contained in:
@@ -5,82 +5,81 @@ iD.modes.Move = function(context, entityIDs) {
|
||||
};
|
||||
|
||||
var keybinding = d3.keybinding('move'),
|
||||
edit = iD.behavior.Edit(context);
|
||||
edit = iD.behavior.Edit(context),
|
||||
annotation = entityIDs.length === 1 ?
|
||||
t('operations.move.annotation.' + context.geometry(entityIDs[0])) :
|
||||
t('operations.move.annotation.multiple'),
|
||||
origin,
|
||||
nudgeInterval;
|
||||
|
||||
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.pan(nudge);
|
||||
context.replace(
|
||||
iD.actions.Move(entityIDs, [-nudge[0], -nudge[1]], context.projection),
|
||||
annotation);
|
||||
var c = context.projection(origin);
|
||||
origin = context.projection.invert([c[0] - nudge[0], c[1] - nudge[1]]);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function stopNudge() {
|
||||
if (nudgeInterval) window.clearInterval(nudgeInterval);
|
||||
nudgeInterval = null;
|
||||
}
|
||||
|
||||
function move() {
|
||||
var p = context.mouse();
|
||||
|
||||
var delta = origin ?
|
||||
[p[0] - context.projection(origin)[0],
|
||||
p[1] - context.projection(origin)[1]] :
|
||||
[0, 0];
|
||||
|
||||
var nudge = edge(p, context.map().dimensions());
|
||||
if (nudge) startNudge(nudge);
|
||||
else stopNudge();
|
||||
|
||||
origin = context.map().mouseCoordinates();
|
||||
|
||||
context.replace(
|
||||
iD.actions.Move(entityIDs, delta, context.projection),
|
||||
annotation);
|
||||
}
|
||||
|
||||
function finish() {
|
||||
d3.event.stopPropagation();
|
||||
context.enter(iD.modes.Select(context, entityIDs));
|
||||
stopNudge();
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
context.pop();
|
||||
context.enter(iD.modes.Select(context, entityIDs));
|
||||
stopNudge();
|
||||
}
|
||||
|
||||
function undone() {
|
||||
context.enter(iD.modes.Browse(context));
|
||||
}
|
||||
|
||||
mode.enter = function() {
|
||||
context.install(edit);
|
||||
|
||||
var origin,
|
||||
nudgeInterval,
|
||||
annotation = entityIDs.length === 1 ?
|
||||
t('operations.move.annotation.' + context.geometry(entityIDs[0])) :
|
||||
t('operations.move.annotation.multiple');
|
||||
|
||||
context.perform(
|
||||
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.pan(nudge);
|
||||
context.replace(
|
||||
iD.actions.Move(entityIDs, [-nudge[0], -nudge[1]], context.projection),
|
||||
annotation);
|
||||
var c = context.projection(origin);
|
||||
origin = context.projection.invert([c[0] - nudge[0], c[1] - nudge[1]]);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function stopNudge() {
|
||||
if (nudgeInterval) window.clearInterval(nudgeInterval);
|
||||
nudgeInterval = null;
|
||||
}
|
||||
|
||||
function move() {
|
||||
var p = context.mouse();
|
||||
|
||||
var delta = origin ?
|
||||
[p[0] - context.projection(origin)[0],
|
||||
p[1] - context.projection(origin)[1]] :
|
||||
[0, 0];
|
||||
|
||||
var nudge = edge(p, context.map().dimensions());
|
||||
if (nudge) startNudge(nudge);
|
||||
else stopNudge();
|
||||
|
||||
origin = context.map().mouseCoordinates();
|
||||
|
||||
context.replace(
|
||||
iD.actions.Move(entityIDs, delta, context.projection),
|
||||
annotation);
|
||||
}
|
||||
|
||||
function finish() {
|
||||
d3.event.stopPropagation();
|
||||
context.enter(iD.modes.Select(context, entityIDs));
|
||||
stopNudge();
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
context.pop();
|
||||
context.enter(iD.modes.Select(context, entityIDs));
|
||||
stopNudge();
|
||||
}
|
||||
|
||||
function undone() {
|
||||
context.enter(iD.modes.Browse(context));
|
||||
}
|
||||
|
||||
context.surface()
|
||||
.on('mousemove.move', move)
|
||||
.on('click.move', finish);
|
||||
@@ -97,6 +96,8 @@ iD.modes.Move = function(context, entityIDs) {
|
||||
};
|
||||
|
||||
mode.exit = function() {
|
||||
stopNudge();
|
||||
|
||||
context.uninstall(edit);
|
||||
|
||||
context.surface()
|
||||
|
||||
Reference in New Issue
Block a user