When connecting nodes, prefer to keep an existing (not new) node

(closes #4974, closes #4674)
This commit is contained in:
Bryan Housel
2018-04-09 14:20:40 -04:00
parent c42556ec96
commit b09c712fc5
2 changed files with 90 additions and 75 deletions
+15 -6
View File
@@ -3,8 +3,8 @@ import { actionDeleteNode } from './delete_node';
// Connect the ways at the given nodes.
//
// The last node will survive. All other nodes will be replaced with
// the surviving node in parent ways, and then removed.
// First choose a node to be the survivor, with preference given
// to an existing (not new) node.
//
// Tags and relation memberships of of non-surviving nodes are merged
// to the survivor.
@@ -17,11 +17,20 @@ import { actionDeleteNode } from './delete_node';
//
export function actionConnect(nodeIds) {
return function(graph) {
var last = nodeIds[nodeIds.length - 1];
var survivor = graph.entity(last);
var survivor;
var node;
var i;
for (var i = 0; i < nodeIds.length - 1; i++) {
var node = graph.entity(nodeIds[i]);
// Choose a survivor node, prefer an existing (not new) node - #4974
for (i = 0; i < nodeIds.length; i++) {
survivor = graph.entity(nodeIds[i]);
if (survivor.version) break; // found one
}
// Replace all non-surviving nodes with the survivor and merge tags.
for (i = 0; i < nodeIds.length; i++) {
node = graph.entity(nodeIds[i]);
if (node.id === survivor.id) continue;
/* eslint-disable no-loop-func */
graph.parentWays(node).forEach(function(parent) {