Zoom to the extent of map markers on first load #50

This commit is contained in:
Ian Renton
2026-04-05 10:26:20 +01:00
parent b3353b168c
commit 06c16e2f1f
10 changed files with 33 additions and 22 deletions

View File

@@ -22,6 +22,8 @@ var ituZones;
var wabwaiGrid;
// Tracks the currently-loaded basemap provider string to avoid unnecessary tile reloads
var loadedBasemap;
// Tracks whether this is the first display of markers after page load
var firstLoad = true;
// Load spots and populate the map.
function loadSpots() {
@@ -76,6 +78,15 @@ function updateMap() {
}
}
});
// On first load, zoom to the extent of the markers
if (firstLoad) {
if (markersLayer.getLayers().length >= 2) {
var group = new L.featureGroup(markersLayer.getLayers());
map.fitBounds(group.getBounds().pad(0.1));
}
firstLoad = false;
}
}
// Get an icon for a spot, based on its band, using PSK Reporter colours, its program etc.