| 
									
										
										
										
											2023-03-11 02:37:07 +01:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   import type { RasterLayerPolygon } from "../../Models/RasterLayers" | 
					
						
							|  |  |  |   import OverlayMap from "./OverlayMap.svelte" | 
					
						
							|  |  |  |   import type { MapProperties } from "../../Models/MapProperties" | 
					
						
							|  |  |  |   import { Store, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import { Map as MlMap } from "maplibre-gl" | 
					
						
							|  |  |  |   import { createEventDispatcher, onDestroy } from "svelte" | 
					
						
							| 
									
										
										
										
											2023-03-11 02:37:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   /*** | 
					
						
							|  |  |  |    * Chooses a background-layer out of available options | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   export let availableLayers: Store<RasterLayerPolygon[]> | 
					
						
							|  |  |  |   export let mapproperties: MapProperties | 
					
						
							|  |  |  |   export let map: Store<MlMap> | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   export let visible: Store<boolean> = undefined | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   let dispatch = createEventDispatcher<{ appliedLayer }>() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   export let favourite: UIEventSource<string> | undefined = undefined | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let rasterLayer = new UIEventSource<RasterLayerPolygon>(availableLayers.data?.[0]) | 
					
						
							|  |  |  |   let hasLayers = true | 
					
						
							|  |  |  |   onDestroy( | 
					
						
							|  |  |  |     availableLayers.addCallbackAndRun((layers) => { | 
					
						
							|  |  |  |       if (layers === undefined || layers.length === 0) { | 
					
						
							|  |  |  |         hasLayers = false | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       hasLayers = true | 
					
						
							|  |  |  |       rasterLayer.setData(layers[0]) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (favourite) { | 
					
						
							|  |  |  |     onDestroy( | 
					
						
							|  |  |  |       favourite.addCallbackAndRunD((favourite) => { | 
					
						
							|  |  |  |         const fav = availableLayers.data?.find((l) => l.properties.id === favourite) | 
					
						
							|  |  |  |         if (!fav) { | 
					
						
							|  |  |  |           return | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         rasterLayer.setData(fav) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     onDestroy( | 
					
						
							|  |  |  |       rasterLayer.addCallbackAndRunD((selected) => { | 
					
						
							|  |  |  |         favourite?.setData(selected.properties.id) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let rasterLayerOnMap = UIEventSource.feedFrom(rasterLayer) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (visible) { | 
					
						
							|  |  |  |     onDestroy( | 
					
						
							|  |  |  |       visible?.addCallbackAndRunD((visible) => { | 
					
						
							|  |  |  |         if (visible) { | 
					
						
							|  |  |  |           rasterLayerOnMap.setData(rasterLayer.data ?? availableLayers.data[0]) | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           rasterLayerOnMap.setData(undefined) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-03-11 02:37:07 +01:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | {#if hasLayers} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:44:01 +02:00
										 |  |  |   <div class="flex h-full w-full flex-col"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     <button | 
					
						
							|  |  |  |       on:click={() => { | 
					
						
							|  |  |  |         mapproperties.rasterLayer.setData(rasterLayer.data) | 
					
						
							|  |  |  |         dispatch("appliedLayer") | 
					
						
							|  |  |  |       }} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:44:01 +02:00
										 |  |  |       class="m-0 h-full w-full p-0" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     > | 
					
						
							|  |  |  |       <OverlayMap | 
					
						
							|  |  |  |         rasterLayer={rasterLayerOnMap} | 
					
						
							|  |  |  |         placedOverMap={map} | 
					
						
							|  |  |  |         placedOverMapProperties={mapproperties} | 
					
						
							|  |  |  |         {visible} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </button> | 
					
						
							|  |  |  |     <select bind:value={$rasterLayer} class="w-full"> | 
					
						
							|  |  |  |       {#each $availableLayers as availableLayer} | 
					
						
							|  |  |  |         <option value={availableLayer}> | 
					
						
							|  |  |  |           {availableLayer.properties.name} | 
					
						
							|  |  |  |         </option> | 
					
						
							|  |  |  |       {/each} | 
					
						
							|  |  |  |     </select> | 
					
						
							|  |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | {/if} |