From 2edbcc4b82bf95bdd124dcfb5deac5c9f7abeb5c Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 11 Dec 2017 15:17:17 -0500 Subject: [PATCH] Match any `*:direction` key, rather than hardcoding a list --- modules/actions/reverse.js | 3 ++- modules/osm/node.js | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/actions/reverse.js b/modules/actions/reverse.js index 051f3e64b..3f92fcd91 100644 --- a/modules/actions/reverse.js +++ b/modules/actions/reverse.js @@ -87,7 +87,8 @@ export function actionReverse(wayId, options) { // Update the direction based tags as appropriate then return an updated node return node.update({tags: _transform(node.tags, function(acc, tagValue, tagKey) { // See if this is a direction tag and reverse (or use existing value if not recognised) - if (tagKey.match(/direction$/) !== null) { + var re = /direction$/; + if (re.test(tagKey)) { acc[tagKey] = {forward: 'backward', backward: 'forward', left: 'right', right: 'left'}[tagValue] || tagValue; } else { // Use the reverseKey method to cater for situations such as traffic_sign:forward=stop diff --git a/modules/osm/node.js b/modules/osm/node.js index 362b4448c..5083caada 100644 --- a/modules/osm/node.js +++ b/modules/osm/node.js @@ -52,19 +52,25 @@ _extend(osmNode.prototype, { // Inspect tags and geometry to determine which direction(s) this node/vertex points directions: function(resolver, projection) { var val; + var i; + // which tag to use? if (this.isHighwayIntersection(resolver) && (this.tags.stop || '').toLowerCase() === 'all') { // all-way stop tag on a highway intersection val = 'all'; } else { - // direction tag - val = ( - this.tags['camera:direction'] || - this.tags['railway:signal:direction'] || - this.tags['traffic_signals:direction'] || - this.tags.direction || - '' - ).toLowerCase(); + // generic direction tag + val = (this.tags.direction || '').toLowerCase(); + + // better suffix-style direction tag + var re = /:direction$/i; + var keys = Object.keys(this.tags); + for (i = 0; i < keys.length; i++) { + if (re.test(keys[i])) { + val = this.tags[keys[i]].toLowerCase(); + break; + } + } } // swap cardinal for numeric directions @@ -105,7 +111,7 @@ _extend(osmNode.prototype, { var nodeIds = {}; resolver.parentWays(this).forEach(function(parent) { var nodes = parent.nodes; - for (var i = 0; i < nodes.length; i++) { + for (i = 0; i < nodes.length; i++) { if (nodes[i] === this.id) { // match current entity if (lookForward && i > 0) { nodeIds[nodes[i - 1]] = true; // look back to prev node