diff --git a/js/id/behavior/drag_node.js b/js/id/behavior/drag_node.js index f1c875c26..e1bb93595 100644 --- a/js/id/behavior/drag_node.js +++ b/js/id/behavior/drag_node.js @@ -103,13 +103,26 @@ iD.behavior.DragNode = function(context) { if (cancelled) return; off(); + function adjacent(d) { + return _.any(context.graph().parentWays(entity).map(function(w) { + return w.areAdjacent(d.id, entity.id); + })); + } + var d = datum(); + 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), connectAnnotation(d)); + + } else if (d.type === 'node' && adjacent(d)) { + context.replace( + iD.actions.DeleteNode(entity.id), + t('operations.delete.annotation.vertex')); + } else if (d.type === 'node' && d.id !== entity.id) { context.replace( iD.actions.Connect([entity.id, d.id]), diff --git a/js/id/behavior/draw_way.js b/js/id/behavior/draw_way.js index 52a8ef8c2..c741abf90 100644 --- a/js/id/behavior/draw_way.js +++ b/js/id/behavior/draw_way.js @@ -139,6 +139,10 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) { // Connect the way to an existing node and continue drawing. drawWay.addNode = function(node) { + + // Avoid creating duplicate segments + if (way.areAdjacent(node.id, way.nodes[way.nodes.length - 1])) return; + context.perform( ReplaceTemporaryNode(node), annotation); diff --git a/js/id/core/way.js b/js/id/core/way.js index 3ad2f4d96..14bbd14fd 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -57,6 +57,16 @@ _.extend(iD.Way.prototype, { return _.uniq(this.nodes).length < (this.isArea() ? 3 : 2); }, + areAdjacent: function(n1, n2) { + for (var i = 0; i < this.nodes.length; i++) { + if (this.nodes[i] === n1) { + if (this.nodes[i - 1] === n2) return true; + if (this.nodes[i + 1] === n2) return true; + } + } + return false; + }, + geometry: function() { return this.isArea() ? 'area' : 'line'; },