- One shared Leaflet map (MapHost) with the traffic, watercraft and vehicle maps turned into layer components that attach to it and clean up on unmount; each layer adds its own data credit - Data loading and per-dataset state moved into hooks used by both the single pages and the combined page - /karte/thurgau: layer panel with on/off switch, controls and legend per dataset, shared year controls for the yearly layers, traffic day/time controls, layers and year in the URL - Side panel shows the selected municipality, harbour or station, or an overview of all active layers; the municipality panel lists the counting stations and harbours in that municipality - Start page shows only the combined map; single maps are linked from the layer cards - Docs: combined map in docs/datasets.md and CLAUDE.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Claudio Schaad <c.schaad@pog.ch> Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import type { DayView, Station } from '../../api/traffic';
|
|
import type { LocationSummary } from '../../api/watercraft';
|
|
import { formatNumber } from '../../traffic/format';
|
|
import { sumCounts } from '../../traffic/vehicleClasses';
|
|
|
|
interface MunicipalityContextProps {
|
|
stations: Station[] | null;
|
|
locations: LocationSummary[] | null;
|
|
day: DayView | null;
|
|
hour: number;
|
|
year: number;
|
|
onSelectStation: (code: number) => void;
|
|
onSelectLocation: (name: string) => void;
|
|
}
|
|
|
|
export function MunicipalityContext({
|
|
stations,
|
|
locations,
|
|
day,
|
|
hour,
|
|
year,
|
|
onSelectStation,
|
|
onSelectLocation,
|
|
}: MunicipalityContextProps) {
|
|
if (!stations && !locations) {
|
|
return null;
|
|
}
|
|
|
|
const dayByStation = new Map(day?.stations.map((s) => [s.code, s]) ?? []);
|
|
const hourLabel = `${String(hour).padStart(2, '0')}:00`;
|
|
|
|
return (
|
|
<section className="municipality-context">
|
|
<h3>In dieser Gemeinde</h3>
|
|
|
|
{stations &&
|
|
(stations.length > 0 ? (
|
|
<ul className="context-list">
|
|
{stations.map((station) => {
|
|
const total =
|
|
dayByStation
|
|
.get(station.code)
|
|
?.directions.reduce((sum, d) => sum + sumCounts(d.hours[hour]), 0) ?? 0;
|
|
return (
|
|
<li key={station.code}>
|
|
<button type="button" onClick={() => onSelectStation(station.code)}>
|
|
<span className="context-kind">Zählstelle</span>
|
|
<span className="context-name">{station.name}</span>
|
|
<span className="context-value">
|
|
{formatNumber(total)} Fz/h um {hourLabel}
|
|
</span>
|
|
</button>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
) : (
|
|
<p className="panel-note">Keine Verkehrszählstelle.</p>
|
|
))}
|
|
|
|
{locations &&
|
|
(locations.length > 0 ? (
|
|
<ul className="context-list">
|
|
{locations.map((location) => (
|
|
<li key={location.name}>
|
|
<button type="button" onClick={() => onSelectLocation(location.name)}>
|
|
<span className="context-kind">Bootsstandort</span>
|
|
<span className="context-name">{location.name}</span>
|
|
<span className="context-value">
|
|
{formatNumber(location.count)} Boote {year}
|
|
</span>
|
|
</button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="panel-note">Kein Bootsstandort.</p>
|
|
))}
|
|
</section>
|
|
);
|
|
}
|