MapComplete/src/UI/Popup/LinkableImage.svelte

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

74 lines
2.6 KiB
Svelte
Raw Normal View History

<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"
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-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-28 23:50:27 +02:00
export let linkable = true
let isLinked = Object.values(tags.data).some((v) => image.pictureUrl === v)
2023-09-28 23:50:27 +02:00
const t = Translations.t.image.nearby
const c = [lon, lat]
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),
})
let distance = Math.round(
GeoOperations.distanceBetween([image.coordinates.lng, image.coordinates.lat], c)
)
$: {
2023-09-21 15:29:34 +02:00
const currentTags = tags.data
const key = Object.keys(image.osmTags)[0]
const url = image.osmTags[key]
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)
} else {
for (const k in currentTags) {
2023-09-21 15:29:34 +02:00
const v = currentTags[k]
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)
}
}
}
}
</script>
2023-09-21 15:29:34 +02:00
<div class="flex w-fit shrink-0 flex-col">
<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" />
<SpecialTranslation t={t.link} {tags} {state} {layer} {feature} />
</label>
{/if}
</div>