Add newly split way to member relations

This commit is contained in:
John Firebaugh
2013-01-18 14:43:25 -08:00
parent f16c54e12f
commit e19f86a285
2 changed files with 95 additions and 1 deletions

View File

@@ -33,8 +33,26 @@ iD.actions.SplitWay = function(nodeId, newWayId) {
graph = iD.actions.UpdateRelationMember(
relation.id,
{id: newWay.id},
relation.memberById(way.id).index)(graph);
relation.memberById(way.id).index
)(graph);
}
} else {
var role = relation.memberById(way.id).role,
last = newWay.last(),
i = relation.memberById(way.id).index,
j;
for (j = 0; j < relation.members.length; j++) {
if (relation.members[j].type === 'way' && graph.entity(relation.members[j].id).contains(last)) {
break;
}
}
graph = iD.actions.AddRelationMember(
relation.id,
{id: newWay.id, type: 'way', role: role},
i <= j ? i + 1 : i
)(graph);
}
});

View File

@@ -37,6 +37,82 @@ describe("iD.actions.SplitWay", function () {
expect(graph.entity('=').tags).to.equal(tags);
});
it("adds the new way to parent relations (no connections)", function () {
// Situation:
// a ---- b ---- c
// Relation: [----]
//
// Split at b.
//
// Expected result:
// a ---- b ==== c
// Relation: [----, ====]
//
var graph = iD.Graph({
'a': iD.Node({id: 'a'}),
'b': iD.Node({id: 'b'}),
'c': iD.Node({id: 'c'}),
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
'r': iD.Relation({id: 'r', members: [{id: '-', type: 'way'}]})
});
graph = iD.actions.SplitWay('b', '=')(graph);
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['-', '=']);
});
it("adds the new way to parent relations (forward order)", function () {
// Situation:
// a ---- b ---- c ~~~~ d
// Relation: [----, ~~~~]
//
// Split at b.
//
// Expected result:
// a ---- b ==== c ~~~~ d
// Relation: [----, ====, ~~~~]
//
var graph = iD.Graph({
'a': iD.Node({id: 'a'}),
'b': iD.Node({id: 'b'}),
'c': iD.Node({id: 'c'}),
'd': iD.Node({id: 'd'}),
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
'~': iD.Way({id: '~', nodes: ['c', 'd']}),
'r': iD.Relation({id: 'r', members: [{id: '-', type: 'way'}, {id: '~', type: 'way'}]})
});
graph = iD.actions.SplitWay('b', '=')(graph);
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['-', '=', '~']);
});
it("adds the new way to parent relations (reverse order)", function () {
// Situation:
// a ---- b ---- c ~~~~ d
// Relation: [~~~~, ----]
//
// Split at b.
//
// Expected result:
// a ---- b ==== c ~~~~ d
// Relation: [~~~~, ====, ----]
//
var graph = iD.Graph({
'a': iD.Node({id: 'a'}),
'b': iD.Node({id: 'b'}),
'c': iD.Node({id: 'c'}),
'd': iD.Node({id: 'd'}),
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
'~': iD.Way({id: '~', nodes: ['c', 'd']}),
'r': iD.Relation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]})
});
graph = iD.actions.SplitWay('b', '=')(graph);
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['~', '=', '-']);
});
['restriction', 'restriction:bus'].forEach(function (type) {
it("updates a restriction's 'from' role", function () {
// Situation: