From acdc1b382445e901cd175f0a245ecb3d46aee546 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 4 Apr 2013 17:58:53 -0400 Subject: [PATCH] add nodes to all of a segment's ways when - dragging a node to a way - starting a line from a way - starting an area from a way - drawing a way --- js/id/behavior/draw.js | 5 +++-- js/id/behavior/draw_way.js | 7 +++---- js/id/modes/add_area.js | 4 ++-- js/id/modes/add_line.js | 4 ++-- js/id/modes/add_point.js | 2 +- js/id/modes/drag_node.js | 3 +-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/js/id/behavior/draw.js b/js/id/behavior/draw.js index 3c5d1243d..214433972 100644 --- a/js/id/behavior/draw.js +++ b/js/id/behavior/draw.js @@ -58,8 +58,9 @@ iD.behavior.Draw = function(context) { function click() { var d = datum(); if (d.type === 'way') { - var choice = iD.geo.chooseIndex(d, d3.mouse(context.surface().node()), context); - event.clickWay(d, choice.loc, choice.index); + var choice = iD.geo.chooseIndex(d, d3.mouse(context.surface().node()), context), + edge = [d.nodes[choice.index - 1], d.nodes[choice.index]]; + event.clickWay(choice.loc, edge); } else if (d.type === 'node') { event.clickNode(d); diff --git a/js/id/behavior/draw_way.js b/js/id/behavior/draw_way.js index 4a6be8636..731260dbb 100644 --- a/js/id/behavior/draw_way.js +++ b/js/id/behavior/draw_way.js @@ -125,12 +125,11 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) { }; // Connect the way to an existing way. - drawWay.addWay = function(way, loc, wayIndex) { - var newNode = iD.Node({loc: loc}); + drawWay.addWay = function(loc, edge) { + var newNode = iD.Node({ loc: loc }); context.perform( - iD.actions.AddEntity(newNode), - iD.actions.AddVertex(way.id, newNode.id, wayIndex), + iD.actions.AddMidpoint({ loc: loc, edge: edge}, newNode), ReplaceTemporaryNode(newNode), annotation); diff --git a/js/id/modes/add_area.js b/js/id/modes/add_area.js index 8bb5724d7..6d0e5ba2a 100644 --- a/js/id/modes/add_area.js +++ b/js/id/modes/add_area.js @@ -27,7 +27,7 @@ iD.modes.AddArea = function(context) { context.enter(iD.modes.DrawArea(context, way.id, graph)); } - function startFromWay(other, loc, index) { + function startFromWay(loc, edge) { var graph = context.graph(), node = iD.Node({loc: loc}), way = iD.Way({tags: defaultTags}); @@ -37,7 +37,7 @@ iD.modes.AddArea = function(context) { iD.actions.AddEntity(way), iD.actions.AddVertex(way.id, node.id), iD.actions.AddVertex(way.id, node.id), - iD.actions.AddVertex(other.id, node.id, index)); + iD.actions.AddMidpoint({ loc: loc, edge: edge }, node)); context.enter(iD.modes.DrawArea(context, way.id, graph)); } diff --git a/js/id/modes/add_line.js b/js/id/modes/add_line.js index d852c6b4d..186016765 100644 --- a/js/id/modes/add_line.js +++ b/js/id/modes/add_line.js @@ -25,7 +25,7 @@ iD.modes.AddLine = function(context) { context.enter(iD.modes.DrawLine(context, way.id, 'forward', graph)); } - function startFromWay(other, loc, index) { + function startFromWay(loc, edge) { var graph = context.graph(), node = iD.Node({loc: loc}), way = iD.Way(); @@ -34,7 +34,7 @@ iD.modes.AddLine = function(context) { iD.actions.AddEntity(node), iD.actions.AddEntity(way), iD.actions.AddVertex(way.id, node.id), - iD.actions.AddVertex(other.id, node.id, index)); + iD.actions.AddMidpoint({ loc: loc, edge: edge }, node)); context.enter(iD.modes.DrawLine(context, way.id, 'forward', graph)); } diff --git a/js/id/modes/add_point.js b/js/id/modes/add_point.js index a3d85f618..f2dad0bcf 100644 --- a/js/id/modes/add_point.js +++ b/js/id/modes/add_point.js @@ -23,7 +23,7 @@ iD.modes.AddPoint = function(context) { context.enter(iD.modes.Select(context, [node.id], true)); } - function addWay(way, loc, index) { + function addWay(loc, edge) { add(loc); } diff --git a/js/id/modes/drag_node.js b/js/id/modes/drag_node.js index a3c76a912..df3558171 100644 --- a/js/id/modes/drag_node.js +++ b/js/id/modes/drag_node.js @@ -107,8 +107,7 @@ iD.modes.DragNode = function(context) { if (d.type === 'way') { var choice = iD.geo.chooseIndex(d, d3.mouse(context.surface().node()), context); context.replace( - iD.actions.MoveNode(entity.id, choice.loc), - iD.actions.AddVertex(d.id, entity.id, choice.index), + iD.actions.AddMidpoint({ loc: choice.loc, edge: [d.nodes[choice.index - 1], d.nodes[choice.index]] }, entity), connectAnnotation(d)); } else if (d.type === 'node' && d.id !== entity.id) {