import 'leaflet/dist/leaflet.css';
import L from 'leaflet';
import { useEffect, useRef } from 'react';
import type { DayView, Station } from '../api/traffic';
import { FlowAnimator } from '../traffic/flowAnimator';
import { sumCounts } from '../traffic/vehicleClasses';
interface TrafficMapProps {
stations: Station[];
day: DayView | null;
hour: number;
selectedCode: number | null;
onSelect: (code: number) => void;
onAnimatorReady: (animator: FlowAnimator) => void;
}
const THURGAU_CENTER: L.LatLngTuple = [47.57, 9.1];
const BASE_MAP_STORAGE_KEY = 'odv.baseMap';
const ATTRIBUTION =
'© swisstopo · Daten: Kanton Thurgau';
const BASE_MAPS = [
{ name: 'Grau', layer: 'ch.swisstopo.pixelkarte-grau', maxNativeZoom: 18 },
{ name: 'Farbe', layer: 'ch.swisstopo.pixelkarte-farbe', maxNativeZoom: 18 },
{ name: 'Luftbild', layer: 'ch.swisstopo.swissimage', maxNativeZoom: 19 },
];
function createBaseLayers(): Record {
return Object.fromEntries(
BASE_MAPS.map((baseMap) => [
baseMap.name,
L.tileLayer(
`https://wmts.geo.admin.ch/1.0.0/${baseMap.layer}/default/current/3857/{z}/{x}/{y}.jpeg`,
{ maxZoom: 19, maxNativeZoom: baseMap.maxNativeZoom, attribution: ATTRIBUTION },
),
]),
);
}
export function TrafficMap({
stations,
day,
hour,
selectedCode,
onSelect,
onAnimatorReady,
}: TrafficMapProps) {
const containerRef = useRef(null);
const mapRef = useRef(null);
const animatorRef = useRef(null);
const roadsRef = useRef(null);
const markersRef = useRef