| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-12-15 01:46:01 +01:00
										 |  |  |   import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import type { OsmTags } from "../../Models/OsmFeature" | 
					
						
							|  |  |  |   import type { SpecialVisualizationState } from "../SpecialVisualization" | 
					
						
							|  |  |  |   import type { P4CPicture } from "../../Logic/Web/NearbyImagesSearch" | 
					
						
							|  |  |  |   import AllImageProviders from "../../Logic/ImageProviders/AllImageProviders" | 
					
						
							|  |  |  |   import LinkImageAction from "../../Logic/Osm/Actions/LinkImageAction" | 
					
						
							|  |  |  |   import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction" | 
					
						
							|  |  |  |   import { Tag } from "../../Logic/Tags/Tag" | 
					
						
							|  |  |  |   import type { Feature } from "geojson" | 
					
						
							|  |  |  |   import Translations from "../i18n/Translations" | 
					
						
							|  |  |  |   import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | 
					
						
							|  |  |  |   import type { ProvidedImage } from "../../Logic/ImageProviders/ImageProvider" | 
					
						
							|  |  |  |   import AttributedImage from "./AttributedImage.svelte" | 
					
						
							|  |  |  |   import SpecialTranslation from "../Popup/TagRendering/SpecialTranslation.svelte" | 
					
						
							| 
									
										
										
										
											2024-06-14 01:00:59 +02:00
										 |  |  |   import LoginToggle from "../Base/LoginToggle.svelte" | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   import { onDestroy } from "svelte" | 
					
						
							|  |  |  |   import { Utils } from "../../Utils" | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-15 01:46:01 +01:00
										 |  |  |   export let tags: UIEventSource<OsmTags> | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  |   export let state: SpecialVisualizationState | 
					
						
							|  |  |  |   export let image: P4CPicture | 
					
						
							|  |  |  |   export let feature: Feature | 
					
						
							|  |  |  |   export let layer: LayerConfig | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   export let highlighted: UIEventSource<string> = undefined | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  |   export let linkable = true | 
					
						
							| 
									
										
										
										
											2024-01-16 23:55:18 +01:00
										 |  |  |   let targetValue = Object.values(image.osmTags)[0] | 
					
						
							|  |  |  |   let isLinked = new UIEventSource(Object.values(tags.data).some((v) => targetValue === v)) | 
					
						
							| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  |   const t = Translations.t.image.nearby | 
					
						
							| 
									
										
										
										
											2023-12-05 18:35:18 +01:00
										 |  |  |   const providedImage: ProvidedImage = { | 
					
						
							| 
									
										
										
										
											2023-12-15 01:46:01 +01:00
										 |  |  |     url: image.thumbUrl ?? image.pictureUrl, | 
					
						
							| 
									
										
										
										
											2023-12-26 12:26:26 +01:00
										 |  |  |     url_hd: image.pictureUrl, | 
					
						
							| 
									
										
										
										
											2023-12-19 23:02:02 +01:00
										 |  |  |     key: undefined, | 
					
						
							| 
									
										
										
										
											2023-12-15 01:46:01 +01:00
										 |  |  |     provider: AllImageProviders.byName(image.provider), | 
					
						
							|  |  |  |     date: new Date(image.date), | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |     id: Object.values(image.osmTags)[0] | 
					
						
							| 
									
										
										
										
											2023-12-05 18:35:18 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 11:36:34 +02:00
										 |  |  |   async function applyLink(isLinked: boolean) { | 
					
						
							| 
									
										
										
										
											2024-01-16 23:55:18 +01:00
										 |  |  |     console.log("Applying linked image", isLinked, targetValue) | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  |     const currentTags = tags.data | 
					
						
							|  |  |  |     const key = Object.keys(image.osmTags)[0] | 
					
						
							| 
									
										
										
										
											2024-01-16 23:55:18 +01:00
										 |  |  |     const url = targetValue | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  |     if (isLinked) { | 
					
						
							| 
									
										
										
										
											2023-11-23 16:00:14 +01:00
										 |  |  |       const action = new LinkImageAction(currentTags.id, key, url, tags, { | 
					
						
							| 
									
										
										
										
											2024-10-17 04:06:03 +02:00
										 |  |  |         theme: tags.data._orig_theme ?? state.theme.id, | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |         changeType: "link-image" | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2024-07-19 11:36:34 +02:00
										 |  |  |       await state.changes.applyAction(action) | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |       for (const k in currentTags) { | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  |         const v = currentTags[k] | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  |         if (v === url) { | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  |           const action = new ChangeTagAction(currentTags.id, new Tag(k, ""), currentTags, { | 
					
						
							| 
									
										
										
										
											2024-10-17 04:06:03 +02:00
										 |  |  |             theme: tags.data._orig_theme ?? state.theme.id, | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |             changeType: "remove-image" | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  |           }) | 
					
						
							|  |  |  |           state.changes.applyAction(action) | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-08-28 15:07:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-20 13:33:38 +01:00
										 |  |  |   isLinked.addCallback((isLinked) => applyLink(isLinked)) | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let element: HTMLDivElement | 
					
						
							|  |  |  |   if (highlighted) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onDestroy( | 
					
						
							|  |  |  |       highlighted.addCallbackD(highlightedUrl => { | 
					
						
							|  |  |  |         if (highlightedUrl === image.pictureUrl) { | 
					
						
							|  |  |  |           Utils.scrollIntoView(element) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | </script> | 
					
						
							| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-02 12:48:15 +02:00
										 |  |  | <div | 
					
						
							|  |  |  |   class="flex w-fit shrink-0 flex-col overflow-hidden rounded-lg" | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   class:border-interactive={$isLinked || $highlighted === image.pictureUrl} | 
					
						
							| 
									
										
										
										
											2024-09-02 12:48:15 +02:00
										 |  |  |   style="border-width: 2px" | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   bind:this={element} | 
					
						
							| 
									
										
										
										
											2024-09-02 12:48:15 +02:00
										 |  |  | > | 
					
						
							| 
									
										
										
										
											2024-08-28 15:07:18 +02:00
										 |  |  |   <AttributedImage | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |     {state} | 
					
						
							| 
									
										
										
										
											2024-08-28 15:07:18 +02:00
										 |  |  |     image={providedImage} | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |     imgClass="max-h-64 w-auto sm:h-32 md:h-64" | 
					
						
							| 
									
										
										
										
											2024-08-28 15:07:18 +02:00
										 |  |  |     previewedImage={state.previewedImage} | 
					
						
							|  |  |  |     attributionFormat="minimal" | 
					
						
							| 
									
										
										
										
											2024-09-04 01:50:34 +02:00
										 |  |  |   > | 
					
						
							|  |  |  |     <!--
 | 
					
						
							|  |  |  |     <div slot="preview-action" class="self-center" > | 
					
						
							|  |  |  |     <LoginToggle {state} silentFail={true}> | 
					
						
							|  |  |  |       {#if linkable} | 
					
						
							|  |  |  |         <label class="normal-background p-2 rounded-full pointer-events-auto"> | 
					
						
							|  |  |  |           <input bind:checked={$isLinked} type="checkbox" /> | 
					
						
							|  |  |  |           <SpecialTranslation t={t.link} {tags} {state} {layer} {feature} /> | 
					
						
							|  |  |  |         </label> | 
					
						
							|  |  |  |       {/if} | 
					
						
							|  |  |  |     </LoginToggle> | 
					
						
							|  |  |  |     </div>--> | 
					
						
							|  |  |  |   </AttributedImage> | 
					
						
							| 
									
										
										
										
											2024-06-16 16:06:26 +02:00
										 |  |  |   <LoginToggle {state} silentFail={true}> | 
					
						
							|  |  |  |     {#if linkable} | 
					
						
							|  |  |  |       <label> | 
					
						
							|  |  |  |         <input bind:checked={$isLinked} type="checkbox" /> | 
					
						
							|  |  |  |         <SpecialTranslation t={t.link} {tags} {state} {layer} {feature} /> | 
					
						
							|  |  |  |       </label> | 
					
						
							|  |  |  |     {/if} | 
					
						
							| 
									
										
										
										
											2024-06-14 01:00:59 +02:00
										 |  |  |   </LoginToggle> | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | </div> |