mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
loc -> point, dxdy -> delta
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
iD.actions.MoveWay = function(wayId, dxdy, projection) {
|
||||
iD.actions.MoveWay = function(wayId, delta, projection) {
|
||||
return function(graph) {
|
||||
var way = graph.entity(wayId);
|
||||
|
||||
_.uniq(way.nodes).forEach(function(id) {
|
||||
var node = graph.entity(id),
|
||||
start = projection(node.loc),
|
||||
end = projection.invert([start[0] + dxdy[0], start[1] + dxdy[1]]);
|
||||
end = projection.invert([start[0] + delta[0], start[1] + delta[1]]);
|
||||
graph = iD.actions.MoveNode(id, end)(graph);
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
(https://github.com/mbostock/d3/issues/563)
|
||||
* The `start` event is not dispatched until the first cursor movement occurs.
|
||||
(https://github.com/mbostock/d3/pull/368)
|
||||
* The `move` event has a `loc` and `dxdy` [x, y] tuple properties rather
|
||||
* The `move` event has a `point` and `delta` [x, y] tuple properties rather
|
||||
than `x`, `y`, `dx`, and `dy` properties.
|
||||
* The `end` event is not dispatched if no movement occurs.
|
||||
* An `off` function is available that unbinds the drag's internal event handlers.
|
||||
@@ -85,8 +85,8 @@ iD.behavior.drag = function () {
|
||||
|
||||
event_({
|
||||
type: "move",
|
||||
loc: [p[0] + offset[0], p[1] + offset[1]],
|
||||
dxdy: [dx, dy]
|
||||
point: [p[0] + offset[0], p[1] + offset[1]],
|
||||
delta: [dx, dy]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ iD.behavior.DragAccuracyHandle = function(mode) {
|
||||
.on('move', function(d) {
|
||||
d3.event.sourceEvent.stopPropagation();
|
||||
history.replace(
|
||||
iD.actions.MoveNode(d.node.id, projection.invert(d3.event.loc)));
|
||||
iD.actions.MoveNode(d.node.id, projection.invert(d3.event.point)));
|
||||
})
|
||||
.on('end', function() {
|
||||
history.replace(
|
||||
|
||||
@@ -14,7 +14,7 @@ iD.behavior.DragNode = function(mode) {
|
||||
.on('move', function(entity) {
|
||||
d3.event.sourceEvent.stopPropagation();
|
||||
history.replace(
|
||||
iD.actions.MoveNode(entity.id, projection.invert(d3.event.loc)));
|
||||
iD.actions.MoveNode(entity.id, projection.invert(d3.event.point)));
|
||||
})
|
||||
.on('end', function() {
|
||||
history.replace(
|
||||
|
||||
@@ -14,7 +14,7 @@ iD.behavior.DragWay = function(mode) {
|
||||
.on('move', function(entity) {
|
||||
d3.event.sourceEvent.stopPropagation();
|
||||
history.replace(
|
||||
iD.actions.MoveWay(entity.id, d3.event.dxdy, projection));
|
||||
iD.actions.MoveWay(entity.id, d3.event.delta, projection));
|
||||
})
|
||||
.on('end', function() {
|
||||
history.replace(
|
||||
|
||||
@@ -3,9 +3,9 @@ describe("iD.actions.MoveWay", function () {
|
||||
var node1 = iD.Node({loc: [0, 0]}),
|
||||
node2 = iD.Node({loc: [5, 10]}),
|
||||
way = iD.Way({nodes: [node1.id, node2.id]}),
|
||||
dxdy = [2, 3],
|
||||
delta = [2, 3],
|
||||
projection = d3.geo.mercator(),
|
||||
graph = iD.actions.MoveWay(way.id, dxdy, projection)(iD.Graph([node1, node2, way])),
|
||||
graph = iD.actions.MoveWay(way.id, delta, projection)(iD.Graph([node1, node2, way])),
|
||||
loc1 = graph.entity(node1.id).loc,
|
||||
loc2 = graph.entity(node2.id).loc;
|
||||
expect(loc1[0]).to.be.closeTo( 1.440, 0.001);
|
||||
@@ -17,9 +17,9 @@ describe("iD.actions.MoveWay", function () {
|
||||
it("moves repeated nodes only once", function () {
|
||||
var node = iD.Node({loc: [0, 0]}),
|
||||
way = iD.Way({nodes: [node.id, node.id]}),
|
||||
dxdy = [2, 3],
|
||||
delta = [2, 3],
|
||||
projection = d3.geo.mercator(),
|
||||
graph = iD.actions.MoveWay(way.id, dxdy, projection)(iD.Graph([node, way])),
|
||||
graph = iD.actions.MoveWay(way.id, delta, projection)(iD.Graph([node, way])),
|
||||
loc = graph.entity(node.id).loc;
|
||||
expect(loc[0]).to.be.closeTo( 1.440, 0.001);
|
||||
expect(loc[1]).to.be.closeTo(-2.159, 0.001);
|
||||
|
||||
Reference in New Issue
Block a user