| 
									
										
										
										
											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 TagRenderingAnswer from "../../UI/Popup/TagRenderingAnswer" | 
					
						
							|  |  |  | import Combine from "../../UI/Base/Combine" | 
					
						
							| 
									
										
										
										
											2021-09-28 18:00:44 +02:00
										 |  |  | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  | import { ElementStorage } from "../ElementStorage" | 
					
						
							| 
									
										
										
										
											2021-10-20 00:09:40 +02:00
										 |  |  | import { Utils } from "../../Utils" | 
					
						
							| 
									
										
										
										
											2021-01-08 18:02:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  | export default class TitleHandler { | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |     constructor(state: { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         selectedElement: Store<any> | 
					
						
							| 
									
										
										
										
											2021-09-28 18:00:44 +02:00
										 |  |  |         layoutToUse: LayoutConfig | 
					
						
							|  |  |  |         allElements: ElementStorage | 
					
						
							|  |  |  |     }) { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         const currentTitle: Store<string> = state.selectedElement.map( | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |             (selected) => { | 
					
						
							| 
									
										
										
										
											2021-09-28 18:00:44 +02:00
										 |  |  |                 const layout = state.layoutToUse | 
					
						
							| 
									
										
										
										
											2022-04-21 12:39:28 +02:00
										 |  |  |                 const defaultTitle = layout?.title?.txt ?? "MapComplete" | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 if (selected === undefined) { | 
					
						
							|  |  |  |                     return defaultTitle | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-03-21 02:03:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 const tags = selected.properties | 
					
						
							|  |  |  |                 for (const layer of layout.layers) { | 
					
						
							|  |  |  |                     if (layer.title === undefined) { | 
					
						
							|  |  |  |                         continue | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                     if (layer.source.osmTags.matchesProperties(tags)) { | 
					
						
							| 
									
										
										
										
											2021-11-08 14:18:45 +01:00
										 |  |  |                         const tagsSource = | 
					
						
							|  |  |  |                             state.allElements.getEventSourceById(tags.id) ?? | 
					
						
							|  |  |  |                             new UIEventSource<any>(tags) | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |                         const title = new TagRenderingAnswer(tagsSource, layer.title, {}) | 
					
						
							| 
									
										
										
										
											2022-06-28 03:21:18 +02:00
										 |  |  |                         return ( | 
					
						
							|  |  |  |                             new Combine([defaultTitle, " | ", title]).ConstructElement() | 
					
						
							|  |  |  |                                 ?.textContent ?? defaultTitle | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                         ) | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-04-17 23:36:46 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 return defaultTitle | 
					
						
							| 
									
										
										
										
											2021-09-28 18:00:44 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             [Locale.language] | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |             document.title = title | 
					
						
							| 
									
										
										
										
											2021-03-21 02:03:07 +01:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-01-08 18:02:07 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |