| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import {UIElement} from "../UIElement"; | 
					
						
							|  |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import State from "../../State"; | 
					
						
							|  |  |  | import CheckBox from "../Input/CheckBox"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import {FixedUiElement} from "../Base/FixedUiElement"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  | import LayerConfig from "../../Customizations/JSON/LayerConfig"; | 
					
						
							| 
									
										
										
										
											2020-07-22 11:49:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-07 15:19:50 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Shows the panel with all layers and a toggle for each of them | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | export default class LayerSelection extends UIElement { | 
					
						
							| 
									
										
										
										
											2020-07-22 11:49:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  |     private _checkboxes: UIElement[]; | 
					
						
							|  |  |  |     private activeLayers: UIEventSource<{ | 
					
						
							|  |  |  |         readonly isDisplayed: UIEventSource<boolean>, | 
					
						
							|  |  |  |         readonly layerDef: LayerConfig; | 
					
						
							|  |  |  |     }[]>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(activeLayers: UIEventSource<{ | 
					
						
							|  |  |  |         readonly isDisplayed: UIEventSource<boolean>, | 
					
						
							|  |  |  |         readonly layerDef: LayerConfig; | 
					
						
							|  |  |  |     }[]>) { | 
					
						
							|  |  |  |         super(activeLayers); | 
					
						
							|  |  |  |         if(activeLayers === undefined){ | 
					
						
							|  |  |  |             throw "ActiveLayers should be defined..." | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this.activeLayers = activeLayers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     InnerRender(): string { | 
					
						
							| 
									
										
										
										
											2020-07-22 11:49:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 16:17:16 +02:00
										 |  |  |         this._checkboxes = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  |         for (const layer of this.activeLayers.data) { | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  |             const leafletStyle = layer.layerDef.GenerateLeafletStyle( | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  |                 new UIEventSource<any>({id: "node/-1"}), | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  |                 false) | 
					
						
							| 
									
										
										
										
											2020-11-27 03:05:29 +01:00
										 |  |  |             const leafletHtml = leafletStyle.icon.html; | 
					
						
							|  |  |  |             const icon = | 
					
						
							| 
									
										
										
										
											2020-12-06 00:20:27 +01:00
										 |  |  |                 new FixedUiElement(leafletHtml.Render()) | 
					
						
							| 
									
										
										
										
											2020-11-27 03:05:29 +01:00
										 |  |  |                     .SetClass("single-layer-selection-toggle") | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  |             let iconUnselected: UIElement = new FixedUiElement(leafletHtml.Render()) | 
					
						
							| 
									
										
										
										
											2020-11-27 03:05:29 +01:00
										 |  |  |                 .SetClass("single-layer-selection-toggle") | 
					
						
							|  |  |  |                 .SetStyle("opacity:0.2;"); | 
					
						
							| 
									
										
										
										
											2020-09-17 19:11:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 01:26:36 +02:00
										 |  |  |             const name = Translations.WT(layer.layerDef.name)?.Clone() | 
					
						
							|  |  |  |                 ?.SetStyle("font-size:large;margin-left: 0.5em;"); | 
					
						
							| 
									
										
										
										
											2020-07-23 16:28:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 17:43:04 +02:00
										 |  |  |             if((name ?? "") === ""){ | 
					
						
							| 
									
										
										
										
											2021-04-21 01:26:36 +02:00
										 |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-17 20:59:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 19:11:16 +02:00
										 |  |  |             const zoomStatus = new VariableUiElement(State.state.locationControl.map(location => { | 
					
						
							| 
									
										
										
										
											2020-09-17 20:59:05 +02:00
										 |  |  |                 if (location.zoom < layer.layerDef.minzoom) { | 
					
						
							| 
									
										
										
										
											2021-01-08 02:13:44 +01:00
										 |  |  |                     return Translations.t.general.layerSelection.zoomInToSeeThisLayer | 
					
						
							| 
									
										
										
										
											2020-09-17 19:11:16 +02:00
										 |  |  |                         .SetClass("alert") | 
					
						
							| 
									
										
										
										
											2020-09-17 20:59:05 +02:00
										 |  |  |                         .SetStyle("display: block ruby;width:min-content;") | 
					
						
							| 
									
										
										
										
											2020-09-17 19:11:16 +02:00
										 |  |  |                         .Render(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return "" | 
					
						
							|  |  |  |             })) | 
					
						
							| 
									
										
										
										
											2021-01-08 14:23:12 +01:00
										 |  |  |             const style = "display:flex;align-items:center;" | 
					
						
							|  |  |  |             const styleWhole = "display:flex; flex-wrap: wrap" | 
					
						
							| 
									
										
										
										
											2020-07-31 16:17:16 +02:00
										 |  |  |             this._checkboxes.push(new CheckBox( | 
					
						
							| 
									
										
										
										
											2021-01-08 14:23:12 +01:00
										 |  |  |                 new Combine([new Combine([icon, name]).SetStyle(style), zoomStatus]) | 
					
						
							|  |  |  |                     .SetStyle(styleWhole), | 
					
						
							|  |  |  |                 new Combine([new Combine([iconUnselected, "<del>", name, "</del>"]).SetStyle(style), zoomStatus]) | 
					
						
							|  |  |  |                     .SetStyle(styleWhole), | 
					
						
							| 
									
										
										
										
											2020-09-13 03:29:44 +02:00
										 |  |  |                 layer.isDisplayed) | 
					
						
							|  |  |  |                 .SetStyle("margin:0.3em;") | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-22 11:49:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 03:29:44 +02:00
										 |  |  |         return new Combine(this._checkboxes) | 
					
						
							|  |  |  |             .SetStyle("display:flex;flex-direction:column;") | 
					
						
							|  |  |  |             .Render(); | 
					
						
							| 
									
										
										
										
											2020-07-22 11:49:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |