fix(map): geofence delete, vessel snapshots, sentinel cache, news briefs
Geofences could be drawn but not removed. VesselAPI Hormuz dots vanished
on restart and DVR skipped between the 5 daily polls. Sentinel-1 re-hit
STAC on every pan and often painted a neighbouring swath. Executive
briefs truncated; ticker stayed empty unless something was critical.
- Layer-panel list + polygon popup DELETE /api/geofences/{id}
- Persist VesselAPI polls to vessels (UTC-day purge, DVR as-of, boot hydrate)
- Cache Sentinel-1 by 2° cell; pick covering scene; clip Leaflet tiles
- Retry truncated LLM JSON; ticker falls back to medium/low; 3-min HUD poll
This commit is contained in:
parent
fdf5969e27
commit
c48788d4b6
20 changed files with 669 additions and 57 deletions
|
|
@ -51,7 +51,9 @@ PC_SAS_TOKEN = "https://planetarycomputer.microsoft.com/api/sas/v1/token/sentine
|
|||
# nginx vhost. Relative template — Leaflet resolves it against the page origin,
|
||||
# so the browser never touches a raw loopback port or titiler.xyz.
|
||||
TITILER_COG_TILES = f"{TITILER_PUBLIC_BASE}/cog/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}"
|
||||
SENTINEL1_TTL = 20 * 60 # 15–30 min quota-friendly window
|
||||
SENTINEL1_TTL = 6 * 3600 # S-1 revisit is 6–12 days; cache the COG all afternoon
|
||||
SENTINEL1_CELL = 2.0 # degrees — pan/zoom inside a cell reuses the same scene
|
||||
SENTINEL1_STAC_LIMIT = 8
|
||||
SENTINEL1_ATTRIBUTION = "Copernicus Sentinel-1 / Microsoft Planetary Computer"
|
||||
|
||||
# GPSJAM (John Wiseman / ADS-B Exchange): daily H3 hexes of aircraft nav
|
||||
|
|
@ -1244,25 +1246,71 @@ def sentinel1_tile_url(signed_cog: str) -> str:
|
|||
return f"{TITILER_COG_TILES}?{params}"
|
||||
|
||||
|
||||
def feature_bbox(feat: dict) -> list[float] | None:
|
||||
"""STAC Feature bbox as [minlon, minlat, maxlon, maxlat], or None."""
|
||||
raw = feat.get("bbox") if isinstance(feat, dict) else None
|
||||
if isinstance(raw, (list, tuple)) and len(raw) >= 4:
|
||||
try:
|
||||
return [float(raw[0]), float(raw[1]), float(raw[2]), float(raw[3])]
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
geom = (feat or {}).get("geometry") or {}
|
||||
coords = geom.get("coordinates") if isinstance(geom, dict) else None
|
||||
if not coords:
|
||||
return None
|
||||
lons: list[float] = []
|
||||
lats: list[float] = []
|
||||
|
||||
def _walk(node: Any) -> None:
|
||||
if isinstance(node, (list, tuple)) and node and isinstance(node[0], (int, float)):
|
||||
lons.append(float(node[0]))
|
||||
lats.append(float(node[1]))
|
||||
elif isinstance(node, (list, tuple)):
|
||||
for child in node:
|
||||
_walk(child)
|
||||
|
||||
_walk(coords)
|
||||
if not lons:
|
||||
return None
|
||||
return [min(lons), min(lats), max(lons), max(lats)]
|
||||
|
||||
|
||||
def pick_sentinel_feature(features: list, lon: float, lat: float) -> dict | None:
|
||||
"""Prefer the scene whose bbox covers the viewport center; else first."""
|
||||
if not features:
|
||||
return None
|
||||
for feat in features:
|
||||
bb = feature_bbox(feat)
|
||||
if bb and bb[0] <= lon <= bb[2] and bb[1] <= lat <= bb[3]:
|
||||
return feat
|
||||
return features[0]
|
||||
|
||||
|
||||
async def fetch_sentinel1(bbox: str) -> dict | None:
|
||||
"""Most recent Sentinel-1 GRD COG for a viewport, signed and TiTiler-ready.
|
||||
|
||||
Returns the overlay tile-template dict, or ``None`` when no GRD imagery
|
||||
covers the bbox in the last 7 days (caller maps to 404). Queries Planetary
|
||||
Computer only when called; cached per quantized bbox + UTC day.
|
||||
Computer only when called; cached per 2° cell + UTC day so pan/zoom inside
|
||||
the same region reuses the COG instead of picking a neighbouring swath.
|
||||
"""
|
||||
minlon, minlat, maxlon, maxlat = parse_bbox(bbox)
|
||||
qminlon, qminlat, qmaxlon, qmaxlat = quantize_bbox(
|
||||
minlon, minlat, maxlon, maxlat, step=SENTINEL1_CELL,
|
||||
)
|
||||
day = datetime.now(timezone.utc).date().isoformat()
|
||||
key = f"sentinel1:{day}:{bbox_cell_key(bbox)}"
|
||||
key = f"sentinel1:{day}:{qminlon:.4f},{qminlat:.4f},{qmaxlon:.4f},{qmaxlat:.4f}"
|
||||
clon = (qminlon + qmaxlon) / 2.0
|
||||
clat = (qminlat + qmaxlat) / 2.0
|
||||
|
||||
async def _load() -> dict | None:
|
||||
now = datetime.now(timezone.utc)
|
||||
week_ago = now - timedelta(days=7)
|
||||
payload = {
|
||||
"collections": ["sentinel-1-grd"],
|
||||
"bbox": [minlon, minlat, maxlon, maxlat],
|
||||
"bbox": [qminlon, qminlat, qmaxlon, qmaxlat],
|
||||
"datetime": f"{week_ago.isoformat()}/{now.isoformat()}",
|
||||
"limit": 1,
|
||||
"limit": SENTINEL1_STAC_LIMIT,
|
||||
"sortby": [{"field": "datetime", "direction": "desc"}],
|
||||
}
|
||||
data = await _pc_call(_post_json(PC_STAC_SEARCH, json=payload))
|
||||
|
|
@ -1270,7 +1318,9 @@ async def fetch_sentinel1(bbox: str) -> dict | None:
|
|||
if not features:
|
||||
return None
|
||||
|
||||
feat = features[0]
|
||||
feat = pick_sentinel_feature(features, clon, clat)
|
||||
if not feat:
|
||||
return None
|
||||
assets = feat.get("assets") or {}
|
||||
chosen_href: str | None = None
|
||||
polarization: str | None = None
|
||||
|
|
@ -1299,6 +1349,7 @@ async def fetch_sentinel1(bbox: str) -> dict | None:
|
|||
"datetime": props.get("datetime") or feat.get("datetime"),
|
||||
"polarization": polarization,
|
||||
"attribution": SENTINEL1_ATTRIBUTION,
|
||||
"bbox": feature_bbox(feat),
|
||||
}
|
||||
|
||||
return await _ttl_get(key, float(SENTINEL1_TTL), _load)
|
||||
|
|
|
|||
Loading…
Reference in a new issue