2021-01-04 04:06:21 +01:00
|
|
|
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";
|
2020-09-25 21:58:29 +02:00
|
|
|
|
|
|
|
export default class BackgroundSelector extends UIElement {
|
|
|
|
|
|
|
|
private _dropdown: UIElement;
|
2020-09-28 00:30:39 +02:00
|
|
|
private readonly _availableLayers: UIEventSource<BaseLayer[]>;
|
2020-09-25 21:58:29 +02:00
|
|
|
|
2020-09-28 00:30:39 +02:00
|
|
|
constructor() {
|
2020-09-25 21:58:29 +02:00
|
|
|
super();
|
|
|
|
const self = this;
|
2020-09-28 00:30:39 +02:00
|
|
|
this._availableLayers = State.state.availableBackgroundLayers;
|
2020-09-25 21:58:29 +02:00
|
|
|
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-25 21:58:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-27 01:38:51 +02:00
|
|
|
const baseLayers: { value: BaseLayer, shown: string }[] = [];
|
2020-09-25 21:58:29 +02:00
|
|
|
for (const i in available) {
|
2020-09-27 01:38:51 +02:00
|
|
|
const layer: BaseLayer = available[i];
|
2020-09-27 23:37:47 +02:00
|
|
|
baseLayers.push({value: layer, shown: layer.name ?? "id:" + layer.id});
|
2020-09-25 21:58:29 +02:00
|
|
|
}
|
|
|
|
|
2021-01-02 19:09:49 +01:00
|
|
|
this._dropdown = new DropDown(Translations.t.general.backgroundMap, baseLayers, State.state.backgroundLayer);
|
2020-09-25 21:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
return this._dropdown.Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|