mapcomplete/UI/Popup/FeatureInfoBox.ts

71 lines
2.4 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";
2021-01-07 04:50:12 +01:00
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
2021-01-08 02:13:44 +01:00
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
export default class FeatureInfoBox extends UIElement {
2021-01-08 02:13:44 +01:00
private _component: UIElement;
2021-01-09 02:11:43 +01:00
public title: UIElement ;
2021-01-08 18:02:07 +01:00
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-09-13 00:53:24 +02:00
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI", undefined))
2021-01-07 04:50:12 +01:00
.SetClass("featureinfobox-title");
2021-01-08 18:02:07 +01:00
this.title = title;
2021-01-08 02:13:44 +01:00
const titleIcons = new Combine(
2020-10-27 01:01:34 +01:00
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon)))
.SetClass("featureinfobox-icons");
let questionBox: UIElement = undefined;
if (State.state.featureSwitchUserbadge.data) {
2020-12-08 23:44:34 +01:00
questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
}
2020-12-08 23:44:34 +01:00
let questionBoxIsUsed = false;
2021-01-08 02:13:44 +01:00
const renderings = layerConfig.tagRenderings.map(tr => {
if (tr.question === null) {
2020-12-08 23:44:34 +01:00
questionBoxIsUsed = true;
// This is the question box!
return questionBox;
}
return new EditableTagRendering(tags, tr);
});
2021-01-08 02:13:44 +01:00
renderings[0]?.SetClass("first-rendering");
if (!questionBoxIsUsed) {
2021-01-08 02:13:44 +01:00
renderings.push(questionBox);
}
2021-01-08 16:49:42 +01:00
const tail = new Combine([]).SetClass("only-on-mobile");
2021-01-08 02:13:44 +01: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 02:13:44 +01:00
return this._component.Render();
}
2020-07-20 15:54:50 +02:00
}