mapcomplete/UI/Popup/FeatureInfoBox.ts

86 lines
3.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";
2021-01-07 03:50:12 +00:00
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import Svg from "../../Svg";
import Ornament from "../Base/Ornament";
export default class FeatureInfoBox extends UIElement {
2020-10-27 00:01:34 +00:00
private _tags: UIEventSource<any>;
private _layerConfig: LayerConfig;
private _title: UIElement;
2020-10-27 00:01:34 +00:00
private _titleIcons: UIElement;
private _renderings: UIElement[];
private _questionBox: UIElement;
2021-01-07 03:50:12 +00:00
private _returnToTheMap: UIElement;
private _tail: 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;
2021-01-07 03:50:12 +00:00
this._returnToTheMap = Svg.back_svg().onClick(() => {
State.state.fullScreenMessage.setData(undefined);
State.state.selectedElement.setData(undefined);
}).SetClass("only-on-mobile")
.SetClass("featureinfobox-back-to-the-map")
2020-09-12 22:53:24 +00:00
2021-01-07 03:50:12 +00:00
this._title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI"))
.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");
let questionBox: UIElement = undefined;
if (State.state.featureSwitchUserbadge.data) {
2020-12-08 22:44:34 +00:00
questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
}
2020-12-08 22:44:34 +00:00
let questionBoxIsUsed = false;
this._renderings = layerConfig.tagRenderings.map(tr => {
if (tr.question === null) {
2020-12-08 22:44:34 +00:00
questionBoxIsUsed = true;
// This is the question box!
return questionBox;
}
return new EditableTagRendering(tags, tr);
});
this._renderings[0]?.SetClass("first-rendering");
if (!questionBoxIsUsed) {
this._renderings.push(questionBox);
}
2021-01-07 03:50:12 +00:00
this._tail = new Combine([new Ornament()]).SetClass("only-on-mobile");
}
InnerRender(): string {
2020-09-12 22:53:24 +00:00
return new Combine([
2021-01-07 03:50:12 +00:00
new Combine([
this._returnToTheMap, new Combine([this._title, this._titleIcons]).SetClass("featureinfobox-titlebar-title")
]).SetClass("featureinfobox-titlebar"),
new Combine([
...this._renderings,
2020-11-24 10:10:43 +00:00
this._questionBox,
2021-01-07 03:50:12 +00:00
this._tail.SetClass("featureinfobox-tail")
]
).SetClass("featureinfobox-content"),
]).SetClass("featureinfobox")
.Render();
}
2020-07-20 13:54:50 +00:00
}