mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
prevent creation of ways with duplicate segments or repeated nodes
This commit is contained in:
@@ -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]),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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';
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user