Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 4ffaba1def85a6d2efee4203016c80f105551091 1 parent 08dca79
@jfirebaugh jfirebaugh authored
Showing with 28 additions and 0 deletions.
  1. +9 −0 js/id/actions/join.js
  2. +19 −0 test/spec/actions/join.js
View
9 js/id/actions/join.js
@@ -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
19 test/spec/actions/join.js
@@ -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'}),
Please sign in to comment.
Something went wrong with that request. Please try again.