2024-08-09 14:40:07 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import type { Feature } from "geojson"
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import Qr from "../../Utils/Qr"
|
|
|
|
import { GeoOperations } from "../../Logic/GeoOperations"
|
|
|
|
|
|
|
|
const smallSize = 100
|
|
|
|
const bigSize = 200
|
|
|
|
let size = new UIEventSource(smallSize)
|
|
|
|
|
|
|
|
export let state: SpecialVisualizationState
|
|
|
|
export let tags: UIEventSource<Record<string, string>>
|
|
|
|
export let feature: Feature
|
2025-05-29 23:26:59 +02:00
|
|
|
export let extraUrlParams: Record<string, string> = {}
|
2024-08-09 14:40:07 +02:00
|
|
|
|
2024-08-14 13:53:56 +02:00
|
|
|
const includeLayout = window.location.pathname.split("/").at(-1).startsWith("theme")
|
|
|
|
let id: Store<string> = tags.mapD((tags) => tags.id)
|
2025-05-29 23:26:59 +02:00
|
|
|
extraUrlParams["z"] ??= 15
|
|
|
|
if (includeLayout) {
|
|
|
|
extraUrlParams["layout"] ??= state.theme.id
|
|
|
|
}
|
|
|
|
if (feature) {
|
|
|
|
const [lon, lat] = GeoOperations.centerpointCoordinates(feature)
|
|
|
|
extraUrlParams["lon"] ??= "" + lon
|
|
|
|
extraUrlParams["lat"] ??= "" + lat
|
|
|
|
} else if (state?.mapProperties?.location?.data) {
|
|
|
|
const l = state?.mapProperties?.location?.data
|
|
|
|
extraUrlParams["lon"] ??= "" + l.lon
|
|
|
|
extraUrlParams["lat"] ??= "" + l.lat
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = []
|
|
|
|
for (const key in extraUrlParams) {
|
|
|
|
console.log(key, "-->", extraUrlParams[key])
|
|
|
|
params.push(key + "=" + encodeURIComponent(extraUrlParams[key]))
|
|
|
|
}
|
|
|
|
let url = id.map((id) => {
|
|
|
|
if (id) {
|
|
|
|
return "#" + id
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}).map(
|
2024-08-14 13:53:56 +02:00
|
|
|
(id) =>
|
2025-05-29 23:26:59 +02:00
|
|
|
`${window.location.protocol}//${window.location.host}${window.location.pathname}?${params.join("&")}${id}`
|
2024-08-14 13:53:56 +02:00
|
|
|
)
|
2024-08-09 14:40:07 +02:00
|
|
|
|
|
|
|
function toggleSize() {
|
|
|
|
if (size.data !== bigSize) {
|
|
|
|
size.setData(bigSize)
|
|
|
|
} else {
|
|
|
|
size.setData(smallSize)
|
|
|
|
}
|
|
|
|
}
|
2025-05-29 23:26:59 +02:00
|
|
|
|
|
|
|
url.addCallbackAndRunD(url => console.log("URL IS", url))
|
2024-08-09 14:40:07 +02:00
|
|
|
</script>
|
|
|
|
|
2025-05-29 23:26:59 +02:00
|
|
|
{#if $id?.startsWith("node/-")}
|
2024-08-09 14:40:07 +02:00
|
|
|
<!-- Not yet uploaded, doesn't have a fixed ID -->
|
|
|
|
<Loading />
|
|
|
|
{:else}
|
2024-08-14 13:53:56 +02:00
|
|
|
<img
|
|
|
|
on:click={() => toggleSize()}
|
|
|
|
src={new Qr($url).toImageElement($size)}
|
|
|
|
style={`width: ${$size}px; height: ${$size}px`}
|
|
|
|
/>
|
2024-08-09 14:40:07 +02:00
|
|
|
{/if}
|