mapcomplete/UI/BigComponents/BackgroundSelector.ts

35 lines
1.2 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-06-14 17:42:26 +02:00
return new DropDown(Translations.t.general.backgroundMap.Clone(), baseLayers, State.state.backgroundLayer)
2021-06-12 02:58:32 +02:00
}
)
)
}
}