From 030b4b3efa7c296710f9f394002da0247537f179 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 22 May 2019 14:12:23 -0400 Subject: [PATCH] Flag almost junctions between highways and themselves (close #6373) --- data/core.yaml | 2 ++ dist/locales/en.json | 3 +++ modules/validations/almost_junction.js | 32 ++++++++++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 7f2d9a393..d3dddca43 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1332,6 +1332,8 @@ en: title: Almost Junctions message: "{feature} is very close but not connected to {feature2}" tip: "Find features that should possibly be connected to other nearby features" + self: + message: "{feature} ends very close to itself but does not reconnect" highway-highway: reference: Intersecting highways should share a junction vertex. close_nodes: diff --git a/dist/locales/en.json b/dist/locales/en.json index b1576c6b1..bcda08882 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1635,6 +1635,9 @@ "title": "Almost Junctions", "message": "{feature} is very close but not connected to {feature2}", "tip": "Find features that should possibly be connected to other nearby features", + "self": { + "message": "{feature} ends very close to itself but does not reconnect" + }, "highway-highway": { "reference": "Intersecting highways should share a junction vertex." } diff --git a/modules/validations/almost_junction.js b/modules/validations/almost_junction.js index 0fb6a6195..471fa84c5 100644 --- a/modules/validations/almost_junction.js +++ b/modules/validations/almost_junction.js @@ -92,16 +92,23 @@ export function validationAlmostJunction() { type: type, severity: 'warning', message: function() { - var entity1 = context.hasEntity(this.entityIds[0]), - entity2 = context.hasEntity(this.entityIds[2]); - return (entity && entity2) ? t('issues.almost_junction.message', { - feature: utilDisplayLabel(entity1, context), - feature2: utilDisplayLabel(entity2, context) - }) : ''; + var entity1 = context.hasEntity(this.entityIds[0]); + if (this.entityIds[0] === this.entityIds[2]) { + return entity1 ? t('issues.almost_junction.self.message', { + feature: utilDisplayLabel(entity1, context) + }) : ''; + } else { + var entity2 = context.hasEntity(this.entityIds[2]); + return (entity1 && entity2) ? t('issues.almost_junction.message', { + feature: utilDisplayLabel(entity1, context), + feature2: utilDisplayLabel(entity2, context) + }) : ''; + } }, reference: showReference, entityIds: [entity.id, node.id, edgeHighway.id], loc: extendableNodeInfo.node.loc, + hash: JSON.stringify(extendableNodeInfo.node.loc), data: { edge: extendableNodeInfo.edge, cross_loc: extendableNodeInfo.cross_loc @@ -179,8 +186,8 @@ export function validationAlmostJunction() { function canConnectWays(way, way2) { - // don't flag almost self-connections for now - if (way.id === way2.id) return false; + // allow self-connections + if (way.id === way2.id) return true; // if one is bridge or tunnel, both must be bridge or tunnel if ((hasTag(way.tags, 'bridge') || hasTag(way2.tags, 'bridge')) && @@ -231,8 +238,13 @@ export function validationAlmostJunction() { if (!canConnectWays(way, way2)) continue; for (var j = 0; j < way2.nodes.length - 1; j++) { - var nA = graph.entity(way2.nodes[j]); - var nB = graph.entity(way2.nodes[j + 1]); + var nAid = way2.nodes[j], + nBid = way2.nodes[j + 1] + + if (nAid === tipNid || nBid === tipNid) continue; + + var nA = graph.entity(nAid), + nB = graph.entity(nBid); var crossLoc = geoLineIntersection([tipNode.loc, extTipLoc], [nA.loc, nB.loc]); if (crossLoc) { return {