mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-13 04:44:50 +02:00
Extract Way#replaceNode
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user