cameras: unwrap Leaflet world copies so California bbox hits ALERTWest
All checks were successful
build-and-deploy / build (push) Successful in 2m54s

Viewing CA on a wrapped map copy clamped both edges to 180, so the API
returned the newest 2000 feeds (mostly VDOT HLS in Virginia) and the CA
viewport was empty. Normalize longitudes into [-180,180] and load 5000.
This commit is contained in:
Sirius DevOps 2026-08-27 16:03:50 -04:00
parent 1145ce8ec1
commit 6f0fc8dbe3

View file

@ -941,23 +941,23 @@ function mapResetView() { if (map) map.setView([25, 10], 2); }
function currentBBox() {
const b = map.getBounds();
// Leaflet at low zoom / worldCopyJump reports longitudes outside ±180
// (and west>east after clamping). That made /api/cameras return a tiny
// sliver (~dozens of pins) instead of the full set.
let west = b.getWest();
let east = b.getEast();
let south = b.getSouth();
let north = b.getNorth();
let south = Math.max(-90, Math.min(90, b.getSouth()));
let north = Math.max(-90, Math.min(90, b.getNorth()));
const lonSpan = east - west;
// World view, or a wrap that spans ~the whole globe.
if (map.getZoom() <= 3 || lonSpan >= 300) {
return '-180.0000,-85.0000,180.0000,85.0000';
}
west = Math.max(-180, Math.min(180, west));
east = Math.max(-180, Math.min(180, east));
south = Math.max(-90, Math.min(90, south));
north = Math.max(-90, Math.min(90, north));
// Normalize each edge into [-180, 180] WITHOUT clamping both to 180
// (that collapsed CA-on-a-wrapped-copy to an empty sliver).
const norm = (x) => ((x + 180) % 360 + 360) % 360 - 180;
west = norm(west);
east = norm(east);
if (west >= east) {
return '-180.0000,-85.0000,180.0000,85.0000';
// Crosses the dateline: keep the latitude strip, don't drop the state.
return `-180.0000,${south.toFixed(4)},180.0000,${north.toFixed(4)}`;
}
return `${west.toFixed(4)},${south.toFixed(4)},${east.toFixed(4)},${north.toFixed(4)}`;
}
@ -1114,7 +1114,7 @@ function camThumb(c) {
async function loadCams() {
if (!map) return;
try {
const r = await fetch(`${API}/api/cameras?bbox=${currentBBox()}&limit=2000`);
const r = await fetch(`${API}/api/cameras?bbox=${currentBBox()}&limit=5000`);
const cams = await r.json();
if (camsGroup) map.removeLayer(camsGroup);
camsGroup = L.layerGroup(cams.map(c => {