2023-09-16 02:30:01 +02:00
|
|
|
<script lang="ts">
|
2023-09-21 15:29:34 +02:00
|
|
|
import { Store } from "../../Logic/UIEventSource"
|
|
|
|
import type { OsmTags } from "../../Models/OsmFeature"
|
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import type { P4CPicture } from "../../Logic/Web/NearbyImagesSearch"
|
|
|
|
import ToSvelte from "../Base/ToSvelte.svelte"
|
|
|
|
import { AttributedImage } from "../Image/AttributedImage"
|
|
|
|
import AllImageProviders from "../../Logic/ImageProviders/AllImageProviders"
|
2023-09-25 02:11:42 +02:00
|
|
|
import LinkImageAction from "../../Logic/Osm/Actions/LinkImageAction"
|
2023-09-21 15:29:34 +02:00
|
|
|
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"
|
|
|
|
import { Tag } from "../../Logic/Tags/Tag"
|
|
|
|
import { GeoOperations } from "../../Logic/GeoOperations"
|
|
|
|
import type { Feature } from "geojson"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import SpecialTranslation from "./TagRendering/SpecialTranslation.svelte"
|
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
2023-09-16 02:30:01 +02:00
|
|
|
|
2023-09-21 15:29:34 +02:00
|
|
|
export let tags: Store<OsmTags>
|
|
|
|
export let lon: number
|
|
|
|
export let lat: number
|
|
|
|
export let state: SpecialVisualizationState
|
|
|
|
export let image: P4CPicture
|
|
|
|
export let feature: Feature
|
|
|
|
export let layer: LayerConfig
|
2023-09-16 02:30:01 +02:00
|
|
|
|
2023-09-28 23:50:27 +02:00
|
|
|
export let linkable = true
|
|
|
|
let isLinked = Object.values(tags.data).some((v) => image.pictureUrl === v)
|
2023-09-16 02:30:01 +02:00
|
|
|
|
2023-09-28 23:50:27 +02:00
|
|
|
const t = Translations.t.image.nearby
|
|
|
|
const c = [lon, lat]
|
2023-12-02 03:12:34 +01:00
|
|
|
console.log(">>>", image)
|
2023-09-16 02:30:01 +02:00
|
|
|
let attributedImage = new AttributedImage({
|
|
|
|
url: image.thumbUrl ?? image.pictureUrl,
|
|
|
|
provider: AllImageProviders.byName(image.provider),
|
2023-09-28 23:50:27 +02:00
|
|
|
date: new Date(image.date),
|
2023-12-02 03:12:34 +01:00
|
|
|
id: Object.values(image.osmTags)[0]
|
|
|
|
}, feature)
|
2023-09-28 23:50:27 +02:00
|
|
|
let distance = Math.round(
|
|
|
|
GeoOperations.distanceBetween([image.coordinates.lng, image.coordinates.lat], c)
|
|
|
|
)
|
|
|
|
|
2023-09-16 02:30:01 +02:00
|
|
|
$: {
|
2023-09-21 15:29:34 +02:00
|
|
|
const currentTags = tags.data
|
|
|
|
const key = Object.keys(image.osmTags)[0]
|
|
|
|
const url = image.osmTags[key]
|
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, {
|
2023-09-21 15:29:34 +02:00
|
|
|
theme: state.layout.id,
|
|
|
|
changeType: "link-image",
|
|
|
|
})
|
|
|
|
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, {
|
|
|
|
theme: state.layout.id,
|
|
|
|
changeType: "remove-image",
|
|
|
|
})
|
|
|
|
state.changes.applyAction(action)
|
2023-09-16 02:30:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2023-09-21 15:29:34 +02:00
|
|
|
|
|
|
|
<div class="flex w-fit shrink-0 flex-col">
|
2023-09-16 02:30:01 +02:00
|
|
|
<ToSvelte construct={attributedImage.SetClass("h-48 w-fit")} />
|
|
|
|
{#if linkable}
|
|
|
|
<label>
|
2023-09-21 15:29:34 +02:00
|
|
|
<input bind:checked={isLinked} type="checkbox" />
|
2023-09-16 02:30:01 +02:00
|
|
|
<SpecialTranslation t={t.link} {tags} {state} {layer} {feature} />
|
|
|
|
</label>
|
|
|
|
{/if}
|
|
|
|
</div>
|