From a980695ee7c72e909529faf4cddd921ffc9aa69e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 16 Jan 2013 12:20:35 -0500 Subject: [PATCH] Avoid creating lines with < 2 nodes (or areas < 3) --- js/id/modes/add_area.js | 6 ++---- js/id/modes/add_line.js | 9 +++------ js/id/modes/draw_area.js | 14 ++++++++++---- js/id/modes/draw_line.js | 16 +++++++++++----- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/js/id/modes/add_area.js b/js/id/modes/add_area.js index 33facb041..6977f2e15 100644 --- a/js/id/modes/add_area.js +++ b/js/id/modes/add_area.js @@ -23,8 +23,7 @@ iD.modes.AddArea = function() { history.perform( iD.actions.AddWay(way), iD.actions.AddWayNode(way.id, datum.id), - iD.actions.AddWayNode(way.id, datum.id), - 'started an area'); + iD.actions.AddWayNode(way.id, datum.id)); } else { // start from a new node @@ -33,8 +32,7 @@ iD.modes.AddArea = function() { iD.actions.AddWay(way), iD.actions.AddNode(node), iD.actions.AddWayNode(way.id, node.id), - iD.actions.AddWayNode(way.id, node.id), - 'started an area'); + iD.actions.AddWayNode(way.id, node.id)); } controller.enter(iD.modes.DrawArea(way.id)); diff --git a/js/id/modes/add_line.js b/js/id/modes/add_line.js index bc87238ca..60f376181 100644 --- a/js/id/modes/add_line.js +++ b/js/id/modes/add_line.js @@ -33,8 +33,7 @@ iD.modes.AddLine = function() { } else { history.perform( iD.actions.AddWay(way), - iD.actions.AddWayNode(way.id, datum.id), - 'started a line'); + iD.actions.AddWayNode(way.id, datum.id)); } } else if (datum.type === 'way') { @@ -46,8 +45,7 @@ iD.modes.AddLine = function() { iD.actions.AddWay(way), iD.actions.AddNode(node), iD.actions.AddWayNode(datum.id, node.id, choice.index), - iD.actions.AddWayNode(way.id, node.id), - 'started a line'); + iD.actions.AddWayNode(way.id, node.id)); } else { // begin a new way @@ -56,8 +54,7 @@ iD.modes.AddLine = function() { history.perform( iD.actions.AddWay(way), iD.actions.AddNode(node), - iD.actions.AddWayNode(way.id, node.id), - 'started a line'); + iD.actions.AddWayNode(way.id, node.id)); } controller.enter(iD.modes.DrawLine(way.id, direction)); diff --git a/js/id/modes/draw_area.js b/js/id/modes/draw_area.js index d868a7620..75b84af65 100644 --- a/js/id/modes/draw_area.js +++ b/js/id/modes/draw_area.js @@ -42,22 +42,28 @@ iD.modes.DrawArea = function(wayId) { var datum = d3.select(d3.event.target).datum() || {}; if (datum.id === tailId || datum.id === headId) { - history.replace(iD.actions.DeleteNode(node.id)); - controller.enter(iD.modes.Select(way)); + if (way.nodes.length > 3) { + history.replace(iD.actions.DeleteNode(node.id)); + controller.enter(iD.modes.Select(way)); + } else { + // Areas with less than 3 nodes gets deleted + history.replace(iD.actions.DeleteWay(way.id)); + controller.enter(iD.modes.Browse()); + } } else if (datum.type === 'node' && datum.id !== node.id) { // connect the way to an existing node history.replace( iD.actions.DeleteNode(node.id), iD.actions.AddWayNode(way.id, datum.id, -1), - 'added to an area'); + way.nodes.length > 2 ? 'added to an area' : ''); controller.enter(iD.modes.DrawArea(wayId)); } else { history.replace( iD.actions.Noop(), - 'added to an area'); + way.nodes.length > 2 ? 'added to an area' : ''); controller.enter(iD.modes.DrawArea(wayId)); } diff --git a/js/id/modes/draw_line.js b/js/id/modes/draw_line.js index 9c3d4b38e..700944b18 100644 --- a/js/id/modes/draw_line.js +++ b/js/id/modes/draw_line.js @@ -42,12 +42,18 @@ iD.modes.DrawLine = function(wayId, direction) { if (datum.id === tailId) { // connect the way in a loop - history.replace( - iD.actions.DeleteNode(node.id), - iD.actions.AddWayNode(wayId, tailId, index), - 'added to a line'); + if (way.nodes.length > 2) { + history.replace( + iD.actions.DeleteNode(node.id), + iD.actions.AddWayNode(wayId, tailId, index), + 'added to a line'); - controller.enter(iD.modes.Select(way)); + controller.enter(iD.modes.Select(way)); + + } else { + history.replace(iD.actions.DeleteWay(way.id)); + controller.enter(iD.modes.Browse()); + } } else if (datum.id === headId) { // finish the way