diff --git a/js/id/actions/restrict_turn.js b/js/id/actions/restrict_turn.js index eeefee3e6..aaac9b734 100644 --- a/js/id/actions/restrict_turn.js +++ b/js/id/actions/restrict_turn.js @@ -29,7 +29,9 @@ // be assigned a new ID. // iD.actions.RestrictTurn = function(turn, projection, restrictionId) { - return function(graph) { + var dispatch = d3.dispatch('split'); + + function action(graph) { var from = graph.entity(turn.from.way), via = graph.entity(turn.via.node), to = graph.entity(turn.to.way); @@ -40,6 +42,8 @@ iD.actions.RestrictTurn = function(turn, projection, restrictionId) { graph = iD.actions.Split(via.id, [newFromId]) .limitWays([from.id])(graph); + dispatch.split(from.id, newFromId, graph); + var newFrom = graph.entity(newFromId); if (newFrom.nodes.indexOf(turn.from.node) !== -1) from = newFrom; @@ -53,6 +57,8 @@ iD.actions.RestrictTurn = function(turn, projection, restrictionId) { graph = iD.actions.Split(via.id, [newToId]) .limitWays([to.id])(graph); + dispatch.split(to.id, newToId, graph); + var newTo = graph.entity(newToId); if (newTo.nodes.indexOf(turn.to.node) !== -1) to = newTo; @@ -75,5 +81,7 @@ iD.actions.RestrictTurn = function(turn, projection, restrictionId) { {id: to.id, type: 'way', role: 'to'} ] })); - }; + } + + return d3.rebind(action, dispatch, 'on'); }; diff --git a/js/id/ui/preset/restrictions.js b/js/id/ui/preset/restrictions.js index 45f137f36..10e3c4ed7 100644 --- a/js/id/ui/preset/restrictions.js +++ b/js/id/ui/preset/restrictions.js @@ -81,8 +81,17 @@ iD.ui.preset.restrictions = function(field, context) { t('operations.restriction.annotation.delete')); } else { context.perform( - iD.actions.RestrictTurn(datum, projection), + iD.actions.RestrictTurn(datum, projection) + .on('split', split), t('operations.restriction.annotation.create')); + + function split(oldID, newID, graph) { + if (graph.entity(newID).contains(datum.from.node)) { + selectedID = newID; + } else if (graph.entity(oldID).contains(datum.from.node)) { + selectedID = oldID; + } + } } } } diff --git a/test/spec/actions/restrict_turn.js b/test/spec/actions/restrict_turn.js index 302f14cad..a403a8a17 100644 --- a/test/spec/actions/restrict_turn.js +++ b/test/spec/actions/restrict_turn.js @@ -236,4 +236,38 @@ describe("iD.actions.RestrictTurn", function() { }, projection, 'r')(graph); expect(u.entity('r').tags.restriction).to.equal('no_u_turn'); }); + + it('emits split events', function() { + // x + // | + // u====*====w + // | + // y + var graph = iD.Graph([ + iD.Node({id: '*'}), + iD.Node({id: 'u'}), + iD.Node({id: 'w'}), + iD.Node({id: 'x'}), + iD.Node({id: 'y'}), + iD.Way({id: '=', nodes: ['u', '*', 'w']}), + iD.Way({id: '-', nodes: ['x', '*', 'y']}) + ]), + action = iD.actions.RestrictTurn({ + from: {node: 'u', way: '=', newID: '=='}, + via: {node: '*'}, + to: {node: 'x', way: '-', newID: '--'}, + restriction: 'no_left_turn' + }); + + var splits = []; + + action.on('split', function(a, b, graph) { + expect(graph).to.be.instanceOf(iD.Graph); + splits.push([a, b]); + }); + + action(graph); + + expect(splits).to.eql([['=', '=='], ['-', '--']]); + }); });