mapcomplete/UI/BigComponents/BackgroundSelector.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.5 KiB
TypeScript
Raw Normal View History

import { DropDown } from "../Input/DropDown"
import Translations from "../i18n/Translations"
import State from "../../State"
2021-01-04 04:36:21 +01:00
import BaseLayer from "../../Models/BaseLayer"
2021-06-12 02:58:32 +02:00
import { VariableUiElement } from "../Base/VariableUIElement"
2022-08-20 12:46:33 +02:00
import { Store } from "../../Logic/UIEventSource"
2021-06-12 02:58:32 +02:00
export default class BackgroundSelector extends VariableUiElement {
2022-08-20 12:46:33 +02:00
constructor(state: { availableBackgroundLayers?: Store<BaseLayer[]> }) {
const available = state.availableBackgroundLayers?.map((available) => {
if (available === undefined) {
return undefined
}
2021-06-12 02:58:32 +02:00
const baseLayers: { value: BaseLayer; shown: string }[] = []
for (const i in available) {
if (!available.hasOwnProperty(i)) {
2021-06-12 02:58:32 +02:00
continue
}
const layer: BaseLayer = available[i]
baseLayers.push({ value: layer, shown: layer.name ?? "id:" + layer.id })
}
2021-09-29 01:12:29 +02:00
return baseLayers
2021-06-12 02:58:32 +02:00
})
2021-06-12 02:58:32 +02:00
super(
2022-08-20 12:46:33 +02:00
available?.map((baseLayers) => {
if (baseLayers === undefined || baseLayers.length <= 1) {
2021-06-12 02:58:32 +02:00
return undefined
}
2021-09-29 01:12:29 +02:00
return new DropDown(
Translations.t.general.backgroundMap.Clone(),
baseLayers,
State.state.backgroundLayer,
2022-09-08 21:40:48 +02:00
{
2021-09-29 01:12:29 +02:00
select_class: "bg-indigo-100 p-1 rounded hover:bg-indigo-200 w-full",
2022-09-08 21:40:48 +02:00
}
2021-06-12 02:58:32 +02:00
)
2022-09-08 21:40:48 +02:00
})
2021-06-12 02:58:32 +02:00
)
}
}