diff --git a/assets/layers/atm/atm.json b/assets/layers/atm/atm.json index 9c36ede46a..5651d1f75f 100644 --- a/assets/layers/atm/atm.json +++ b/assets/layers/atm/atm.json @@ -151,6 +151,9 @@ "freeform": { "key": "brand", "type": "nsi", + "helperArgs": [ + "amenity=atm" + ], "placeholder": { "en": "Brand name", "de": "Markenname", diff --git a/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte b/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte index d05b352f73..6a4957cbaa 100644 --- a/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte +++ b/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte @@ -14,12 +14,21 @@ */ export let value: UIEventSource = new UIEventSource(undefined) export let feature: Feature + export let tags: UIEventSource> + export let helperArgs: (string | number | boolean)[] + export let key: string - // Currently hardcoded, should be dynamic - let maintag = "amenity=atm" - let tag = "brand" + let maintag = helperArgs[0].toString() + let tag = key const path = `${tag}s/${maintag.split("=")[0]}/${maintag.split("=")[1]}` + + // Check if the path exists in the NSI file + if (!nsiFile.nsi[path]) { + console.error(`Path ${path} does not exist in the NSI file`) + throw new Error(`Path ${path} does not exist in the NSI file`) + } + let items = nsiFile.nsi[path].items // Get the coordinates if the feature is a point, otherwise use the center @@ -34,7 +43,9 @@ lat = feature.bbox[1] + (feature.bbox[3] - feature.bbox[1]) / 2 } - // Filter the items + /** + * Filter the items, first by the display name, then by the location set + */ let filter = "" $: filteredItems = items .filter((item) => item.displayName.toLowerCase().includes(filter.toLowerCase())) diff --git a/src/UI/InputElement/InputHelper.svelte b/src/UI/InputElement/InputHelper.svelte index e7676dde86..581b38815b 100644 --- a/src/UI/InputElement/InputHelper.svelte +++ b/src/UI/InputElement/InputHelper.svelte @@ -27,6 +27,9 @@ export let feature: Feature export let args: (string | number | boolean)[] = undefined export let state: SpecialVisualizationState + export let tags: UIEventSource> + export let helperArgs: (string | number | boolean)[] + export let key: string let properties = { feature, args: args ?? [] } @@ -52,5 +55,5 @@ {:else if type === "wikidata"} InputHelpers.constructWikidataHelper(value, properties)} /> {:else if type === "nsi"} - + {/if} diff --git a/src/UI/InputElement/Validators/NameSuggestionIndexValidator.ts b/src/UI/InputElement/Validators/NameSuggestionIndexValidator.ts index 2cfebde862..09625378dc 100644 --- a/src/UI/InputElement/Validators/NameSuggestionIndexValidator.ts +++ b/src/UI/InputElement/Validators/NameSuggestionIndexValidator.ts @@ -24,7 +24,6 @@ export default class NameSuggestionIndexValidator extends Validator { "main", "The main tag to give suggestions for, e.g. `amenity=restaurant`.", ], - ["key", "The key to give suggestions for, e.g. `brand`."], ] ), ]), diff --git a/src/UI/Popup/TagRendering/FreeformInput.svelte b/src/UI/Popup/TagRendering/FreeformInput.svelte index e0c85b22d2..aca885e436 100644 --- a/src/UI/Popup/TagRendering/FreeformInput.svelte +++ b/src/UI/Popup/TagRendering/FreeformInput.svelte @@ -27,6 +27,8 @@ inline = false inline = config.freeform?.inline } + let helperArgs = config.freeform?.helperArgs + let key = config.freeform?.key const dispatch = createEventDispatcher<{ selected }>() export let feedback: UIEventSource @@ -75,6 +77,9 @@ type={config.freeform.type} {value} {state} + {tags} + {helperArgs} + {key} on:submit />