mapcomplete/UI/BigComponents/BackgroundSelector.ts

42 lines
1.5 KiB
TypeScript
Raw Normal View History

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