| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |   import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  |   import type { SpecialVisualizationState } from "../SpecialVisualization" | 
					
						
							|  |  |  |   import type { Feature } from "geojson" | 
					
						
							|  |  |  |   import Loading from "../Base/Loading.svelte" | 
					
						
							|  |  |  |   import Qr from "../../Utils/Qr" | 
					
						
							|  |  |  |   import { GeoOperations } from "../../Logic/GeoOperations" | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |   import { Utils } from "../../Utils" | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  |   const smallSize = 100 | 
					
						
							|  |  |  |   const bigSize = 200 | 
					
						
							|  |  |  |   let size = new UIEventSource(smallSize) | 
					
						
							|  |  |  |   export let state: SpecialVisualizationState | 
					
						
							|  |  |  |   export let tags: UIEventSource<Record<string, string>> | 
					
						
							|  |  |  |   export let feature: Feature | 
					
						
							| 
									
										
										
										
											2025-05-29 23:26:59 +02:00
										 |  |  |   export let extraUrlParams: Record<string, string> = {} | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |   export let sideText: string = undefined | 
					
						
							|  |  |  |   export let sideTextClass: string = undefined | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |   const includeLayout = window.location.pathname.split("/").at(-1).startsWith("theme") | 
					
						
							|  |  |  |   let id: Store<string> = tags.mapD((tags) => tags.id) | 
					
						
							| 
									
										
										
										
											2025-05-29 23:26:59 +02:00
										 |  |  |   extraUrlParams["z"] ??= 15 | 
					
						
							|  |  |  |   if (includeLayout) { | 
					
						
							|  |  |  |     extraUrlParams["layout"] ??= state.theme.id | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (feature) { | 
					
						
							|  |  |  |     const [lon, lat] = GeoOperations.centerpointCoordinates(feature) | 
					
						
							|  |  |  |     extraUrlParams["lon"] ??= "" + lon | 
					
						
							|  |  |  |     extraUrlParams["lat"] ??= "" + lat | 
					
						
							|  |  |  |   } else if (state?.mapProperties?.location?.data) { | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |     const l: { lon: number; lat: number } = state?.mapProperties?.location?.data | 
					
						
							|  |  |  |     if (l.lon !== 0 && l.lat !== 0) { | 
					
						
							|  |  |  |       extraUrlParams["lon"] ??= "" + l.lon | 
					
						
							|  |  |  |       extraUrlParams["lat"] ??= "" + l.lat | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-29 23:26:59 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const params = [] | 
					
						
							|  |  |  |   for (const key in extraUrlParams) { | 
					
						
							|  |  |  |     console.log(key, "-->", extraUrlParams[key]) | 
					
						
							|  |  |  |     params.push(key + "=" + encodeURIComponent(extraUrlParams[key])) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   let url = id.map((id) => { | 
					
						
							|  |  |  |     if (id) { | 
					
						
							|  |  |  |       return "#" + id | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return "" | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }).map( | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |     (id) => | 
					
						
							| 
									
										
										
										
											2025-05-29 23:26:59 +02:00
										 |  |  |       `${window.location.protocol}//${window.location.host}${window.location.pathname}?${params.join("&")}${id}` | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |   ) | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function toggleSize() { | 
					
						
							|  |  |  |     if (size.data !== bigSize) { | 
					
						
							|  |  |  |       size.setData(bigSize) | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       size.setData(smallSize) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-05-29 23:26:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |   let sideTextSub = (tags ?? new ImmutableStore({})).map(tgs => Utils.SubstituteKeys(sideText, tgs)) | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-29 23:26:59 +02:00
										 |  |  | {#if $id?.startsWith("node/-")} | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  |   <!-- Not yet uploaded, doesn't have a fixed ID --> | 
					
						
							|  |  |  |   <Loading /> | 
					
						
							|  |  |  | {:else} | 
					
						
							| 
									
										
										
										
											2025-05-30 15:10:48 +02:00
										 |  |  |   <div class="flex flex-col my-4"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <div class="flex w-full items-center  "> | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |     <img | 
					
						
							|  |  |  |       class="shrink-0" | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |     on:click={() => toggleSize()} | 
					
						
							|  |  |  |     src={new Qr($url).toImageElement($size)} | 
					
						
							|  |  |  |     style={`width: ${$size}px; height: ${$size}px`} | 
					
						
							|  |  |  |   /> | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |     {#if sideText} | 
					
						
							|  |  |  |       <div class={sideTextClass}>{ $sideTextSub}</div> | 
					
						
							|  |  |  |     {/if} | 
					
						
							| 
									
										
										
										
											2025-05-30 15:10:48 +02:00
										 |  |  |     </div> | 
					
						
							|  |  |  |     <a href={$url} target="_blank" class="subtle text-sm  ">{$url}</a> | 
					
						
							| 
									
										
										
										
											2025-05-30 00:19:02 +02:00
										 |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2024-08-09 14:40:07 +02:00
										 |  |  | {/if} |