cameras: unwrap Leaflet world copies so California bbox hits ALERTWest
All checks were successful
build-and-deploy / build (push) Successful in 2m54s
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:
parent
1145ce8ec1
commit
6f0fc8dbe3
1 changed files with 11 additions and 11 deletions
|
|
@ -941,23 +941,23 @@ function mapResetView() { if (map) map.setView([25, 10], 2); }
|
||||||
|
|
||||||
function currentBBox() {
|
function currentBBox() {
|
||||||
const b = map.getBounds();
|
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 west = b.getWest();
|
||||||
let east = b.getEast();
|
let east = b.getEast();
|
||||||
let south = b.getSouth();
|
let south = Math.max(-90, Math.min(90, b.getSouth()));
|
||||||
let north = b.getNorth();
|
let north = Math.max(-90, Math.min(90, b.getNorth()));
|
||||||
const lonSpan = east - west;
|
const lonSpan = east - west;
|
||||||
|
// World view, or a wrap that spans ~the whole globe.
|
||||||
if (map.getZoom() <= 3 || lonSpan >= 300) {
|
if (map.getZoom() <= 3 || lonSpan >= 300) {
|
||||||
return '-180.0000,-85.0000,180.0000,85.0000';
|
return '-180.0000,-85.0000,180.0000,85.0000';
|
||||||
}
|
}
|
||||||
west = Math.max(-180, Math.min(180, west));
|
// Normalize each edge into [-180, 180] WITHOUT clamping both to 180
|
||||||
east = Math.max(-180, Math.min(180, east));
|
// (that collapsed CA-on-a-wrapped-copy to an empty sliver).
|
||||||
south = Math.max(-90, Math.min(90, south));
|
const norm = (x) => ((x + 180) % 360 + 360) % 360 - 180;
|
||||||
north = Math.max(-90, Math.min(90, north));
|
west = norm(west);
|
||||||
|
east = norm(east);
|
||||||
if (west >= 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)}`;
|
return `${west.toFixed(4)},${south.toFixed(4)},${east.toFixed(4)},${north.toFixed(4)}`;
|
||||||
}
|
}
|
||||||
|
|
@ -1114,7 +1114,7 @@ function camThumb(c) {
|
||||||
async function loadCams() {
|
async function loadCams() {
|
||||||
if (!map) return;
|
if (!map) return;
|
||||||
try {
|
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();
|
const cams = await r.json();
|
||||||
if (camsGroup) map.removeLayer(camsGroup);
|
if (camsGroup) map.removeLayer(camsGroup);
|
||||||
camsGroup = L.layerGroup(cams.map(c => {
|
camsGroup = L.layerGroup(cams.map(c => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue