diff --git a/site/src/components/SegmentsView.svelte b/site/src/components/SegmentsView.svelte index d0a2173..235b6ef 100644 --- a/site/src/components/SegmentsView.svelte +++ b/site/src/components/SegmentsView.svelte @@ -66,7 +66,23 @@ map.on('mouseenter', 'seg-hit', () => { map.getCanvas().style.cursor = 'pointer'; }); map.on('mouseleave', 'seg-hit', () => { map.getCanvas().style.cursor = ''; }); - fetchSegments(); + // Initial view: fit to all existing segments, fall back to default center + fetch('/api/segments', { credentials: 'include' }) + .then(r => r.ok ? r.json() : []) + .then((all: Segment[]) => { + if (all.length > 0) { + const lonMin = Math.min(...all.map(s => s.bbox[0])); + const latMin = Math.min(...all.map(s => s.bbox[1])); + const lonMax = Math.max(...all.map(s => s.bbox[2])); + const latMax = Math.max(...all.map(s => s.bbox[3])); + map.fitBounds([[lonMin, latMin], [lonMax, latMax]], { padding: 60, maxZoom: 14 }); + segments = all; + updateMapSource(); + } else { + fetchSegments(); + } + }) + .catch(() => fetchSegments()); }); map.on('moveend', () => {