2024-02-20 13:33:38 +01:00
|
|
|
<script lang="ts">
|
|
|
|
/**
|
|
|
|
* The comparison tool loads json-data from a speficied URL, eventually post-processes it
|
|
|
|
* and compares it with the current object
|
|
|
|
*/
|
|
|
|
import { onMount } from "svelte"
|
|
|
|
import { Utils } from "../../Utils"
|
|
|
|
import VeloparkLoader from "../../Logic/Web/VeloparkLoader"
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import { UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
import ComparisonTable from "./ComparisonTable.svelte"
|
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
|
|
import type { Feature } from "geojson"
|
|
|
|
import type { OsmTags } from "../../Models/OsmFeature"
|
2024-01-13 05:24:56 +01:00
|
|
|
|
2024-02-20 13:33:38 +01:00
|
|
|
export let url: string
|
|
|
|
export let postprocessVelopark: boolean
|
|
|
|
export let state: SpecialVisualizationState
|
|
|
|
export let tags: UIEventSource<OsmTags>
|
|
|
|
export let layer: LayerConfig
|
|
|
|
export let feature: Feature
|
|
|
|
export let readonly = false
|
|
|
|
let data: any = undefined
|
|
|
|
let error: any = undefined
|
2024-01-13 05:24:56 +01:00
|
|
|
|
2024-02-20 13:33:38 +01:00
|
|
|
onMount(async () => {
|
2024-01-13 05:24:56 +01:00
|
|
|
const _url = tags.data[url]
|
|
|
|
if (!_url) {
|
2024-02-20 13:33:38 +01:00
|
|
|
error = "No URL found in attribute" + url
|
2024-01-13 05:24:56 +01:00
|
|
|
}
|
|
|
|
try {
|
2024-02-20 13:33:38 +01:00
|
|
|
console.log("Attempting to download", _url)
|
|
|
|
const downloaded = await Utils.downloadJsonAdvanced(_url)
|
|
|
|
if (downloaded["error"]) {
|
|
|
|
console.error(downloaded)
|
|
|
|
error = downloaded["error"]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (postprocessVelopark) {
|
|
|
|
data = VeloparkLoader.convert(downloaded["content"])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data = downloaded["content"]
|
2024-01-13 05:24:56 +01:00
|
|
|
} catch (e) {
|
2024-02-20 13:33:38 +01:00
|
|
|
console.error(e)
|
|
|
|
error = "" + e
|
2024-01-13 05:24:56 +01:00
|
|
|
}
|
2024-02-20 13:33:38 +01:00
|
|
|
})
|
2024-01-13 05:24:56 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if error !== undefined}
|
|
|
|
<div class="alert">
|
|
|
|
Something went wrong: {error}
|
|
|
|
</div>
|
|
|
|
{:else if data === undefined}
|
|
|
|
<Loading>
|
|
|
|
Loading {$tags[url]}
|
|
|
|
</Loading>
|
2024-01-14 22:24:35 +01:00
|
|
|
{:else if data.properties !== undefined}
|
2024-02-20 13:33:38 +01:00
|
|
|
<ComparisonTable
|
|
|
|
externalProperties={data.properties}
|
|
|
|
osmProperties={$tags}
|
|
|
|
{state}
|
|
|
|
{feature}
|
|
|
|
{layer}
|
|
|
|
{tags}
|
|
|
|
{readonly}
|
|
|
|
/>
|
2024-01-13 05:24:56 +01:00
|
|
|
{/if}
|