fix high priority issues

This commit is contained in:
Davide Scaini
2026-03-31 22:53:50 +02:00
parent e2870c3344
commit f8abab2c23
3 changed files with 40 additions and 16 deletions
+7 -5
View File
@@ -85,13 +85,15 @@
$: if (map && MarkerClass && timeseries && !markersAdded) {
markersAdded = true;
const add = () => {
const lats = (timeseries!.lat ?? []).filter(v => v != null) as number[];
const lons = (timeseries!.lon ?? []).filter(v => v != null) as number[];
if (!lats.length) return;
// Filter lat/lon together so indices stay aligned
const pts = (timeseries!.lat ?? [])
.map((lat, i) => ({ lat, lon: (timeseries!.lon ?? [])[i] }))
.filter(p => p.lat != null && p.lon != null) as { lat: number; lon: number }[];
if (!pts.length) return;
new MarkerClass({ element: makeDot('#4ade80'), anchor: 'center' })
.setLngLat([lons[0], lats[0]]).addTo(map);
.setLngLat([pts[0].lon, pts[0].lat]).addTo(map);
new MarkerClass({ element: makeDot('#f87171'), anchor: 'center' })
.setLngLat([lons[lons.length - 1], lats[lats.length - 1]]).addTo(map);
.setLngLat([pts[pts.length - 1].lon, pts[pts.length - 1].lat]).addTo(map);
};
map.loaded() ? add() : map.once('load', add);
}