mapcomplete/UI/Popup/FeatureInfoBox.ts

71 lines
2.4 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";
2021-01-07 03:50:12 +00:00
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
2021-01-08 01:13:44 +00:00
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
export default class FeatureInfoBox extends UIElement {
2021-01-08 01:13:44 +00:00
private _component: UIElement;
2021-01-09 01:11:43 +00:00
public title: UIElement ;
2021-01-08 17:02:07 +00:00
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-09-12 22:53:24 +00:00
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI", undefined))
2021-01-07 03:50:12 +00:00
.SetClass("featureinfobox-title");
2021-01-08 17:02:07 +00:00
this.title = title;
2021-01-08 01:13:44 +00:00
const titleIcons = new Combine(
2020-10-27 00:01:34 +00:00
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;
2021-01-08 01:13:44 +00:00
const 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);
});
2021-01-08 01:13:44 +00:00
renderings[0]?.SetClass("first-rendering");
if (!questionBoxIsUsed) {
2021-01-08 01:13:44 +00:00
renderings.push(questionBox);
}
2021-01-08 15:49:42 +00:00
const tail = new Combine([]).SetClass("only-on-mobile");
2021-01-08 01:13:44 +00:00
const content = new Combine([
...renderings,
tail.SetClass("featureinfobox-tail")
]
)
const titleBar = new Combine([
new Combine([title, titleIcons]).SetClass("featureinfobox-titlebar-title")
])
this._component = new ScrollableFullScreen(titleBar, content)
}
InnerRender(): string {
2021-01-08 01:13:44 +00:00
return this._component.Render();
}
2020-07-20 13:54:50 +00:00
}