mapcomplete/UI/CenterMessageBox.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-06-23 22:35:19 +00:00
import {UIElement} from "./UIElement";
import {UIEventSource} from "./UIEventSource";
2020-07-30 07:59:30 +00:00
import {OsmConnection} from "../Logic/Osm/OsmConnection";
2020-07-20 21:43:42 +00:00
import Translations from "./i18n/Translations";
import {State} from "../State";
2020-06-23 22:35:19 +00:00
export class CenterMessageBox extends UIElement {
private readonly _queryRunning: UIEventSource<boolean>;
private startZoom: number;
2020-06-23 22:35:19 +00:00
constructor(
startZoom: number,
queryRunning: UIEventSource<boolean>
) {
super(State.state.centerMessage);
this.startZoom = startZoom;
2020-06-23 22:35:19 +00:00
this.ListenTo(State.state.locationControl);
2020-06-23 22:35:19 +00:00
this.ListenTo(queryRunning);
this._queryRunning = queryRunning;
2020-06-23 22:35:19 +00:00
}
private prep(): { innerHtml: string, done: boolean } {
if (State.state.centerMessage.data != "") {
return {innerHtml: State.state.centerMessage.data, done: false};
2020-06-23 22:35:19 +00:00
}
2020-07-18 22:13:45 +00:00
if (this._queryRunning.data) {
return {innerHtml: Translations.t.centerMessage.loadingData.Render(), done: false};
} else if (State.state.locationControl.data.zoom < this.startZoom) {
return {innerHtml: Translations.t.centerMessage.zoomIn.Render(), done: false};
} else {
return {innerHtml: Translations.t.centerMessage.ready.Render(), done: true};
2020-06-23 22:35:19 +00:00
}
}
InnerRender(): string {
return this.prep().innerHtml;
2020-06-23 22:35:19 +00:00
}
2020-06-23 22:35:19 +00:00
InnerUpdate(htmlElement: HTMLElement) {
const pstyle = htmlElement.parentElement.style;
if (State.state.centerMessage.data != "") {
2020-06-23 22:35:19 +00:00
pstyle.opacity = "1";
pstyle.pointerEvents = "all";
State.state.osmConnection.registerActivateOsmAUthenticationClass();
2020-06-23 22:35:19 +00:00
return;
}
pstyle.pointerEvents = "none";
if (this.prep().done) {
2020-06-23 22:35:19 +00:00
pstyle.opacity = "0";
} else {
pstyle.opacity = "0.5";
2020-06-23 22:35:19 +00:00
}
}
}