Prefer to keep existing ways when joining (fixes #1424)

This commit is contained in:
John Firebaugh
2013-05-07 12:33:42 -07:00
parent 08dca79f9e
commit 4ffaba1def
2 changed files with 28 additions and 0 deletions

View File

@@ -20,6 +20,15 @@ iD.actions.Join = function(ids) {
b = graph.entity(idB),
nodes;
// Prefer to keep an existing way.
if (a.isNew() && !b.isNew()) {
var tmp = a;
a = b;
b = tmp;
idA = a.id;
idB = b.id;
}
if (a.first() === b.first()) {
// a <-- b ==> c
// Expected result:

View File

@@ -149,6 +149,25 @@ describe("iD.actions.Join", function () {
expect(graph.entity('-').tags).to.eql({'lanes:backward': 2});
});
it("prefers to keep existing ways", function () {
// a --> b ==> c
// --- is new, === is existing
// Expected result:
// a ==> b ==> c
var graph = iD.Graph({
'a': iD.Node({id: 'a'}),
'b': iD.Node({id: 'b'}),
'c': iD.Node({id: 'c'}),
'w-1': iD.Way({id: 'w-1', nodes: ['a', 'b']}),
'w1': iD.Way({id: 'w1', nodes: ['b', 'c']})
});
graph = iD.actions.Join(['w-1', 'w1'])(graph);
expect(graph.entity('w1').nodes).to.eql(['a', 'b', 'c']);
expect(graph.hasEntity('w-1')).to.be.undefined;
});
it("merges tags", function () {
var graph = iD.Graph({
'a': iD.Node({id: 'a'}),