segments: fit initial map view to all existing segments
This commit is contained in:
@@ -66,7 +66,23 @@
|
||||
map.on('mouseenter', 'seg-hit', () => { map.getCanvas().style.cursor = 'pointer'; });
|
||||
map.on('mouseleave', 'seg-hit', () => { map.getCanvas().style.cursor = ''; });
|
||||
|
||||
// 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', () => {
|
||||
|
||||
Reference in New Issue
Block a user