forked from MapComplete/MapComplete
Use arguments
This commit is contained in:
parent
b8b194d04b
commit
a944a26e9c
5 changed files with 27 additions and 6 deletions
|
@ -151,6 +151,9 @@
|
|||
"freeform": {
|
||||
"key": "brand",
|
||||
"type": "nsi",
|
||||
"helperArgs": [
|
||||
"amenity=atm"
|
||||
],
|
||||
"placeholder": {
|
||||
"en": "Brand name",
|
||||
"de": "Markenname",
|
||||
|
|
|
@ -14,12 +14,21 @@
|
|||
*/
|
||||
export let value: UIEventSource<string> = new UIEventSource<string>(undefined)
|
||||
export let feature: Feature
|
||||
export let tags: UIEventSource<Record<string, string>>
|
||||
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()))
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
export let feature: Feature
|
||||
export let args: (string | number | boolean)[] = undefined
|
||||
export let state: SpecialVisualizationState
|
||||
export let tags: UIEventSource<Record<string, string>>
|
||||
export let helperArgs: (string | number | boolean)[]
|
||||
export let key: string
|
||||
|
||||
let properties = { feature, args: args ?? [] }
|
||||
</script>
|
||||
|
@ -52,5 +55,5 @@
|
|||
{:else if type === "wikidata"}
|
||||
<ToSvelte construct={() => InputHelpers.constructWikidataHelper(value, properties)} />
|
||||
{:else if type === "nsi"}
|
||||
<NameSuggestionIndexInput {value} {feature} />
|
||||
<NameSuggestionIndexInput {value} {feature} {tags} {helperArgs} {key} />
|
||||
{/if}
|
||||
|
|
|
@ -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`."],
|
||||
]
|
||||
),
|
||||
]),
|
||||
|
|
|
@ -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<Translation>
|
||||
|
@ -75,6 +77,9 @@
|
|||
type={config.freeform.type}
|
||||
{value}
|
||||
{state}
|
||||
{tags}
|
||||
{helperArgs}
|
||||
{key}
|
||||
on:submit
|
||||
/>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue