From 9c86a4da8bfe9a0a374b9ea9a9bd15ddc0492fda Mon Sep 17 00:00:00 2001 From: Chris Lount Date: Fri, 26 Aug 2022 11:38:48 +0100 Subject: [PATCH] #16 - Ensure map gets built with end nodes --- package-lock.json | 2 +- package.json | 2 +- src/graph.ts | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d701ac49c5e9..3a2075541c61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "openlr_decoder", - "version": "0.2.0", + "version": "0.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5b70bfcd451a..96b29a750275 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openlr_decoder", - "version": "0.4.0", + "version": "0.4.1", "description": "A general purpose road network OpenLR decoding solution", "keywords": [ "openlr", diff --git a/src/graph.ts b/src/graph.ts index 8d874bab66e4..34741452c18e 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -4,10 +4,17 @@ import type {node, linkLookup, nodeChildLink, graphInput} from "./nodes"; export function buildLinkLookups(nodeCollection: Array) { const linkLookup = {}; const graphInput = {}; - nodeCollection.map(node => node.startLinks.map(link => addLinkToGraph(link, linkLookup, graphInput))); + nodeCollection.map(node => checkForEndpoints(node, linkLookup, graphInput)); return {links: linkLookup as linkLookup, graphInput: graphInput as graphInput}; } +function checkForEndpoints(node: node, linkLookup: linkLookup, graphInput: graphInput){ + if(node.startLinks) + node.startLinks.map(link => addLinkToGraph(link, linkLookup, graphInput)); + else + node.endLinks.map(link => addLinkToGraph(link, linkLookup, graphInput)); +} + export function getGraph(input: graphInput){ return new Graph(input); }