forked from MapComplete/MapComplete
		
	More work on splitting roads, WIP; refactoring tests
This commit is contained in:
		
							parent
							
								
									e374bb355c
								
							
						
					
					
						commit
						1f93923820
					
				
					 62 changed files with 1163 additions and 823 deletions
				
			
		|  | @ -2,65 +2,38 @@ import {UIEventSource} from "../UIEventSource"; | |||
| import Translations from "../../UI/i18n/Translations"; | ||||
| import Locale from "../../UI/i18n/Locale"; | ||||
| import TagRenderingAnswer from "../../UI/Popup/TagRenderingAnswer"; | ||||
| import {ElementStorage} from "../ElementStorage"; | ||||
| import Combine from "../../UI/Base/Combine"; | ||||
| import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; | ||||
| 
 | ||||
| class TitleElement extends UIEventSource<string> { | ||||
| export default class TitleHandler { | ||||
|     constructor(state) { | ||||
|         const currentTitle: UIEventSource<string> = state.selectedElement.map( | ||||
|             selected => { | ||||
|                 console.log("UPdating title") | ||||
| 
 | ||||
|     private readonly _layoutToUse: UIEventSource<LayoutConfig>; | ||||
|     private readonly _selectedFeature: UIEventSource<any>; | ||||
|     private readonly _allElementsStorage: ElementStorage; | ||||
| 
 | ||||
|     constructor(layoutToUse: UIEventSource<LayoutConfig>, | ||||
|                 selectedFeature: UIEventSource<any>, | ||||
|                 allElementsStorage: ElementStorage) { | ||||
|         super("MapComplete"); | ||||
| 
 | ||||
|         this._layoutToUse = layoutToUse; | ||||
|         this._selectedFeature = selectedFeature; | ||||
|         this._allElementsStorage = allElementsStorage; | ||||
| 
 | ||||
|         this.syncWith( | ||||
|             this._selectedFeature.map( | ||||
|                 selected => { | ||||
|                     const defaultTitle = Translations.WT(this._layoutToUse.data?.title)?.txt ?? "MapComplete" | ||||
| 
 | ||||
|                     if (selected === undefined) { | ||||
|                         return defaultTitle | ||||
|                     } | ||||
| 
 | ||||
|                     const layout = layoutToUse.data; | ||||
|                     const tags = selected.properties; | ||||
| 
 | ||||
| 
 | ||||
|                     for (const layer of layout.layers) { | ||||
|                         if (layer.title === undefined) { | ||||
|                             continue; | ||||
|                         } | ||||
|                         if (layer.source.osmTags.matchesProperties(tags)) { | ||||
|                             const tagsSource = allElementsStorage.getEventSourceById(tags.id) | ||||
|                             const title = new TagRenderingAnswer(tagsSource, layer.title) | ||||
|                             return new Combine([defaultTitle, " | ", title]).ConstructElement().innerText; | ||||
|                         } | ||||
|                     } | ||||
|                 const layout = state.layoutToUse.data | ||||
|                 const defaultTitle = Translations.WT(layout?.title)?.txt ?? "MapComplete" | ||||
| 
 | ||||
|                 if (selected === undefined) { | ||||
|                     return defaultTitle | ||||
|                 } | ||||
|                 , [Locale.language, layoutToUse] | ||||
|             ) | ||||
| 
 | ||||
|                 const tags = selected.properties; | ||||
|                 for (const layer of layout.layers) { | ||||
|                     if (layer.title === undefined) { | ||||
|                         continue; | ||||
|                     } | ||||
|                     if (layer.source.osmTags.matchesProperties(tags)) { | ||||
|                         const tagsSource = state.allElements.getEventSourceById(tags.id) | ||||
|                         const title = new TagRenderingAnswer(tagsSource, layer.title) | ||||
|                         return new Combine([defaultTitle, " | ", title]).ConstructElement().innerText; | ||||
|                     } | ||||
|                 } | ||||
|                 return defaultTitle | ||||
|             }, [Locale.language, state.layoutToUse] | ||||
|         ) | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export default class TitleHandler { | ||||
|     constructor(layoutToUse: UIEventSource<LayoutConfig>, | ||||
|                 selectedFeature: UIEventSource<any>, | ||||
|                 allElementsStorage: ElementStorage) { | ||||
|         new TitleElement(layoutToUse, selectedFeature, allElementsStorage).addCallbackAndRunD(title => { | ||||
|         currentTitle.addCallbackAndRunD(title => { | ||||
|             document.title = title | ||||
|         }) | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue