MapComplete/src/UI/Image/NearbyImages.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.8 KiB
Svelte
Raw Normal View History

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"
import type { Feature } from "geojson"
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-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-12-19 22:08:00 +01:00
export let linkable: boolean = true
export let layer: LayerConfig
2024-07-19 11:37:20 +02:00
let imagesProvider = state.nearbyImageSearcher
let loadedImages = AllImageProviders.LoadImagesFor(tags).mapD(loaded => new Set(loaded.map(img => img.url)))
let imageState = imagesProvider.getImagesAround(lon, lat)
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])
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"))
</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}
<div class="flex justify-center m-4">
<Loading />
</div>
{:else }
<Tr t={Translations.t.image.nearby.noNearbyImages} cls="alert" />
{/if}
{:else}
<div class="flex w-full space-x-1 overflow-x-auto" style="scroll-snap-type: x proximity">
{#each $result as image (image.pictureUrl)}
2024-06-20 04:21:29 +02:00
<span class="w-fit shrink-0" style="scroll-snap-align: start">
<LinkableImage {tags} {image} {state} {feature} {layer} {linkable} />
</span>
2024-07-19 11:37:20 +02:00
{/each}
</div>
{/if}
<div class="flex justify-between my-2">
<div>
{#if $someLoading && $result.length > 0}
<Loading />
{/if}
{#if $errors.length > 0}
<Tr cls="alert font-sm block" t={Translations.t.image.nearby.failed.Subs({service: $errors.join(", ")}) } />
{/if}
</div>
<MapillaryLink large={false}
mapProperties={{zoom: new ImmutableStore(16), location: new ImmutableStore({lon, lat})}} />
2024-06-18 03:33:11 +02:00
</div>
2024-07-19 11:37:20 +02:00
</div>