58 lines
1.7 KiB
Vue
58 lines
1.7 KiB
Vue
<script setup lang="ts">
|
|
import type { Sensor } from '#shared/types'
|
|
|
|
const props = defineProps<{
|
|
sensors: Sensor[]
|
|
activeId: string
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
select: [sensorId: string]
|
|
}>()
|
|
|
|
const bounds = computed(() => {
|
|
const lats = props.sensors.map((sensor) => sensor.lat)
|
|
const lons = props.sensors.map((sensor) => sensor.lon)
|
|
const pad = 0.0009
|
|
return {
|
|
minLat: Math.min(...lats) - pad,
|
|
maxLat: Math.max(...lats) + pad,
|
|
minLon: Math.min(...lons) - pad,
|
|
maxLon: Math.max(...lons) + pad,
|
|
}
|
|
})
|
|
|
|
function position(sensor: Sensor) {
|
|
const { minLat, maxLat, minLon, maxLon } = bounds.value
|
|
const x = ((sensor.lon - minLon) / (maxLon - minLon)) * 76 + 12
|
|
const y = ((maxLat - sensor.lat) / (maxLat - minLat)) * 52 + 30
|
|
return { left: `${x}%`, top: `${y}%` }
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="map-frame" role="group" aria-label="Schematic map of the eight Heilbronn sensors">
|
|
<div class="map-frame__label">
|
|
<OnyxBadge color="info" density="compact">Schematic</OnyxBadge>
|
|
<p class="small muted" style="margin: 0.35rem 0 0">
|
|
Relative sensor positions in the 580 m cluster. Not a city-wide heatmap.
|
|
</p>
|
|
</div>
|
|
|
|
<button
|
|
v-for="(sensor, index) in props.sensors"
|
|
:key="sensor.id"
|
|
type="button"
|
|
class="sensor-pin"
|
|
:class="{ 'sensor-pin--active': sensor.id === props.activeId }"
|
|
:style="position(sensor)"
|
|
:aria-label="`${sensor.name}: mean ${sensor.mean}, p95 ${sensor.p95}`"
|
|
:aria-pressed="sensor.id === props.activeId"
|
|
@click="emit('select', sensor.id)"
|
|
>
|
|
<span class="sensor-pin__dot">{{ index + 1 }}</span>
|
|
<span class="sensor-pin__name">{{ sensor.name }}</span>
|
|
</button>
|
|
</div>
|
|
</template>
|