For node-way merge, preserve original node if possible

(closes #3683)
This commit is contained in:
Bryan Housel
2016-12-31 02:01:13 -05:00
parent 4e2d975e13
commit c2713c3a3f
3 changed files with 45 additions and 4 deletions
+22 -3
View File
@@ -17,15 +17,34 @@ export function actionMerge(ids) {
points.forEach(function(point) {
target = target.mergeTags(point.tags);
graph = graph.replace(target);
graph.parentRelations(point).forEach(function(parent) {
graph = graph.replace(parent.replaceMember(point, target));
});
graph = graph.remove(point);
});
var nodes = _.uniq(graph.childNodes(target)),
removeNode = point;
graph = graph.replace(target);
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (graph.parentWays(node).length > 1 ||
graph.parentRelations(node).length ||
node.hasInterestingTags()) {
continue;
}
// Found an uninteresting child node on the target way.
// Move orig point into its place to preserve point's history. #3683
graph = graph.replace(point.update({ tags: {}, loc: node.loc }));
target = target.replaceNode(node.id, point.id);
graph = graph.replace(target);
removeNode = node;
break;
}
graph = graph.remove(removeNode);
});
return graph;
};
+4 -1
View File
@@ -27,7 +27,10 @@ export function operationMerge(selectedIDs, context) {
}
context.perform(action, annotation);
var ids = selectedIDs.filter(function(id) { return context.hasEntity(id); });
var ids = selectedIDs.filter(function(id) {
var entity = context.hasEntity(id);
return entity && entity.type !== 'node';
});
context.enter(modeSelect(context, ids).suppressMenu(true));
};
+19
View File
@@ -36,4 +36,23 @@ describe('iD.actionMerge', function () {
expect(graph.entity('w').tags).to.eql({a: 'a', b: 'b', area: 'yes'});
expect(graph.entity('r').members).to.eql([{id: 'w', role: 'r', type: 'way'}]);
});
it('preserves original point if possible', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [1, 0], tags: {a: 'a'}}),
iD.Node({id: 'p', loc: [0, 0], tags: {p: 'p'}}),
iD.Node({id: 'q', loc: [0, 1]}),
iD.Way({id: 'w', nodes: ['p', 'q'], tags: {w: 'w'}})
]),
action = iD.actionMerge(['a', 'w']);
graph = action(graph);
expect(graph.hasEntity('a')).to.be.ok;
expect(graph.hasEntity('p')).to.be.ok;
expect(graph.hasEntity('q')).to.be.undefined;
expect(graph.entity('w').tags).to.eql({a: 'a', w: 'w'});
expect(graph.entity('w').nodes).to.eql(['p', 'a']);
expect(graph.entity('a').loc[0]).to.eql(0);
expect(graph.entity('a').loc[1]).to.eql(1);
});
});