mapcomplete/UI/Popup/FeatureInfoBox.ts

57 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-10-14 12:15:09 +02:00
import {UIElement} from "../UIElement";
import {UIEventSource} from "../../Logic/UIEventSource";
2020-10-27 01:01:34 +01:00
import LayerConfig from "../../Customizations/JSON/LayerConfig";
import EditableTagRendering from "./EditableTagRendering";
import QuestionBox from "./QuestionBox";
import Combine from "../Base/Combine";
import TagRenderingAnswer from "./TagRenderingAnswer";
import State from "../../State";
export class FeatureInfoBox extends UIElement {
2020-10-27 01:01:34 +01:00
private _tags: UIEventSource<any>;
private _layerConfig: LayerConfig;
2020-10-27 01:01:34 +01:00
private _title : UIElement;
private _titleIcons: UIElement;
private _renderings: UIElement[];
private _questionBox : UIElement;
constructor(
2020-10-27 01:01:34 +01:00
tags: UIEventSource<any>,
layerConfig: LayerConfig
) {
2020-10-27 01:01:34 +01:00
super();
2020-11-17 16:29:51 +01:00
if (layerConfig === undefined) {
2020-11-02 18:59:21 +01:00
throw "Undefined layerconfig"
}
2020-10-27 01:01:34 +01:00
this._tags = tags;
this._layerConfig = layerConfig;
2020-09-13 00:53:24 +02:00
2020-11-17 02:22:48 +01:00
this._title = layerConfig.title === undefined ? undefined :
new TagRenderingAnswer(tags, layerConfig.title)
2020-11-17 16:29:51 +01:00
.SetClass("featureinfobox-title");
2020-10-27 01:01:34 +01:00
this._titleIcons = new Combine(
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon)))
.SetClass("featureinfobox-icons");
this._renderings = layerConfig.tagRenderings.map(tr => new EditableTagRendering(tags, tr));
if (State.state.featureSwitchUserbadge.data) {
this._questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
}
}
InnerRender(): string {
2020-09-13 00:53:24 +02:00
return new Combine([
2020-10-27 01:01:34 +01:00
new Combine([this._title, this._titleIcons])
.SetClass("featureinfobox-titlebar"),
new Combine([
...this._renderings,
this._questionBox
]
).SetClass("featureinfobox-content"),
]).SetClass("featureinfobox")
.Render();
}
2020-07-20 15:54:50 +02:00
}