From 899d2a7b0099a447e4fed78e5187492a873d2162 Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Mon, 9 Jun 2025 15:19:26 +0100 Subject: [PATCH] Updated home.blade.php and HomeController with latest changes 11 --- public/js/customMap.js | 79 +++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/public/js/customMap.js b/public/js/customMap.js index f1486d385..eaa5eb3d8 100644 --- a/public/js/customMap.js +++ b/public/js/customMap.js @@ -1,6 +1,8 @@ L.custom = { init: function (obj, params) { + console.log('πŸš€ Initializing custom map...'); + window.map = L.map(obj, { center: [48, 4], zoom: 4, @@ -17,13 +19,35 @@ L.custom = { console.log('πŸ”₯ Full API response:', data); - // SAFELY get the correct countries object + // Detect correct format var countryData = Array.isArray(data) && data.length > 1 ? data[1] : data; - console.log('βœ… Using countryData:', countryData); + console.log('🌍 Detected countries:', Object.keys(countryData)); + + // Marker click + var markerOnClick = function (e) { + var id = e.target.options.id; + $.ajax({ + dataType: "json", + url: "api/event/detail?id=" + id, + success: function (res) { + var event = res.data; + + var content = '

' + event.title + '

' + + '' + + '

' + event.description + '

'; + + var popup = L.popup({ maxWidth: 600 }) + .setContent(content) + + e.target.bindPopup(popup).openPopup(); + } + }); + } // Clear old layers if (markersCountryLayers.length > 0) { + console.log(`♻️ Clearing ${markersCountryLayers.length} old marker layers...`); $.each(markersCountryLayers, function (key, countryLayer) { countryLayer.clearLayers(); map.removeLayer(countryLayer); @@ -31,41 +55,40 @@ L.custom = { markersCountryLayers = []; } - // NEW: Build master cluster + // Build single master cluster var allMarkers = []; + var totalEvents = 0; + var missingGeo = 0; + + $.each(countryData, function (countryCode, countryEvents) { + console.log(`β†’ Processing country: ${countryCode} with ${countryEvents.length} events`); + totalEvents += countryEvents.length; - $.each(countryData, function (countryIso, events) { - $.each(events, function (idx, event) { - if (event.geoposition) { - var coordinates = event.geoposition.split(','); + $.each(countryEvents, function (idx, val) { + if (val.geoposition) { + var coordinates = val.geoposition.split(','); var lat = parseFloat(coordinates[0]); var lng = parseFloat(coordinates[1]); if (!isNaN(lat) && !isNaN(lng)) { - var marker = L.marker(L.latLng(lat, lng), { id: event.id }); - marker.on('click', function (e) { - var id = e.target.options.id; - $.ajax({ - dataType: "json", - url: "api/event/detail?id=" + id, - success: function (res) { - var ev = res.data; - var content = '

' + ev.title + '

' + - '
' + - '' + - '

' + ev.description + '

'; - - var popup = L.popup({ maxWidth: 600 }).setContent(content); - e.target.bindPopup(popup).openPopup(); - } - }); - }); + var marker = L.marker(L.latLng(lat, lng), { id: val.id }); + marker.on('click', markerOnClick); allMarkers.push(marker); + } else { + console.warn(`⚠️ Invalid geoposition for event ID ${val.id} in ${countryCode}:`, val.geoposition); + missingGeo++; } + } else { + console.warn(`⚠️ Missing geoposition for event ID ${val.id} in ${countryCode}`); + missingGeo++; } }); }); + console.log(`βœ… Total events processed: ${totalEvents}`); + console.log(`βœ… Total valid markers: ${allMarkers.length}`); + console.log(`⚠️ Total events missing/invalid geoposition: ${missingGeo}`); + var masterCluster = L.markerClusterGroup({ showCoverageOnHover: false, maxClusterRadius: 120, @@ -98,8 +121,8 @@ L.custom = { markersCountryLayers.push(masterCluster); map.addLayer(masterCluster); - console.log('βœ… Markers added:', allMarkers.length); - + console.log('πŸ—ΊοΈ Master cluster added to map.'); + console.log('➑️ Triggering next components...'); $wt._queue("next"); }; @@ -112,6 +135,7 @@ L.custom = { } function getEvents(year) { + console.log(`πŸ“‘ Fetching events for year: ${year}...`); $.ajax({ dataType: "json", url: "api/event/list?year=" + year, @@ -120,6 +144,7 @@ L.custom = { } var year = param('year') ? param('year') : new Date().getFullYear(); + console.log(`🎯 Initial map year = ${year}`); getEvents(year); } };