Cycle through only_ turn restriction states

(re: #2622)
This commit is contained in:
Bryan Housel
2018-02-07 19:04:28 -05:00
parent 3c340a0362
commit 0cbff57dc9
6 changed files with 42 additions and 37 deletions
+3 -8
View File
@@ -27,7 +27,7 @@ import {
// Normally, this will be undefined and the relation will automatically
// be assigned a new ID.
//
export function actionRestrictTurn(turn, projection, restrictionId) {
export function actionRestrictTurn(turn, projection, restrictionID) {
return function(graph) {
var fromWay = graph.entity(turn.from.way);
@@ -49,15 +49,10 @@ export function actionRestrictTurn(turn, projection, restrictionId) {
members.push({ id: toWay.id, type: 'way', role: 'to' });
return graph.replace(osmRelation({
id: restrictionId,
id: restrictionID,
tags: {
type: 'restriction',
restriction: turn.restriction ||
osmInferRestriction(
graph,
turn.from,
turn.to,
projection)
restriction: turn.restriction || osmInferRestriction(graph, turn.from, turn.to, projection)
},
members: members
}));
+4 -4
View File
@@ -8,19 +8,19 @@ import { actionDeleteRelation } from './delete_relation';
// from: { node: <node ID>, way: <way ID> },
// via: { node: <node ID> },
// to: { node: <node ID>, way: <way ID> },
// restriction: <relation ID>
// restrictionID: <relation ID>
// }
//
// In the simple case, `restriction` is a reference to a `no_*` restriction
// In the simple case, `restrictionID` is a reference to a `no_*` restriction
// on the turn itself. In this case, it is simply deleted.
//
// The more complex case is where `restriction` references an `only_*`
// The more complex case is where `restrictionID` references an `only_*`
// restriction on a different turn in the same intersection. In that case,
// that restriction is also deleted, but at the same time restrictions on
// the turns other than the first two are created.
//
export function actionUnrestrictTurn(turn) {
return function(graph) {
return actionDeleteRelation(turn.restriction)(graph);
return actionDeleteRelation(turn.restrictionID)(graph);
};
}
+1 -1
View File
@@ -471,7 +471,7 @@ export function osmIntersection(graph, startVertexId) {
var turn = pathToTurn(currPath);
if (turn) {
if (matchedRestriction) {
turn.restriction = matchedRestriction.id;
turn.restrictionID = matchedRestriction.id;
turn.only = matchedRestriction.only;
turn.direct = matchedRestriction.direct;
turn.indirect = matchedRestriction.indirect;
+18 -5
View File
@@ -1,3 +1,5 @@
import _cloneDeep from 'lodash-es/cloneDeep';
import { dispatch as d3_dispatch } from 'd3-dispatch';
import {
@@ -206,7 +208,18 @@ export function uiFieldRestrictions(field, context) {
} else if (datum instanceof osmTurn) {
var actions;
if (datum.restriction) {
datum.restriction = osmInferRestriction(vgraph, datum.from, datum.to, projection);
if (datum.restrictionID && !datum.only) { // cycle thru the `only_` state
var datumOnly = _cloneDeep(datum);
datumOnly.only = true;
datumOnly.restriction = datumOnly.restriction.replace(/^no\_/, 'only_');
actions = _intersection.actions.concat([
actionUnrestrictTurn(datum, projection),
actionRestrictTurn(datumOnly, projection),
t('operations.restriction.annotation.create')
]);
} else if (datum.restrictionID) {
actions = _intersection.actions.concat([
actionUnrestrictTurn(datum, projection),
t('operations.restriction.annotation.delete')
@@ -250,14 +263,14 @@ export function uiFieldRestrictions(field, context) {
.classed('related', true);
var turnType = {
'no_left_turn': 'Left Turns',
'no_right_turn': 'Right Turns',
'no_u_turn': 'U-Turns',
'no_left_turn': 'Left Turn',
'no_right_turn': 'Right Turn',
'no_u_turn': 'U-Turn',
'no_straight_on': 'Continuing'
}[osmInferRestriction(vgraph, datum.from, datum.to, projection)];
var restrictType = 'IS';
if (datum.restriction) {
if (datum.restrictionID) {
if (datum.only) { restrictType = 'IS ONLY'; }
if (datum.direct) { restrictType = 'IS NOT'; }
if (datum.indirect) { restrictType = 'IS NOT '; }