| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | <script lang="ts">/** | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |  * The FilterView shows the various options to enable/disable a single layer or to only show a subset of the data. | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | import type FilteredLayer from "../../Models/FilteredLayer"; | 
					
						
							|  |  |  | import LayerConfig from "../../Models/ThemeConfig/LayerConfig"; | 
					
						
							|  |  |  | import ToSvelte from "../Base/ToSvelte.svelte"; | 
					
						
							|  |  |  | import Checkbox from "../Base/Checkbox.svelte"; | 
					
						
							|  |  |  | import FilterConfig from "../../Models/ThemeConfig/FilterConfig"; | 
					
						
							|  |  |  | import type { Writable } from "svelte/store"; | 
					
						
							|  |  |  | import If from "../Base/If.svelte"; | 
					
						
							|  |  |  | import Dropdown from "../Base/Dropdown.svelte"; | 
					
						
							|  |  |  | import { onDestroy } from "svelte"; | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | import { UIEventSource } from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import FilterviewWithFields from "./FilterviewWithFields.svelte"; | 
					
						
							|  |  |  | import Tr from "../Base/Tr.svelte"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export let filteredLayer: FilteredLayer; | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | export let highlightedLayer: UIEventSource<string> | undefined; | 
					
						
							|  |  |  | export let zoomlevel: UIEventSource<number>; | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | let layer: LayerConfig = filteredLayer.layerDef; | 
					
						
							|  |  |  | let isDisplayed: boolean = filteredLayer.isDisplayed.data; | 
					
						
							|  |  |  | onDestroy(filteredLayer.isDisplayed.addCallbackAndRunD(d => { | 
					
						
							|  |  |  |   isDisplayed = d; | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Gets a UIEventSource as boolean for the given option, to be used with a checkbox | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function getBooleanStateFor(option: FilterConfig): Writable<boolean> { | 
					
						
							|  |  |  |   const state = filteredLayer.appliedFilters.get(option.id); | 
					
						
							|  |  |  |   return state.sync(f => f === 0, [], (b) => b ? 0 : undefined); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Gets a UIEventSource as number for the given option, to be used with a dropdown or radiobutton | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function getStateFor(option: FilterConfig): Writable<number> { | 
					
						
							|  |  |  |   return filteredLayer.appliedFilters.get(option.id); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | let mainElem: HTMLElement; | 
					
						
							|  |  |  | $:  onDestroy( | 
					
						
							|  |  |  |   highlightedLayer.addCallbackAndRun(highlightedLayer => { | 
					
						
							|  |  |  |     if (highlightedLayer === filteredLayer.layerDef.id) { | 
					
						
							|  |  |  |       mainElem?.classList?.add("glowing-shadow"); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       mainElem?.classList?.remove("glowing-shadow"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | {#if filteredLayer.layerDef.name} | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   <div bind:this={mainElem}> | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |     <label class="flex gap-1"> | 
					
						
							|  |  |  |       <Checkbox selected={filteredLayer.isDisplayed} /> | 
					
						
							|  |  |  |       <If condition={filteredLayer.isDisplayed}> | 
					
						
							|  |  |  |         <ToSvelte construct={() => layer.defaultIcon()?.SetClass("block h-6 w-6")}></ToSvelte> | 
					
						
							|  |  |  |         <ToSvelte slot="else" construct={() => layer.defaultIcon()?.SetClass("block h-6 w-6 opacity-50")}></ToSvelte> | 
					
						
							|  |  |  |       </If> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {filteredLayer.layerDef.name} | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       {#if $zoomlevel < layer.minzoom} | 
					
						
							|  |  |  |         <span class="alert"> | 
					
						
							|  |  |  |           <Tr t={Translations.t.general.layerSelection.zoomInToSeeThisLayer} /> | 
					
						
							|  |  |  |         </span> | 
					
						
							|  |  |  |       {/if} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |     </label> | 
					
						
							|  |  |  |     <If condition={filteredLayer.isDisplayed}> | 
					
						
							|  |  |  |       <div id="subfilters" class="flex flex-col gap-y-1 mb-4 ml-4"> | 
					
						
							|  |  |  |         {#each filteredLayer.layerDef.filters as filter} | 
					
						
							|  |  |  |           <div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             <!-- There are three (and a half) modes of filters: a single checkbox, a radio button/dropdown or with fields --> | 
					
						
							|  |  |  |             {#if filter.options.length === 1 && filter.options[0].fields.length === 0} | 
					
						
							|  |  |  |               <label> | 
					
						
							|  |  |  |                 <Checkbox selected={getBooleanStateFor(filter)} /> | 
					
						
							|  |  |  |                 {filter.options[0].question} | 
					
						
							|  |  |  |               </label> | 
					
						
							|  |  |  |             {/if} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |             {#if filter.options.length === 1 && filter.options[0].fields.length > 0} | 
					
						
							|  |  |  |               <FilterviewWithFields id={filter.id} filteredLayer={filteredLayer} | 
					
						
							|  |  |  |                                     option={filter.options[0]}></FilterviewWithFields> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             {/if} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |             {#if filter.options.length > 1} | 
					
						
							|  |  |  |               <Dropdown value={getStateFor(filter)}> | 
					
						
							|  |  |  |                 {#each filter.options as option, i} | 
					
						
							|  |  |  |                   <option value={i}> | 
					
						
							|  |  |  |                     { option.question} | 
					
						
							|  |  |  |                   </option> | 
					
						
							|  |  |  |                 {/each} | 
					
						
							|  |  |  |               </Dropdown> | 
					
						
							|  |  |  |             {/if} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         {/each} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </If> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | {/if} |