Avoid creating lines with < 2 nodes (or areas < 3)

This commit is contained in:
Ansis Brammanis
2013-01-16 12:20:35 -05:00
parent fc272199c7
commit a980695ee7
4 changed files with 26 additions and 19 deletions
+2 -4
View File
@@ -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));
+3 -6
View File
@@ -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));
+10 -4
View File
@@ -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));
}
+11 -5
View File
@@ -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