mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Update selected segment after splits
This commit is contained in:
@@ -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');
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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([['=', '=='], ['-', '--']]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user