mapcomplete/UI/Popup/FeatureInfoBox.ts

61 lines
2.1 KiB
TypeScript
Raw Normal View History

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