Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1a2721fbe |
@@ -177,6 +177,18 @@ html:not(.dark) .border-indigo-800 { border-color: #a5b4fc !important; }
|
|||||||
z-index: 0;
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pinned 511 camera tiles (MapView DotCameraLayer): strip Leaflet's tooltip
|
||||||
|
* padding and let the tile's own theme colours show, so the tile is no bigger
|
||||||
|
* than the video it holds. */
|
||||||
|
.leaflet-tooltip.drb-cam-pin {
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--line-strong);
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Form inputs ─────────────────────────────────────────────────────────── */
|
/* ── Form inputs ─────────────────────────────────────────────────────────── */
|
||||||
html:not(.dark) input:not([type="submit"]):not([type="button"]):not([type="reset"]),
|
html:not(.dark) input:not([type="submit"]):not([type="button"]):not([type="reset"]),
|
||||||
html:not(.dark) select,
|
html:not(.dark) select,
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import type HlsType from "hls.js";
|
||||||
|
import type { Ny511Camera } from "@/lib/types";
|
||||||
|
|
||||||
|
// 511NY stills are served with max-age=60, so refreshing faster buys nothing.
|
||||||
|
const SNAPSHOT_REFRESH_MS = 60_000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One 511NY camera: the live HLS stream when the camera has one (NYSDOT's
|
||||||
|
* skyvdn hosts send Access-Control-Allow-Origin: *), otherwise its snapshot on
|
||||||
|
* a timer. A stream that fails falls back to the snapshot rather than a black box.
|
||||||
|
*/
|
||||||
|
export function CameraFeed({ camera, className }: { camera: Ny511Camera; className?: string }) {
|
||||||
|
const videoRef = useRef<HTMLVideoElement>(null);
|
||||||
|
const [videoFailed, setVideoFailed] = useState(false);
|
||||||
|
const [tick, setTick] = useState(() => Date.now());
|
||||||
|
const useVideo = !!camera.video_url && !videoFailed;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (useVideo) return;
|
||||||
|
const id = setInterval(() => setTick(Date.now()), SNAPSHOT_REFRESH_MS);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, [useVideo]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
const src = camera.video_url;
|
||||||
|
if (!useVideo || !video || !src) return;
|
||||||
|
let hls: HlsType | null = null;
|
||||||
|
let cancelled = false;
|
||||||
|
|
||||||
|
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
||||||
|
video.src = src; // Safari/iOS play HLS natively
|
||||||
|
} else {
|
||||||
|
import("hls.js")
|
||||||
|
.then(({ default: Hls }) => {
|
||||||
|
if (cancelled) return;
|
||||||
|
if (!Hls.isSupported()) { setVideoFailed(true); return; }
|
||||||
|
hls = new Hls({ maxBufferLength: 10, backBufferLength: 0 });
|
||||||
|
hls.on(Hls.Events.ERROR, (_evt, data) => { if (data.fatal) setVideoFailed(true); });
|
||||||
|
hls.loadSource(src);
|
||||||
|
hls.attachMedia(video);
|
||||||
|
})
|
||||||
|
.catch(() => setVideoFailed(true));
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
hls?.destroy();
|
||||||
|
video.removeAttribute("src");
|
||||||
|
video.load(); // stop the download, not just the playback
|
||||||
|
};
|
||||||
|
}, [useVideo, camera.video_url]);
|
||||||
|
|
||||||
|
if (useVideo) {
|
||||||
|
return <video ref={videoRef} muted autoPlay playsInline className={className} onError={() => setVideoFailed(true)} />;
|
||||||
|
}
|
||||||
|
if (!camera.image_url) {
|
||||||
|
return <div className={`${className ?? ""} flex items-center justify-center text-[10px] text-ink-muted`}>No image</div>;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
|
return <img src={`${camera.image_url}?t=${tick}`} alt={`Camera: ${camera.name}`} className={className} />;
|
||||||
|
}
|
||||||
@@ -22,7 +22,8 @@ import { useAircraft } from "@/lib/useAircraft";
|
|||||||
import { useAircraftTrail } from "@/lib/useAircraftTrail";
|
import { useAircraftTrail } from "@/lib/useAircraftTrail";
|
||||||
import { useVessels } from "@/lib/useVessels";
|
import { useVessels } from "@/lib/useVessels";
|
||||||
import { use511 } from "@/lib/use511";
|
import { use511 } from "@/lib/use511";
|
||||||
import type { Ny511Event, Ny511FeedStatus } from "@/lib/types";
|
import type { Ny511Camera, Ny511Event, Ny511FeedStatus } from "@/lib/types";
|
||||||
|
import { CameraFeed } from "@/components/CameraFeed";
|
||||||
|
|
||||||
// ── Leaflet icon fix ──────────────────────────────────────────────────────────
|
// ── Leaflet icon fix ──────────────────────────────────────────────────────────
|
||||||
delete (L.Icon.Default.prototype as unknown as Record<string, unknown>)._getIconUrl;
|
delete (L.Icon.Default.prototype as unknown as Record<string, unknown>)._getIconUrl;
|
||||||
@@ -380,14 +381,28 @@ function FeedProblem({ map, label, status, fetchError }: { map: L.Map; label: st
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pinned cameras: clicking a camera's snapshot pins its live feed as a small
|
||||||
|
// tile anchored at the camera, so several views along one road can be read
|
||||||
|
// against the map. Oldest pin drops past the cap.
|
||||||
|
const MAX_CAMERA_PINS = 6;
|
||||||
|
|
||||||
function DotCameraLayer() {
|
function DotCameraLayer() {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const shown = useOverlayShown(map, OVERLAY_DOT_CAMERAS);
|
const shown = useOverlayShown(map, OVERLAY_DOT_CAMERAS);
|
||||||
const { data, error } = use511(map, "cameras", shown);
|
const { data, error } = use511(map, "cameras", shown);
|
||||||
|
const [pinned, setPinned] = useState<Ny511Camera[]>([]);
|
||||||
|
const pinnedIds = useMemo(() => new Set(pinned.map((c) => c.id)), [pinned]);
|
||||||
|
|
||||||
|
const pin = (c: Ny511Camera) => {
|
||||||
|
map.closePopup();
|
||||||
|
setPinned((prev) => (prev.some((p) => p.id === c.id) ? prev : [...prev, c].slice(-MAX_CAMERA_PINS)));
|
||||||
|
};
|
||||||
|
const unpin = (id: string) => setPinned((prev) => prev.filter((p) => p.id !== id));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{shown && <FeedProblem map={map} label="DOT cameras" status={data.cameras_status} fetchError={error} />}
|
{shown && <FeedProblem map={map} label="DOT cameras" status={data.cameras_status} fetchError={error} />}
|
||||||
{(data.cameras ?? []).map((c) => (
|
{(data.cameras ?? []).filter((c) => !pinnedIds.has(c.id)).map((c) => (
|
||||||
<Marker key={c.id} position={[c.lat, c.lon]} icon={cameraIcon()}>
|
<Marker key={c.id} position={[c.lat, c.lon]} icon={cameraIcon()}>
|
||||||
<Popup minWidth={260} maxWidth={340}>
|
<Popup minWidth={260} maxWidth={340}>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
@@ -395,14 +410,32 @@ function DotCameraLayer() {
|
|||||||
{c.roadway && <div className="text-xs text-ink-muted">{c.roadway}{c.direction && c.direction !== "Unknown" ? ` · ${c.direction}` : ""}</div>}
|
{c.roadway && <div className="text-xs text-ink-muted">{c.roadway}{c.direction && c.direction !== "Unknown" ? ` · ${c.direction}` : ""}</div>}
|
||||||
{c.image_url && (
|
{c.image_url && (
|
||||||
// Popup content mounts on open, so the timestamp busts the cache per open.
|
// Popup content mounts on open, so the timestamp busts the cache per open.
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
<button type="button" onClick={() => pin(c)} title="Pin this camera to the map" className="block w-full p-0 border-0 bg-transparent cursor-pointer">
|
||||||
<img src={`${c.image_url}?t=${Date.now()}`} alt={`Camera: ${c.name}`} className="w-full rounded border border-line" loading="lazy" />
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img src={`${c.image_url}?t=${Date.now()}`} alt={`Camera: ${c.name}`} className="w-full rounded border border-line" loading="lazy" />
|
||||||
|
</button>
|
||||||
)}
|
)}
|
||||||
<div className="text-[10px] text-ink-muted">Snapshot: 511NY / NYSDOT</div>
|
<div className="text-[10px] text-ink-muted">
|
||||||
|
Click the image to pin {c.video_url ? "the live feed" : "it"} to the map · 511NY / NYSDOT
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Popup>
|
</Popup>
|
||||||
</Marker>
|
</Marker>
|
||||||
))}
|
))}
|
||||||
|
{/* Players only exist while the overlay is on, so hiding it stops every stream. */}
|
||||||
|
{shown && pinned.map((c) => (
|
||||||
|
<Marker key={`pin-${c.id}`} position={[c.lat, c.lon]} icon={cameraIcon()} zIndexOffset={300}>
|
||||||
|
<Tooltip permanent interactive direction="top" offset={[0, -8]} opacity={1} className="drb-cam-pin">
|
||||||
|
<div className="w-[192px]">
|
||||||
|
<div className="flex items-center gap-1 px-1.5 h-4">
|
||||||
|
<span className="flex-1 truncate text-[10px] leading-4 text-ink-2" title={c.name}>{c.name}</span>
|
||||||
|
<button type="button" onClick={() => unpin(c.id)} aria-label={`Unpin ${c.name}`} className="text-ink-muted hover:text-ink text-xs leading-none px-0.5">×</button>
|
||||||
|
</div>
|
||||||
|
<CameraFeed camera={c} className="block w-[192px] h-[108px] object-cover bg-black rounded-b" />
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</Marker>
|
||||||
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"react": "^18.3.0",
|
"react": "^18.3.0",
|
||||||
"react-dom": "^18.3.0",
|
"react-dom": "^18.3.0",
|
||||||
"firebase": "^10.12.0",
|
"firebase": "^10.12.0",
|
||||||
|
"hls.js": "^1.5.0",
|
||||||
"leaflet": "^1.9.4",
|
"leaflet": "^1.9.4",
|
||||||
"react-leaflet": "^4.2.1",
|
"react-leaflet": "^4.2.1",
|
||||||
"react-markdown": "^9.0.1"
|
"react-markdown": "^9.0.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user