From 5371d42cdf8fa7a9e008dfb6083f3bdafc2edf0f Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 7 Dec 2012 14:33:16 -0500 Subject: [PATCH] Continue with splitWay --- js/id/actions/split_way.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/js/id/actions/split_way.js b/js/id/actions/split_way.js index 55623ce5e..18fc36992 100644 --- a/js/id/actions/split_way.js +++ b/js/id/actions/split_way.js @@ -13,17 +13,32 @@ iD.actions.SplitWay = function(nodeId) { // Create a 'b' way that contains all of the tags in the second // half of this way - var b = iD.Way({ tags: _.clone(way.tags), nodes: way.nodes.slice(idx) }); - graph = graph.replace(b); + var newWay = iD.Way({ tags: _.clone(way.tags), nodes: way.nodes.slice(idx) }); + graph = graph.replace(newWay); + // Reduce the original way to only contain the first set of nodes graph = graph.replace(way.update({ nodes: way.nodes.slice(0, idx + 1) }), 'changed way direction'); - var parentRelations = graph.parentRelations(way); + var parentRelations = graph.parentRelations(way.id); + + function isVia(x) { return x.role = 'via'; } + function isSelf(x) { return x.id = way.id; } parentRelations.forEach(function(relation) { - console.log(relation); if (relation.tags.type === 'restriction') { - console.log(relation); + var via = _.find(relation.members, isVia); + var ownrole = _.find(relation.members, isSelf).role; + if (via && !_.contains(newWay.nodes, via.id)) { + // the new way doesn't contain the node that's important + // to the turn restriction, so we don't need to worry + // about adding it to the turn restriction. + } else { + graph = graph.replace(iD.actions.AddRelationMember(relation.id, { + role: ownrole, + id: newWay.id, + type: 'way' + })); + } } });