mapcomplete/UI/BigComponents/BackgroundSelector.ts

38 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

import {UIElement} from "../UIElement";
import {DropDown} from "../Input/DropDown";
import Translations from "../i18n/Translations";
import State from "../../State";
import {UIEventSource} from "../../Logic/UIEventSource";
2021-01-04 04:36:21 +01:00
import BaseLayer from "../../Models/BaseLayer";
export default class BackgroundSelector extends UIElement {
private _dropdown: UIElement;
private readonly _availableLayers: UIEventSource<BaseLayer[]>;
constructor() {
super();
const self = this;
this._availableLayers = State.state.availableBackgroundLayers;
this._availableLayers.addCallbackAndRun(available => self.CreateDropDown(available));
}
private CreateDropDown(available) {
if(available.length === 0){
2020-09-25 23:00:20 +02:00
return;
}
2020-09-27 01:38:51 +02:00
const baseLayers: { value: BaseLayer, shown: string }[] = [];
for (const i in available) {
2020-09-27 01:38:51 +02:00
const layer: BaseLayer = available[i];
baseLayers.push({value: layer, shown: layer.name ?? "id:" + layer.id});
}
2021-01-02 19:09:49 +01:00
this._dropdown = new DropDown(Translations.t.general.backgroundMap, baseLayers, State.state.backgroundLayer);
}
InnerRender(): string {
return this._dropdown.Render();
}
}