Files
Noel Sabia 8d687ad05b
ci / check (push) Successful in 1m17s
ci / check (pull_request) Successful in 1m13s
feat: add operational use cases console
2026-11-14 21:39:15 +01:00

363 lines
13 KiB
Vue

<script setup lang="ts">
import type { CoolRouteBundle, CoolRouteId } from '#shared/cool'
import { ROUTE_ORDER, routeValuesFor } from '#shared/use-cases'
interface BuildingPolygon {
name: string | null
kind: string
points: Array<[number, number]>
}
interface PlacePoint {
name: string | null
lat: number
lon: number
near_routes_m?: Record<string, number>
}
interface PlacesBundle {
cool_places: PlacePoint[]
water: PlacePoint[]
benches: PlacePoint[]
}
const props = defineProps<{
bundle: CoolRouteBundle
buildings: BuildingPolygon[] | null
places: PlacesBundle | null
selectedRouteId: CoolRouteId
time: string
}>()
const WIDTH = 760
const HEIGHT = 380
const PAD = 34
const zoom = ref(1)
const map = ref<SVGSVGElement | null>(null)
const viewBox = computed(() => {
if (zoom.value === 1) return `0 0 ${WIDTH} ${HEIGHT}`
const w = WIDTH / zoom.value
const h = HEIGHT / zoom.value
return `${(WIDTH - w) / 2} ${(HEIGHT - h) / 2} ${w} ${h}`
})
const bounds = computed(() => {
const points = props.bundle.routes.flatMap((route) => route.geometry)
if (!points.length) return { minLon: 9.2175, maxLon: 9.2204, minLat: 49.1402, maxLat: 49.1426 }
const lons = points.map(([lon]) => lon)
const lats = points.map(([, lat]) => lat)
return {
minLon: Math.min(...lons),
maxLon: Math.max(...lons),
minLat: Math.min(...lats),
maxLat: Math.max(...lats),
}
})
function project([lon, lat]: [number, number]): [number, number] {
const b = bounds.value
const nx = (lon - b.minLon) / Math.max(b.maxLon - b.minLon, 0.000001)
const ny = (b.maxLat - lat) / Math.max(b.maxLat - b.minLat, 0.000001)
return [PAD + nx * (WIDTH - PAD * 2), PAD + ny * (HEIGHT - PAD * 2)]
}
function pathFor(routeId: CoolRouteId): string {
const route = props.bundle.routes.find((entry) => entry.id === routeId)
if (!route || route.geometry.length < 2) return ''
const points = route.geometry.map(project)
return points.map(([x, y], index) => `${index === 0 ? 'M' : 'L'} ${x.toFixed(2)} ${y.toFixed(2)}`).join(' ')
}
const polygons = computed(() =>
(props.buildings ?? []).map((building) => ({
...building,
d: `${building.points
.map(([lon, lat], index) => {
const [x, y] = project([lon, lat])
return `${index === 0 ? 'M' : 'L'} ${x.toFixed(2)} ${y.toFixed(2)}`
})
.join(' ')} Z`,
})),
)
const routePaths = computed(() =>
ROUTE_ORDER.map((id) => ({
id,
d: pathFor(id),
active: id === props.selectedRouteId,
recommended: props.bundle.recommendationByTime[props.time] === id,
})),
)
const selectedRoute = computed(() =>
props.bundle.routes.find((route) => route.id === props.selectedRouteId),
)
const values = computed(() => routeValuesFor(props.bundle, props.selectedRouteId, props.time))
const origin = computed(() => {
const [x, y] = project([
props.bundle.origin.lon ?? 9.218444,
props.bundle.origin.lat ?? 49.140269,
])
return { x, y }
})
const destination = computed(() => {
const [x, y] = project([
props.bundle.destination.lon ?? 9.218659,
props.bundle.destination.lat ?? 49.142318,
])
return { x, y }
})
// The shaded route's middle is the real Deutschhof / Kiliansplatz corridor.
const corridor = computed(() => {
const route = props.bundle.routes.find((entry) => entry.id === 'shaded')
if (!route || route.geometry.length < 4) return ''
const slice = route.geometry.slice(
Math.floor(route.geometry.length * 0.28),
Math.ceil(route.geometry.length * 0.78),
)
return slice
.map(([lon, lat], index) => {
const [x, y] = project([lon, lat])
return `${index === 0 ? 'M' : 'L'} ${x.toFixed(2)} ${y.toFixed(2)}`
})
.join(' ')
})
const waterPoints = computed(() =>
(props.places?.water ?? []).map((place) => {
const [x, y] = project([place.lon, place.lat])
return { ...place, x, y }
}),
)
const benchPoints = computed(() =>
(props.places?.benches ?? [])
.filter((place) => {
const near = place.near_routes_m?.[props.selectedRouteId]
return typeof near === 'number' && near <= 30
})
.slice(0, 7)
.map((place) => {
const [x, y] = project([place.lon, place.lat])
return { ...place, x, y }
}),
)
const keyPlaces = computed(() => {
const names = ['Kiliansplatz', 'Marktplatz', 'Deutschhof']
return (props.places?.cool_places ?? [])
.filter((place) => place.name && names.some((name) => place.name!.includes(name)))
.slice(0, 3)
.map((place) => {
const [x, y] = project([place.lon, place.lat])
return { ...place, x, y }
})
})
function zoomBy(delta: number) {
zoom.value = Math.max(1, Math.min(2.2, Math.round((zoom.value + delta) * 10) / 10))
}
function resetZoom() {
zoom.value = 1
}
</script>
<template>
<figure class="m-0 flex w-full flex-col gap-2">
<div
class="relative h-[370px] w-full overflow-hidden rounded-xl border border-[#1e3a52] bg-[#050f17] shadow-inner"
>
<svg
ref="map"
class="absolute inset-0 h-full w-full"
:viewBox="viewBox"
role="img"
:aria-label="`Schematic of the ${selectedRoute?.longName ?? selectedRouteId} between ${bundle.origin.name} and ${bundle.destination.name}. Buildings are real OSM footprints; the projection is a schematic and not for navigation.`"
preserveAspectRatio="xMidYMid meet"
>
<defs>
<pattern id="uc-grid" width="38" height="38" patternUnits="userSpaceOnUse">
<path d="M 38 0 L 0 0 0 38" fill="none" stroke="#102536" stroke-width="0.8" stroke-dasharray="2 3" />
</pattern>
<marker id="uc-arrow" markerWidth="7" markerHeight="7" refX="5" refY="5" viewBox="0 0 10 10" orient="auto-start-reverse">
<path d="M 0 1.5 L 8 5 L 0 8.5 z" fill="#00C3CD" />
</marker>
<filter id="uc-glow" x="-30%" y="-30%" width="160%" height="160%">
<feGaussianBlur stdDeviation="4" result="blur" />
<feMerge>
<feMergeNode in="blur" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<rect width="100%" height="100%" fill="url(#uc-grid)" />
<!-- Real OSM building footprints around the route. -->
<path
v-for="(building, index) in polygons"
:key="`${building.name ?? 'building'}-${index}`"
:d="building.d"
fill="#0e2233"
:stroke="building.name ? '#23445f' : '#1a354c'"
stroke-width="0.8"
/>
<!-- Translucent corridor behind the real shaded route. -->
<path
v-if="corridor"
:d="corridor"
fill="none"
stroke="#00C3CD"
stroke-width="26"
stroke-linecap="round"
stroke-linejoin="round"
opacity="0.07"
/>
<!-- Alternatives first. -->
<path
v-for="path in routePaths.filter((entry) => !entry.active)"
:key="path.id"
:d="path.d"
fill="none"
stroke="#64748B"
stroke-width="2.4"
stroke-dasharray="5 4"
stroke-linecap="round"
stroke-linejoin="round"
opacity="0.55"
/>
<!-- Selected route: glow + line + direction arrow. -->
<template v-for="path in routePaths.filter((entry) => entry.active)" :key="`active-${path.id}`">
<path
:d="path.d"
fill="none"
stroke="#00C3CD"
stroke-width="10"
stroke-linecap="round"
stroke-linejoin="round"
opacity="0.18"
filter="url(#uc-glow)"
/>
<path
:d="path.d"
fill="none"
stroke="#00C3CD"
stroke-width="4"
stroke-linecap="round"
stroke-linejoin="round"
marker-end="url(#uc-arrow)"
/>
</template>
<!-- Real drinking water points. -->
<g v-for="(place, index) in waterPoints" :key="`water-${index}`" :transform="`translate(${place.x} ${place.y})`">
<circle r="7" fill="#081723" stroke="#00C3CD" stroke-width="1" opacity="0.9" />
<path d="M0 -4 C3 0 4 1.2 4 2.8 A4 4 0 1 1 -4 2.8 C-4 1.2 -3 0 0 -4 Z" fill="#00C3CD" />
<title>{{ place.name ?? 'Drinking water' }}</title>
</g>
<!-- Benches within 30 m of the selected route. -->
<g v-for="(place, index) in benchPoints" :key="`bench-${index}`" :transform="`translate(${place.x} ${place.y})`">
<rect x="-3" y="-2" width="6" height="4" rx="1" fill="#94A3B8" opacity="0.8" />
<title>{{ place.name ?? 'Mapped bench' }}</title>
</g>
<!-- Key place labels from the real bundle. -->
<g v-for="place in keyPlaces" :key="place.name ?? 'place'" :transform="`translate(${place.x} ${place.y})`">
<circle r="2.2" fill="#00C3CD" />
<text x="6" y="3" fill="#94A3B8" font-size="8.5" font-family="Inter, sans-serif">{{ place.name }}</text>
</g>
<!-- Origin / destination cards, like a wayfinding board. -->
<g :transform="`translate(${origin.x} ${origin.y})`">
<circle r="10" fill="#00C3CD" stroke="#081723" stroke-width="2" />
<text x="0" y="3.5" text-anchor="middle" fill="#081723" font-size="10" font-weight="700" font-family="Inter, sans-serif">A</text>
<g transform="translate(16 -26)">
<rect width="132" height="32" rx="6" fill="#132b40" stroke="#00C3CD" stroke-opacity="0.5" />
<text x="8" y="12" fill="#94A3B8" font-size="6.5" font-family="Inter, sans-serif" letter-spacing="0.8">START POINT</text>
<text x="8" y="24" fill="#FFFFFF" font-size="9" font-weight="600" font-family="Inter, sans-serif">{{ bundle.origin.name }}</text>
</g>
</g>
<g :transform="`translate(${destination.x} ${destination.y})`">
<circle r="10" fill="#FFFFFF" stroke="#081723" stroke-width="2" />
<text x="0" y="3.5" text-anchor="middle" fill="#081723" font-size="10" font-weight="700" font-family="Inter, sans-serif">B</text>
<g transform="translate(-148 12)">
<rect width="132" height="32" rx="6" fill="#132b40" stroke="#00C3CD" stroke-opacity="0.5" />
<text x="8" y="12" fill="#94A3B8" font-size="6.5" font-family="Inter, sans-serif" letter-spacing="0.8">DESTINATION</text>
<text x="8" y="24" fill="#FFFFFF" font-size="9" font-weight="600" font-family="Inter, sans-serif">{{ bundle.destination.name }}</text>
</g>
</g>
<!-- Compass + solar cue. -->
<g transform="translate(38 40)">
<circle r="17" fill="#081723" fill-opacity="0.7" stroke="#1e3a52" />
<text x="0" y="-21" text-anchor="middle" fill="#94A3B8" font-size="7" font-family="Inter, sans-serif">N</text>
<path d="M0 -12 L4 4 L0 1 L-4 4 Z" fill="#00C3CD" />
</g>
</svg>
<!-- Canvas controls. -->
<div class="absolute right-3 top-3 z-10 flex flex-col gap-1 rounded-lg border border-[#1e3a52] bg-[#0e2233]/90 p-1 backdrop-blur">
<button
type="button"
class="flex h-7 w-7 items-center justify-center rounded text-[#94A3B8] transition-colors hover:bg-[#132b40] hover:text-white"
aria-label="Zoom in"
@click="zoomBy(0.3)"
>
<Icon name="material-symbols:add" class="text-[17px]" />
</button>
<button
type="button"
class="flex h-7 w-7 items-center justify-center rounded text-[#94A3B8] transition-colors hover:bg-[#132b40] hover:text-white"
aria-label="Zoom out"
@click="zoomBy(-0.3)"
>
<Icon name="material-symbols:remove" class="text-[17px]" />
</button>
<button
type="button"
class="flex h-7 w-7 items-center justify-center rounded text-[#00C3CD] transition-colors hover:bg-[#132b40]"
aria-label="Reset map view"
title="Recenter view"
@click="resetZoom"
>
<Icon name="material-symbols:my-location" class="text-[17px]" />
</button>
</div>
<div class="pointer-events-none absolute bottom-3 left-3 z-10 rounded-md border border-[#1e3a52] bg-[#0e2233]/90 px-2 py-1 text-[9px] font-medium text-[#94A3B8] backdrop-blur">
Schematic projection · real OSM footprints · not for navigation
</div>
</div>
<figcaption class="flex flex-wrap items-center justify-between gap-3 pt-1 text-[11px] text-[#94A3B8]">
<div class="flex flex-wrap items-center gap-4">
<span class="flex items-center gap-1.5">
<span class="h-1.5 w-3.5 rounded-full bg-[#00C3CD]" />
<span class="font-medium text-white">Active recommendation</span>
</span>
<span class="flex items-center gap-1.5">
<span class="h-2.5 w-2.5 rounded-sm border border-[#64748B] bg-[#475569]/40" />
<span>Alternative route</span>
</span>
<span class="flex items-center gap-1.5">
<span class="h-2.5 w-2.5 rounded-full border border-[#00C3CD] bg-[#00C3CD]/20" />
<span>Drinking water</span>
</span>
<span class="flex items-center gap-1.5">
<span class="h-2.5 w-2.5 rounded-sm bg-[#94A3B8]" />
<span>Mapped bench</span>
</span>
</div>
<span class="font-mono text-[#64748B]">EPSG:4326 · modeled, not measured</span>
</figcaption>
</figure>
</template>