bug fix
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s

This commit is contained in:
Tudor
2026-01-08 23:29:48 +00:00
parent b7943e1042
commit 3f8e1911aa

View File

@@ -610,51 +610,79 @@ function formatMetricValue(value, metric) {
* Initialize Leaflet maps for all school cards in a container * Initialize Leaflet maps for all school cards in a container
*/ */
function initializeSchoolMaps(container) { function initializeSchoolMaps(container) {
// Check if Leaflet is loaded
if (typeof L === "undefined") {
console.warn("Leaflet not loaded yet, skipping map initialization");
return;
}
const mapElements = container.querySelectorAll(".school-map");
if (mapElements.length === 0) return;
// Clean up existing maps first // Clean up existing maps first
container.querySelectorAll(".school-map").forEach((mapEl) => { mapElements.forEach((mapEl) => {
const existingMap = schoolMaps.get(mapEl); const existingMap = schoolMaps.get(mapEl);
if (existingMap) { if (existingMap) {
existingMap.remove(); try {
existingMap.remove();
} catch (e) {
// Ignore cleanup errors
}
schoolMaps.delete(mapEl); schoolMaps.delete(mapEl);
} }
}); });
// Initialize new maps // Initialize new maps with a small delay to ensure DOM is ready
container.querySelectorAll(".school-map").forEach((mapEl) => { setTimeout(() => {
const lat = parseFloat(mapEl.dataset.lat); mapElements.forEach((mapEl) => {
const lng = parseFloat(mapEl.dataset.lng); try {
const schoolName = mapEl.dataset.name; // Skip if already initialized
if (schoolMaps.has(mapEl)) return;
if (isNaN(lat) || isNaN(lng)) return; const lat = parseFloat(mapEl.dataset.lat);
const lng = parseFloat(mapEl.dataset.lng);
const schoolName = mapEl.dataset.name;
// Create map if (isNaN(lat) || isNaN(lng)) return;
const map = L.map(mapEl, {
center: [lat, lng], // Ensure element has dimensions
zoom: 15, if (mapEl.offsetWidth === 0 || mapEl.offsetHeight === 0) {
zoomControl: false, console.warn("Map container has no dimensions, skipping");
attributionControl: false, return;
dragging: true, }
scrollWheelZoom: false,
// Create map
const map = L.map(mapEl, {
center: [lat, lng],
zoom: 15,
zoomControl: false,
attributionControl: false,
dragging: true,
scrollWheelZoom: false,
});
// Add tile layer (OpenStreetMap)
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
}).addTo(map);
// Add marker
const marker = L.marker([lat, lng]).addTo(map);
marker.bindTooltip(schoolName, { permanent: false, direction: "top" });
// Store map reference
schoolMaps.set(mapEl, map);
// Handle click to open fullscreen
mapEl.addEventListener("click", (e) => {
e.stopPropagation();
openMapModal(lat, lng, schoolName);
});
} catch (err) {
console.error("Error initializing map:", err);
}
}); });
}, 100);
// Add tile layer (OpenStreetMap)
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
}).addTo(map);
// Add marker
const marker = L.marker([lat, lng]).addTo(map);
marker.bindTooltip(schoolName, { permanent: false, direction: "top" });
// Store map reference
schoolMaps.set(mapEl, map);
// Handle click to open fullscreen
mapEl.addEventListener("click", (e) => {
e.stopPropagation();
openMapModal(lat, lng, schoolName);
});
});
} }
/** /**