bug fix
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
This commit is contained in:
@@ -610,23 +610,47 @@ 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) {
|
||||||
|
try {
|
||||||
existingMap.remove();
|
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(() => {
|
||||||
|
mapElements.forEach((mapEl) => {
|
||||||
|
try {
|
||||||
|
// Skip if already initialized
|
||||||
|
if (schoolMaps.has(mapEl)) return;
|
||||||
|
|
||||||
const lat = parseFloat(mapEl.dataset.lat);
|
const lat = parseFloat(mapEl.dataset.lat);
|
||||||
const lng = parseFloat(mapEl.dataset.lng);
|
const lng = parseFloat(mapEl.dataset.lng);
|
||||||
const schoolName = mapEl.dataset.name;
|
const schoolName = mapEl.dataset.name;
|
||||||
|
|
||||||
if (isNaN(lat) || isNaN(lng)) return;
|
if (isNaN(lat) || isNaN(lng)) return;
|
||||||
|
|
||||||
|
// Ensure element has dimensions
|
||||||
|
if (mapEl.offsetWidth === 0 || mapEl.offsetHeight === 0) {
|
||||||
|
console.warn("Map container has no dimensions, skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create map
|
// Create map
|
||||||
const map = L.map(mapEl, {
|
const map = L.map(mapEl, {
|
||||||
center: [lat, lng],
|
center: [lat, lng],
|
||||||
@@ -654,7 +678,11 @@ function initializeSchoolMaps(container) {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
openMapModal(lat, lng, schoolName);
|
openMapModal(lat, lng, schoolName);
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error initializing map:", err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user