2024-01-13 05:24:56 +01:00
|
|
|
<script lang="ts">
|
2024-02-20 13:33:38 +01:00
|
|
|
import LinkableImage from "../Image/LinkableImage.svelte"
|
|
|
|
import { UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
import type { OsmTags } from "../../Models/OsmFeature"
|
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import type { Feature } from "geojson"
|
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
|
|
import ComparisonAction from "./ComparisonAction.svelte"
|
|
|
|
import Party from "../../assets/svg/Party.svelte"
|
|
|
|
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"
|
|
|
|
import { Tag } from "../../Logic/Tags/Tag"
|
|
|
|
import { And } from "../../Logic/Tags/And"
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import AttributedImage from "../Image/AttributedImage.svelte"
|
|
|
|
|
|
|
|
export let osmProperties: Record<string, string>
|
|
|
|
export let externalProperties: Record<string, string>
|
|
|
|
|
|
|
|
export let tags: UIEventSource<OsmTags>
|
|
|
|
export let state: SpecialVisualizationState
|
|
|
|
export let feature: Feature
|
|
|
|
export let layer: LayerConfig
|
|
|
|
|
|
|
|
export let readonly = false
|
|
|
|
|
|
|
|
let externalKeys: string[] = Object.keys(externalProperties).sort()
|
|
|
|
|
|
|
|
const imageKeyRegex = /image|image:[0-9]+/
|
|
|
|
let knownImages = new Set(
|
|
|
|
Object.keys(osmProperties)
|
|
|
|
.filter((k) => k.match(imageKeyRegex))
|
|
|
|
.map((k) => osmProperties[k])
|
|
|
|
)
|
|
|
|
let unknownImages = externalKeys
|
|
|
|
.filter((k) => k.match(imageKeyRegex))
|
|
|
|
.map((k) => externalProperties[k])
|
|
|
|
.filter((i) => !knownImages.has(i))
|
|
|
|
|
|
|
|
let propertyKeysExternal = externalKeys.filter((k) => k.match(imageKeyRegex) === null)
|
2024-02-26 02:24:46 +01:00
|
|
|
let missing = propertyKeysExternal.filter((k) => osmProperties[k] === undefined && typeof externalProperties[k] === "string")
|
2024-02-20 13:33:38 +01:00
|
|
|
let same = propertyKeysExternal.filter((key) => osmProperties[key] === externalProperties[key])
|
|
|
|
let different = propertyKeysExternal.filter(
|
2024-02-26 02:24:46 +01:00
|
|
|
(key) => osmProperties[key] !== undefined && osmProperties[key] !== externalProperties[key] && typeof externalProperties[key] === "string"
|
2024-02-20 13:33:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
let currentStep: "init" | "applying_all" | "all_applied" = "init"
|
|
|
|
|
|
|
|
async function applyAllMissing() {
|
|
|
|
currentStep = "applying_all"
|
|
|
|
const tagsToApply = missing.map((k) => new Tag(k, externalProperties[k]))
|
|
|
|
const change = new ChangeTagAction(tags.data.id, new And(tagsToApply), tags.data, {
|
|
|
|
theme: state.layout.id,
|
|
|
|
changeType: "import",
|
|
|
|
})
|
|
|
|
await state.changes.applyChanges(await change.CreateChangeDescriptions())
|
|
|
|
currentStep = "all_applied"
|
|
|
|
}
|
2024-01-13 05:24:56 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if different.length > 0}
|
|
|
|
<h3>Conflicting items</h3>
|
2024-01-16 04:21:11 +01:00
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Key</th>
|
|
|
|
<th>OSM</th>
|
|
|
|
<th>External</th>
|
|
|
|
</tr>
|
|
|
|
{#each different as key}
|
2024-02-26 02:24:46 +01:00
|
|
|
<ComparisonAction {key} {state} {tags} {externalProperties} {layer} {feature} {readonly} />
|
2024-01-16 04:21:11 +01:00
|
|
|
{/each}
|
|
|
|
</table>
|
2024-01-13 05:24:56 +01:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if missing.length > 0}
|
|
|
|
{#if currentStep === "init"}
|
|
|
|
<table class="w-full">
|
|
|
|
<tr>
|
|
|
|
<th>Key</th>
|
|
|
|
<th>External</th>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
{#each missing as key}
|
2024-01-16 04:21:11 +01:00
|
|
|
<ComparisonAction {key} {state} {tags} {externalProperties} {layer} {feature} {readonly} />
|
2024-01-13 05:24:56 +01:00
|
|
|
{/each}
|
|
|
|
</table>
|
2024-01-16 04:21:11 +01:00
|
|
|
{#if !readonly}
|
|
|
|
<button on:click={() => applyAllMissing()}>Apply all missing values</button>
|
|
|
|
{/if}
|
2024-01-13 05:24:56 +01:00
|
|
|
{:else if currentStep === "applying_all"}
|
|
|
|
<Loading>Applying all missing values</Loading>
|
|
|
|
{:else if currentStep === "all_applied"}
|
2024-02-20 13:33:38 +01:00
|
|
|
<div class="thanks">All values are applied</div>
|
2024-01-13 05:24:56 +01:00
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if unknownImages.length === 0 && missing.length === 0 && different.length === 0}
|
2024-02-20 13:33:38 +01:00
|
|
|
<div class="thanks m-0 flex items-center gap-x-2 px-2">
|
|
|
|
<Party class="h-8 w-8" />
|
2024-01-13 05:24:56 +01:00
|
|
|
All data from Velopark is also included into OpenStreetMap
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if unknownImages.length > 0}
|
2024-01-16 04:21:11 +01:00
|
|
|
{#if readonly}
|
|
|
|
<div class="w-full overflow-x-auto">
|
2024-02-20 13:33:38 +01:00
|
|
|
<div class="flex h-32 w-max gap-x-2">
|
2024-01-16 04:21:11 +01:00
|
|
|
{#each unknownImages as image}
|
2024-02-20 13:33:38 +01:00
|
|
|
<AttributedImage
|
|
|
|
imgClass="h-32 w-max shrink-0"
|
|
|
|
image={{ url: image }}
|
|
|
|
previewedImage={state.previewedImage}
|
|
|
|
/>
|
2024-01-16 04:21:11 +01:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
{#each unknownImages as image}
|
|
|
|
<LinkableImage
|
|
|
|
{tags}
|
|
|
|
{state}
|
|
|
|
image={{
|
2024-02-20 13:33:38 +01:00
|
|
|
pictureUrl: image,
|
|
|
|
provider: "Velopark",
|
|
|
|
thumbUrl: image,
|
|
|
|
details: undefined,
|
|
|
|
coordinates: undefined,
|
|
|
|
osmTags: { image },
|
|
|
|
}}
|
2024-01-16 04:21:11 +01:00
|
|
|
{feature}
|
2024-02-20 13:33:38 +01:00
|
|
|
{layer}
|
|
|
|
/>
|
2024-01-16 04:21:11 +01:00
|
|
|
{/each}
|
|
|
|
{/if}
|
2024-01-13 05:24:56 +01:00
|
|
|
{/if}
|