Extract Way#replaceNode

This commit is contained in:
John Firebaugh
2013-02-08 12:03:48 -08:00
parent 5139de969e
commit d59320ee4b
2 changed files with 14 additions and 7 deletions
+1 -7
View File
@@ -20,13 +20,7 @@ iD.actions.Connect = function(nodeIds) {
var node = graph.entity(nodeIds[i]), index;
graph.parentWays(node).forEach(function (parent) {
while (true) {
index = parent.nodes.indexOf(node.id);
if (index < 0)
break;
parent = parent.updateNode(survivor.id, index);
}
graph = graph.replace(parent);
graph = graph.replace(parent.replaceNode(node.id, survivor.id));
});
graph.parentRelations(node).forEach(function (parent) {
+13
View File
@@ -75,6 +75,19 @@ _.extend(iD.Way.prototype, {
return this.update({nodes: nodes});
},
replaceNode: function(needle, replacement) {
if (this.nodes.indexOf(needle) < 0)
return this;
var nodes = this.nodes.slice();
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] === needle) {
nodes[i] = replacement;
}
}
return this.update({nodes: nodes});
},
removeNode: function(id) {
var nodes = _.without(this.nodes, id);