From d2d464d9ee8c220e524bbf52c8697cd3dcc3d3c6 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 6 Apr 2018 11:30:16 +0200 Subject: [PATCH] only drop restrictions from FROM towards VIA when adding new only partially adresses bugs in #4968: * doesn't crash anymore in complex situations (short FROM ways where both ends connect to a TO way) * adding a only-restriction at one end of a short FROM doesn't delete restrictions on the other end of the same FROM anymore --- modules/osm/intersection.js | 14 ++++++-------- modules/ui/fields/restrictions.js | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/osm/intersection.js b/modules/osm/intersection.js index 9d0b7a83c..384961f53 100644 --- a/modules/osm/intersection.js +++ b/modules/osm/intersection.js @@ -408,22 +408,20 @@ export function osmIntersection(graph, startVertexId, maxDistance) { var isAlongOnlyPath = false; if (t.id === way.id) { // match VIA, TO - if (v.length === 1 && v[0].type === 'node' && v[0].id === entity.id) { - matchesViaTo = true; // match VIA node - - } else { // match all VIA ways + if (v.length === 1 && v[0].type === 'node') { // match VIA node + matchesViaTo = v[0].id === entity.id; + } else { // match all VIA ways var pathVias = []; - for (k = 1; k < currPath.length; k++) { // k = 1 skips FROM way - if (currPath[k][0] === 'w') pathVias.push(currPath[k]); + for (k = 2; k < currPath.length; k+=2) { // k = 1 skips FROM way + pathVias.push(currPath[k]); } var restrictionVias = []; for (k = 0; k < v.length; k++) { - if (v[k].type === 'way') restrictionVias.push(v[k].id); + restrictionVias.push(v[k].id); } var diff = _difference(pathVias, restrictionVias); matchesViaTo = !diff.length; } - } else if (isOnly) { for (k = 0; k < v.length; k++) { // way doesn't match TO, but is one of the via ways along the path of an "only" diff --git a/modules/ui/fields/restrictions.js b/modules/ui/fields/restrictions.js index 23e3e0f5e..32e6e9790 100644 --- a/modules/ui/fields/restrictions.js +++ b/modules/ui/fields/restrictions.js @@ -359,13 +359,13 @@ export function uiFieldRestrictions(field, context) { datumOnly.only = true; restrictionType = restrictionType.replace(/^no/, 'only'); - // Adding an ONLY restriction should destroy all other direct restrictions from the FROM. + // Adding an ONLY restriction should destroy all other direct restrictions from the FROM towards the VIA. // We will remember them in _oldTurns, and restore them if the user clicks again. turns = _intersection.turns(_fromWayID, 2); extraActions = []; _oldTurns = []; for (i = 0; i < turns.length; i++) { - if (turns[i].direct) { + if (turns[i].direct && turns[i].path[1] === datum.path[1]) { turns[i].restrictionType = osmInferRestriction(vgraph, turns[i], projection); _oldTurns.push(turns[i]); extraActions.push(actionUnrestrictTurn(turns[i]));