2022-06-05 02:24:14 +02:00
|
|
|
import { Store, UIEventSource } from "../UIEventSource"
|
2021-01-08 18:02:07 +01:00
|
|
|
import Locale from "../../UI/i18n/Locale"
|
2021-01-25 03:12:09 +01:00
|
|
|
import Combine from "../../UI/Base/Combine"
|
2021-10-20 00:09:40 +02:00
|
|
|
import { Utils } from "../../Utils"
|
2023-03-28 05:13:48 +02:00
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
|
|
import { Feature } from "geojson"
|
|
|
|
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
|
2023-03-29 17:21:20 +02:00
|
|
|
import SvelteUIElement from "../../UI/Base/SvelteUIElement"
|
2023-03-31 03:28:11 +02:00
|
|
|
import TagRenderingAnswer from "../../UI/Popup/TagRendering/TagRenderingAnswer.svelte"
|
|
|
|
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
|
2021-01-08 18:02:07 +01:00
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
export default class TitleHandler {
|
2023-03-28 05:13:48 +02:00
|
|
|
constructor(
|
|
|
|
selectedElement: Store<Feature>,
|
|
|
|
selectedLayer: Store<LayerConfig>,
|
|
|
|
allElements: FeaturePropertiesStore,
|
2023-03-31 03:28:11 +02:00
|
|
|
state: SpecialVisualizationState
|
2023-03-28 05:13:48 +02:00
|
|
|
) {
|
2023-03-25 02:48:24 +01:00
|
|
|
const currentTitle: Store<string> = selectedElement.map(
|
2021-09-22 05:02:09 +02:00
|
|
|
(selected) => {
|
2023-03-31 03:28:11 +02:00
|
|
|
const defaultTitle = state.layout?.title?.txt ?? "MapComplete"
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2023-04-02 02:59:20 +02:00
|
|
|
if (selected === undefined || selectedLayer.data === undefined) {
|
2021-09-22 05:02:09 +02:00
|
|
|
return defaultTitle
|
|
|
|
}
|
2021-03-21 02:03:07 +01:00
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
const tags = selected.properties
|
2023-04-02 02:59:20 +02:00
|
|
|
const layer = selectedLayer.data
|
2023-04-06 01:33:08 +02:00
|
|
|
if (layer.title === undefined) {
|
|
|
|
return defaultTitle
|
|
|
|
}
|
2023-04-02 02:59:20 +02:00
|
|
|
const tagsSource =
|
|
|
|
allElements.getStore(tags.id) ?? new UIEventSource<Record<string, string>>(tags)
|
|
|
|
const title = new SvelteUIElement(TagRenderingAnswer, {
|
|
|
|
tags: tagsSource,
|
|
|
|
state,
|
2023-04-06 01:33:08 +02:00
|
|
|
config: layer.title,
|
2023-04-02 02:59:20 +02:00
|
|
|
selectedElement: selectedElement.data,
|
|
|
|
layer,
|
|
|
|
})
|
|
|
|
return (
|
|
|
|
new Combine([defaultTitle, " | ", title]).ConstructElement()?.textContent ??
|
|
|
|
defaultTitle
|
|
|
|
)
|
2021-09-28 18:00:44 +02:00
|
|
|
},
|
2023-03-28 05:13:48 +02:00
|
|
|
[Locale.language, selectedLayer]
|
2021-06-11 22:51:45 +02:00
|
|
|
)
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
currentTitle.addCallbackAndRunD((title) => {
|
2021-11-07 16:34:51 +01:00
|
|
|
if (Utils.runningFromConsole) {
|
2021-10-20 00:09:40 +02:00
|
|
|
return
|
|
|
|
}
|
2022-10-27 01:50:41 +02:00
|
|
|
try {
|
|
|
|
document.title = title
|
|
|
|
} catch (e) {
|
2022-09-20 16:03:28 +02:00
|
|
|
console.error(e)
|
|
|
|
}
|
2021-03-21 02:03:07 +01:00
|
|
|
})
|
2021-01-08 18:02:07 +01:00
|
|
|
}
|
|
|
|
}
|