| 
									
										
										
										
											2023-09-21 15:29:34 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Show nearby images which can be clicked | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   import type { OsmTags } from "../../Models/OsmFeature" | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |   import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |   import type { SpecialVisualizationState } from "../SpecialVisualization" | 
					
						
							|  |  |  |   import type { P4CPicture } from "../../Logic/Web/NearbyImagesSearch" | 
					
						
							|  |  |  |   import LinkableImage from "./LinkableImage.svelte" | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   import type { Feature, Point } from "geojson" | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |   import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | 
					
						
							|  |  |  |   import Loading from "../Base/Loading.svelte" | 
					
						
							|  |  |  |   import AllImageProviders from "../../Logic/ImageProviders/AllImageProviders" | 
					
						
							|  |  |  |   import Tr from "../Base/Tr.svelte" | 
					
						
							|  |  |  |   import Translations from "../i18n/Translations" | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |   import MapillaryLink from "../BigComponents/MapillaryLink.svelte" | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   import MaplibreMap from "../Map/MaplibreMap.svelte" | 
					
						
							|  |  |  |   import { Map as MlMap } from "maplibre-gl" | 
					
						
							|  |  |  |   import { MapLibreAdaptor } from "../Map/MapLibreAdaptor" | 
					
						
							|  |  |  |   import ShowDataLayer from "../Map/ShowDataLayer" | 
					
						
							|  |  |  |   import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource" | 
					
						
							|  |  |  |   import * as geocoded_image from "../../assets/generated/layers/geocoded_image.json" | 
					
						
							|  |  |  |   import type { LayerConfigJson } from "../../Models/ThemeConfig/Json/LayerConfigJson" | 
					
						
							|  |  |  |   import { onDestroy } from "svelte" | 
					
						
							|  |  |  |   import { BBox } from "../../Logic/BBox" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-11 15:22:45 +01:00
										 |  |  |   export let tags: UIEventSource<OsmTags> | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |   export let state: SpecialVisualizationState | 
					
						
							|  |  |  |   export let lon: number | 
					
						
							|  |  |  |   export let lat: number | 
					
						
							|  |  |  |   export let feature: Feature | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |   export let linkable: boolean = true | 
					
						
							|  |  |  |   export let layer: LayerConfig | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |   let imagesProvider = state.nearbyImageSearcher | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |   let loadedImages = AllImageProviders.LoadImagesFor(tags).mapD( | 
					
						
							|  |  |  |     (loaded) => new Set(loaded.map((img) => img.url)) | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |   let imageState = imagesProvider.getImagesAround(lon, lat) | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |   let result: Store<P4CPicture[]> = imageState.images.mapD( | 
					
						
							|  |  |  |     (pics: P4CPicture[]) => | 
					
						
							|  |  |  |       pics | 
					
						
							|  |  |  |         .filter( | 
					
						
							|  |  |  |           (p: P4CPicture) => | 
					
						
							|  |  |  |             !loadedImages.data.has(p.pictureUrl) && // We don't show any image which is already linked | 
					
						
							|  |  |  |             !p.details.isSpherical | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         .slice(0, 25), | 
					
						
							|  |  |  |     [loadedImages] | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   let asFeatures = result.map(p4cs => p4cs.map(p4c => (<Feature<Point>>{ | 
					
						
							|  |  |  |     type: "Feature", | 
					
						
							|  |  |  |     geometry: { | 
					
						
							|  |  |  |       type: "Point", | 
					
						
							|  |  |  |       coordinates: [p4c.coordinates.lng, p4c.coordinates.lat] | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     properties: { | 
					
						
							|  |  |  |       id: p4c.pictureUrl, | 
					
						
							|  |  |  |       rotation: p4c.direction | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let selected = new UIEventSource<P4CPicture>(undefined) | 
					
						
							|  |  |  |   let selectedAsFeature = selected.mapD(s => { | 
					
						
							|  |  |  |     return [<Feature<Point>>{ | 
					
						
							|  |  |  |       type: "Feature", | 
					
						
							|  |  |  |       geometry: { | 
					
						
							|  |  |  |         type: "Point", | 
					
						
							|  |  |  |         coordinates: [s.coordinates.lng, s.coordinates.lat] | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       properties: { | 
					
						
							|  |  |  |         id: s.pictureUrl, | 
					
						
							|  |  |  |         selected: "yes", | 
					
						
							|  |  |  |         rotation: s.direction | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |   let someLoading = imageState.state.mapD((stateRecord) => | 
					
						
							|  |  |  |     Object.values(stateRecord).some((v) => v === "loading") | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  |   let errors = imageState.state.mapD((stateRecord) => | 
					
						
							|  |  |  |     Object.keys(stateRecord).filter((k) => stateRecord[k] === "error") | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   let highlighted = new UIEventSource<string>(undefined) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onDestroy(highlighted.addCallbackD(hl => { | 
					
						
							|  |  |  |       const p4c = result.data?.find(i => i.pictureUrl === hl) | 
					
						
							|  |  |  |       selected.set(p4c) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   )) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let map: UIEventSource<MlMap> = new UIEventSource<MlMap>(undefined) | 
					
						
							|  |  |  |   let mapProperties = new MapLibreAdaptor(map, { | 
					
						
							|  |  |  |     rasterLayer: state.mapProperties.rasterLayer, | 
					
						
							|  |  |  |     rotation: state.mapProperties.rotation, | 
					
						
							|  |  |  |     pitch: state.mapProperties.pitch, | 
					
						
							|  |  |  |     zoom: new UIEventSource<number>(16), | 
					
						
							|  |  |  |     location: new UIEventSource({ lon, lat }), | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const geocodedImageLayer = new LayerConfig(<LayerConfigJson>geocoded_image) | 
					
						
							|  |  |  |   new ShowDataLayer(map, { | 
					
						
							|  |  |  |     features: new StaticFeatureSource(asFeatures), | 
					
						
							|  |  |  |     layer: geocodedImageLayer, | 
					
						
							|  |  |  |     zoomToFeatures: true, | 
					
						
							|  |  |  |     onClick: (feature) => { | 
					
						
							|  |  |  |       highlighted.set(feature.properties.id) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ShowDataLayer.showMultipleLayers( | 
					
						
							|  |  |  |     map, | 
					
						
							|  |  |  |     new StaticFeatureSource([feature]), | 
					
						
							|  |  |  |     state.layout.layers | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onDestroy( | 
					
						
							|  |  |  |   asFeatures.addCallbackAndRunD(features => { | 
					
						
							|  |  |  |     if(features.length == 0){ | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     let bbox = BBox.get(features[0]) | 
					
						
							|  |  |  |     for (const f of features) { | 
					
						
							|  |  |  |       bbox = bbox.unionWith(BBox.get(f)) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     mapProperties.maxbounds.set(bbox.pad(1.1)) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   new ShowDataLayer(map, { | 
					
						
							|  |  |  |     features: new StaticFeatureSource(selectedAsFeature), | 
					
						
							|  |  |  |     layer: geocodedImageLayer, | 
					
						
							|  |  |  |     onClick: (feature) => { | 
					
						
							|  |  |  |       highlighted.set(feature.properties.id) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 02:30:01 +02:00
										 |  |  | </script> | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  | <div class="flex flex-col"> | 
					
						
							|  |  |  |   {#if $result.length === 0} | 
					
						
							|  |  |  |     {#if $someLoading} | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |       <div class="m-4 flex justify-center"> | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |         <Loading /> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |     {:else} | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |       <Tr t={Translations.t.image.nearby.noNearbyImages} cls="alert" /> | 
					
						
							|  |  |  |     {/if} | 
					
						
							|  |  |  |   {:else} | 
					
						
							| 
									
										
										
										
											2024-08-28 15:07:18 +02:00
										 |  |  |     <div class="flex w-full space-x-4 overflow-x-auto" style="scroll-snap-type: x proximity"> | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |       {#each $result as image (image.pictureUrl)} | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |         <span class="w-fit shrink-0" style="scroll-snap-align: start" | 
					
						
							|  |  |  |               on:mouseenter={() => {highlighted.set(image.pictureUrl)}} | 
					
						
							|  |  |  |               on:mouseleave={() =>{ highlighted.set(undefined); selected.set(undefined)}} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <LinkableImage {tags} {image} {state} {feature} {layer} {linkable} {highlighted} /> | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |         </span> | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |       {/each} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {/if} | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   <span class="self-end pt-2"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <MapillaryLink | 
					
						
							|  |  |  |     large={false} | 
					
						
							|  |  |  |     mapProperties={{ zoom: new ImmutableStore(16), location: new ImmutableStore({ lon, lat }) }} | 
					
						
							|  |  |  |   /> | 
					
						
							|  |  |  |   </span> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |   <div class="my-2 flex justify-between"> | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |     <div> | 
					
						
							|  |  |  |       {#if $someLoading && $result.length > 0} | 
					
						
							|  |  |  |         <Loading /> | 
					
						
							|  |  |  |       {/if} | 
					
						
							|  |  |  |       {#if $errors.length > 0} | 
					
						
							| 
									
										
										
										
											2024-07-21 10:52:51 +02:00
										 |  |  |         <Tr | 
					
						
							|  |  |  |           cls="alert font-sm block" | 
					
						
							|  |  |  |           t={Translations.t.image.nearby.failed.Subs({ service: $errors.join(", ") })} | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  |       {/if} | 
					
						
							|  |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2024-09-12 01:31:00 +02:00
										 |  |  |   </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <div class="h-48"> | 
					
						
							|  |  |  |     <MaplibreMap interactive={false} {map} {mapProperties} /> | 
					
						
							| 
									
										
										
										
											2024-06-18 03:33:11 +02:00
										 |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2024-07-19 11:37:20 +02:00
										 |  |  | </div> |