MapComplete/src/UI/Favourites/FavouriteSummary.svelte

83 lines
3.1 KiB
Svelte
Raw Normal View History

<script lang="ts">
2023-12-19 22:08:00 +01:00
import type { SpecialVisualizationState } from "../SpecialVisualization"
import TagRenderingAnswer from "../Popup/TagRendering/TagRenderingAnswer.svelte"
import type { Feature } from "geojson"
import { ImmutableStore, UIEventSource } from "../../Logic/UIEventSource"
import { GeoOperations } from "../../Logic/GeoOperations"
import Center from "../../assets/svg/Center.svelte"
2023-12-19 22:08:00 +01:00
export let feature: Feature
let properties: Record<string, string> = feature.properties
export let state: SpecialVisualizationState
let tags =
state.featureProperties.getStore(properties.id) ??
new UIEventSource<Record<string, string>>(properties)
2023-12-02 03:19:50 +01:00
2023-12-19 22:08:00 +01:00
const favLayer = state.layerState.filteredLayers.get("favourite")
const favConfig = favLayer?.layerDef
const titleConfig = favConfig?.title
2023-12-04 03:32:25 +01:00
function center() {
2023-12-19 22:08:00 +01:00
const [lon, lat] = GeoOperations.centerpointCoordinates(feature)
state.mapProperties.location.setData({ lon, lat })
const z = state.mapProperties.zoom.data
2023-12-19 22:08:00 +01:00
state.mapProperties.zoom.setData(Math.min(17, Math.max(12, z)))
state.guistate.menuIsOpened.setData(false)
2023-12-02 03:19:50 +01:00
}
2023-12-04 03:32:25 +01:00
function select() {
2023-12-19 22:08:00 +01:00
state.selectedElement.setData(feature)
center()
2023-12-02 03:19:50 +01:00
}
2023-12-04 03:32:25 +01:00
2023-12-19 22:08:00 +01:00
const coord = GeoOperations.centerpointCoordinates(feature)
2023-12-04 03:32:25 +01:00
const distance = state.mapProperties.location.stabilized(500).mapD(({ lon, lat }) => {
2023-12-19 22:08:00 +01:00
let meters = Math.round(GeoOperations.distanceBetween(coord, [lon, lat]))
2023-12-21 17:36:43 +01:00
return GeoOperations.distanceToHuman(meters)
2023-12-19 22:08:00 +01:00
})
const titleIconBlacklist = ["osmlink", "sharelink", "favourite_title_icon"]
</script>
2023-12-06 03:07:36 +01:00
{#if favLayer !== undefined}
2023-12-19 22:08:00 +01:00
<div
class="no-weblate my-1 flex grid-cols-2 flex-wrap items-center justify-between rounded border-2 border-dashed border-gray-300 px-1"
>
<button class="link m-0 ml-1 cursor-pointer justify-self-start" on:click={() => select()}>
<TagRenderingAnswer
{state}
config={titleConfig}
extraClasses="underline"
layer={favConfig}
selectedElement={feature}
{tags}
/>
</button>
2023-12-04 03:32:25 +01:00
2023-12-19 22:08:00 +01:00
<div
class="title-icons links-as-button flex flex-wrap items-center gap-x-0.5 self-end justify-self-end p-1 pt-0.5 sm:pt-1"
>
{#each favConfig.titleIcons as titleIconConfig}
{#if titleIconBlacklist.indexOf(titleIconConfig.id) < 0 && (titleIconConfig.condition?.matchesProperties(properties) ?? true) && (titleIconConfig.metacondition?.matchesProperties( { ...properties, ...state.userRelatedState.preferencesAsTags.data } ) ?? true) && titleIconConfig.IsKnown(properties)}
<div class={titleIconConfig.renderIconClass ?? "flex h-8 w-8 items-center"}>
<TagRenderingAnswer
config={titleIconConfig}
{tags}
selectedElement={feature}
{state}
layer={favLayer.layerDef}
extraClasses="h-full justify-center"
/>
</div>
{/if}
{/each}
2023-12-04 03:32:25 +01:00
2023-12-19 22:08:00 +01:00
<button class="p-1" on:click={() => center()}>
<Center class="h-6 w-6" />
</button>
<div class="w-14">
{$distance}
</div>
2023-12-04 03:32:25 +01:00
</div>
2023-12-02 03:19:50 +01:00
</div>
2023-12-06 03:07:36 +01:00
{/if}