mapcomplete/UI/BackgroundSelector.ts

38 lines
1.2 KiB
TypeScript
Raw 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";
2020-09-27 22:48:43 +02:00
import {BaseLayer} from "../Logic/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});
}
2020-09-27 01:38:51 +02:00
this._dropdown = new DropDown(Translations.t.general.backgroundMap, baseLayers, State.state.bm.CurrentLayer);
}
InnerRender(): string {
return this._dropdown.Render();
}
}