Browse files

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
  • Loading branch information...
1 parent 4944592 commit acdc1b382445e901cd175f0a245ecb3d46aee546 @ansis ansis committed Apr 4, 2013
View
5 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);
View
7 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);
View
4 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));
}
View
4 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));
}
View
2 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);
}
View
3 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) {

0 comments on commit acdc1b3

Please sign in to comment.