mapcomplete/UI/BigComponents/BackgroundSelector.ts

37 lines
1.3 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";
2021-06-12 02:58:32 +02:00
export default class BackgroundSelector extends VariableUiElement {
constructor() {
2021-06-12 02:58:32 +02:00
const available = State.state.availableBackgroundLayers.map(available => {
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});
}
return baseLayers
}
)
2021-06-12 02:58:32 +02:00
super(
available.map(baseLayers => {
if (baseLayers.length <= 1) {
return undefined;
}
2021-09-29 01:12:29 +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
}
)
)
}
}