| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {AllKnownLayouts} from "../../Customizations/AllKnownLayouts"; | 
					
						
							|  |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import State from "../../State"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  | import Toggle from "../Input/Toggle"; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {SubtleButton} from "../Base/SubtleButton"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import LayerConfig from "../../Customizations/JSON/LayerConfig"; | 
					
						
							|  |  |  | import Img from "../Base/Img"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  | export default class PersonalLayersPanel extends VariableUiElement { | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  |     constructor() { | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |         super( | 
					
						
							|  |  |  |             State.state.installedThemes.map(installedThemes => { | 
					
						
							|  |  |  |                 const t = Translations.t.favourite; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // Lets get all the layers
 | 
					
						
							|  |  |  |                 const allThemes = AllKnownLayouts.layoutsList.concat(installedThemes.map(layout => layout.layout)) | 
					
						
							|  |  |  |                     .filter(theme => !theme.hideFromOverview) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const allLayers = [] | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     const seenLayers = new Set<string>() | 
					
						
							|  |  |  |                     for (const layers of allThemes.map(theme => theme.layers)) { | 
					
						
							|  |  |  |                         for (const layer of layers) { | 
					
						
							|  |  |  |                             if (seenLayers.has(layer.id)) { | 
					
						
							|  |  |  |                                 continue | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             seenLayers.add(layer.id) | 
					
						
							|  |  |  |                             allLayers.push(layer) | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |                 // Time to create a panel based on them!
 | 
					
						
							|  |  |  |                 const panel: BaseUIElement = new Combine(allLayers.map(PersonalLayersPanel.CreateLayerToggle)); | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |                 return new Toggle( | 
					
						
							|  |  |  |                     new Combine([ | 
					
						
							|  |  |  |                         t.panelIntro.Clone(), | 
					
						
							|  |  |  |                         panel | 
					
						
							|  |  |  |                     ]).SetClass("flex flex-col"), | 
					
						
							|  |  |  |                     new SubtleButton( | 
					
						
							|  |  |  |                         Svg.osm_logo_ui(), | 
					
						
							|  |  |  |                         t.loginNeeded.Clone().SetClass("text-center") | 
					
						
							|  |  |  |                     ).onClick(() => State.state.osmConnection.AttemptLogin()), | 
					
						
							|  |  |  |                     State.state.osmConnection.isLoggedIn | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |     /*** | 
					
						
							|  |  |  |      * Creates a toggle for the given layer, which'll update State.state.favouriteLayers right away | 
					
						
							|  |  |  |      * @param layer | 
					
						
							|  |  |  |      * @constructor | 
					
						
							|  |  |  |      * @private | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private static CreateLayerToggle(layer: LayerConfig): Toggle { | 
					
						
							|  |  |  |         let icon :BaseUIElement =new Combine([ layer.GenerateLeafletStyle( | 
					
						
							|  |  |  |             new UIEventSource<any>({id: "node/-1"}), | 
					
						
							|  |  |  |             false, | 
					
						
							|  |  |  |             "2em" | 
					
						
							|  |  |  |         ).icon.html]).SetClass("relative") | 
					
						
							|  |  |  |         let iconUnset =new Combine([ layer.GenerateLeafletStyle( | 
					
						
							|  |  |  |             new UIEventSource<any>({id: "node/-1"}), | 
					
						
							|  |  |  |             false, | 
					
						
							|  |  |  |             "2em" | 
					
						
							|  |  |  |         ).icon.html]).SetClass("relative") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         iconUnset.SetStyle("opacity:0.1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let name = layer.name ; | 
					
						
							|  |  |  |         if (name === undefined) { | 
					
						
							|  |  |  |             return undefined; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const content = new Combine([ | 
					
						
							|  |  |  |             Translations.WT(name).Clone().SetClass("font-bold"), | 
					
						
							|  |  |  |             Translations.WT(layer.description)?.Clone() | 
					
						
							|  |  |  |         ]).SetClass("flex flex-col") | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |         const contentUnselected = new Combine([ | 
					
						
							|  |  |  |             Translations.WT(name).Clone().SetClass("font-bold"), | 
					
						
							|  |  |  |             Translations.WT(layer.description)?.Clone() | 
					
						
							|  |  |  |         ]).SetClass("flex flex-col line-through") | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         return new Toggle( | 
					
						
							| 
									
										
										
										
											2021-06-19 19:16:20 +02:00
										 |  |  |             new SubtleButton( | 
					
						
							|  |  |  |                 icon, | 
					
						
							|  |  |  |                 content ), | 
					
						
							|  |  |  |             new SubtleButton( | 
					
						
							|  |  |  |                 iconUnset, | 
					
						
							|  |  |  |                 contentUnselected | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             State.state.favouriteLayers.map(favLayers => { | 
					
						
							|  |  |  |                 return favLayers.indexOf(layer.id) >= 0 | 
					
						
							|  |  |  |             }, [], (selected, current) => { | 
					
						
							|  |  |  |                 if (!selected && current.indexOf(layer.id) <= 0) { | 
					
						
							|  |  |  |                     // Not selected and not contained: nothing to change: we return current as is
 | 
					
						
							|  |  |  |                     return current; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (selected && current.indexOf(layer.id) >= 0) { | 
					
						
							|  |  |  |                     // Selected and contained: this is fine!
 | 
					
						
							|  |  |  |                     return current; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 const clone = [...current] | 
					
						
							|  |  |  |                 if (selected) { | 
					
						
							|  |  |  |                     clone.push(layer.id) | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     clone.splice(clone.indexOf(layer.id), 1) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return clone | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         ).ToggleOnClick(); | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |