From 0ae8b6825520e113870862c96065f707e9c00bb0 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Mon, 12 Jun 2023 18:26:53 +0200 Subject: [PATCH] Adding a level in tag definitions to support routes (in addition to POIs) --- src/lib/osm/tagsStatus.test.ts | 8 +++--- src/lib/osm/tagsStatus.ts | 48 ++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/lib/osm/tagsStatus.test.ts b/src/lib/osm/tagsStatus.test.ts index 5417a86..ed1dbd3 100644 --- a/src/lib/osm/tagsStatus.test.ts +++ b/src/lib/osm/tagsStatus.test.ts @@ -11,11 +11,12 @@ describe('The getTagStatus function', () => { expect( getTagStatus( 'whatever', - { hiking: { eating: { whatever: {} } } }, + { hiking: { route: { eating: { whatever: {} } } } }, 'hiking', 'eating' ) ).toEqual({ + type: 'route', definition: {}, highlighted: true, }); @@ -24,11 +25,12 @@ describe('The getTagStatus function', () => { expect( getTagStatus( 'whatever', - { hiking: { sleeping: { whatever: {} } } }, + { hiking: { route: { eating: { whatever: {} } } } }, 'hiking', - 'eating' + 'sleeping' ) ).toEqual({ + type: 'route', definition: {}, highlighted: false, }); diff --git a/src/lib/osm/tagsStatus.ts b/src/lib/osm/tagsStatus.ts index 77932a4..e438855 100644 --- a/src/lib/osm/tagsStatus.ts +++ b/src/lib/osm/tagsStatus.ts @@ -4,8 +4,14 @@ interface TagCategoryDefinitions { [key: string]: TagFormatDefinition; } +enum TagType { + POI = 'poi', + ROUTE = 'route', +} + interface TagActivityDefinitions { - [key: string]: TagCategoryDefinitions; + poi?: { [key: string]: TagCategoryDefinitions }; + route?: { [key: string]: TagCategoryDefinitions }; } interface TagDefinitions { @@ -13,6 +19,7 @@ interface TagDefinitions { } interface TagStatus { + type?: TagType; definition?: TagFormatDefinition; highlighted: boolean; } @@ -31,21 +38,34 @@ export const getTagStatus = ( return defaultStatus; } - const highlightedDefinitions = activityDefinitions[highlightedKey]; + for (const type of Object.values(TagType)) { + const typeDefinitions = activityDefinitions[type as TagType]; - if (!!highlightedDefinitions) { - const definition = highlightedDefinitions[tag]; - if (!!definition) { - return { definition, highlighted: true }; - } - } + if (!!typeDefinitions) { + const highlightedDefinitions = typeDefinitions[highlightedKey]; - for (const category of Object.keys(activityDefinitions)) { - if (category !== highlightedKey) { - const categoryDefinitions = activityDefinitions[category]; - const definition = categoryDefinitions[tag]; - if (!!definition) { - return { definition, highlighted: false }; + if (!!highlightedDefinitions) { + const definition = highlightedDefinitions[tag]; + if (!!definition) { + return { type, definition, highlighted: true }; + } + } + + for (const category of Object.keys(typeDefinitions)) { + if (category !== highlightedKey) { + const categoryDefinitions = typeDefinitions[category]; + console.log({ + caller: 'getTagStatus / looping over categories', + type, + typeDefinitions, + category, + categoryDefinitions, + }); + const definition = categoryDefinitions[tag]; + if (!!definition) { + return { type, definition, highlighted: false }; + } + } } } }