' +
+ '

' +
+ '
' + event.description + '
';
- // Clear previous layers if needed
- if (markersCountryLayers.length > 0) {
- $.each(markersCountryLayers, function (key, layer) {
- layer.clearLayers();
- map.removeLayer(layer);
- });
- markersCountryLayers = [];
- }
+ var popup = L.popup({ maxWidth: 600 })
+ .setContent(content);
- // Create ONE global cluster group
- var allMarkersClusterGroup = L.markerClusterGroup({
- showCoverageOnHover: false,
- maxClusterRadius: 120,
- chunkedLoading: true,
- iconCreateFunction: function (cluster) {
- var total = cluster.getAllChildMarkers().length;
- var iconSize;
- var className = "mycluster ";
- if (total <= 10) {
- iconSize = L.point(30, 30);
- className += "size1";
- } else if (total <= 100) {
- iconSize = L.point(35, 35);
- className += "size2";
- } else if (total <= 1000) {
- iconSize = L.point(40, 40);
- className += "size3";
- } else if (total <= 10000) {
- iconSize = L.point(45, 45);
- className += "size4";
- } else {
- iconSize = L.point(50, 50);
- className += "size5";
- }
- return L.divIcon({ html: '
' + total + '
', className: className, iconSize: iconSize });
+ e.target.bindPopup(popup).openPopup();
}
});
+ };
+
+ // Success callback
+ var success = function (data) {
+
+ // Clear existing markers first
+ globalMarkersGroup.clearLayers();
- // Add ALL markers to ONE cluster group
- $.each(data, function (key, country) {
- $.each(country, function (key, val) {
+ // Loop over countries and events
+ $.each(data, function (countryCode, countryEvents) {
+ $.each(countryEvents, function (key, val) {
var coordinates = val.geoposition.split(',');
- var marker = L.marker(L.latLng(coordinates[0], coordinates[1]), { id: val.id });
+ var marker = L.marker(L.latLng(coordinates[0], coordinates[1]), {
+ id: val.id,
+ country: countryCode // store country on marker for filtering
+ });
marker.on('click', markerOnClick);
- allMarkersClusterGroup.addLayer(marker);
+ globalMarkersGroup.addLayer(marker);
});
});
- // Add the global cluster group to the map
- map.addLayer(allMarkersClusterGroup);
-
- // Save reference
- markersCountryLayers.push(allMarkersClusterGroup);
-
- // process next components
+ // Process next components
$wt._queue("next");
- }
+ };
+
+ // Country filter
+ $('#id_country').on('change', function () {
+ var selectedCountry = this.value;
+
+ // Loop through all markers and toggle visibility
+ globalMarkersGroup.eachLayer(function (marker) {
+ if (!selectedCountry || selectedCountry === '') {
+ marker.setOpacity(1); // Show all
+ } else if (marker.options.country === selectedCountry) {
+ marker.setOpacity(1); // Show matching
+ } else {
+ marker.setOpacity(0); // Hide others
+ }
+ });
+ });
+ // Year filter
$('#id_year').on('change', function () {
getEvents(this.value);
});
+ // Get URL param
function param(name) {
return (location.search.split(name + '=')[1] || '').split('&')[0];
}
+ // AJAX fetch events
function getEvents(year) {
$.ajax({
dataType: "json",
@@ -109,7 +120,8 @@ L.custom = {
});
}
- var year = param('year') ? param('year') : 2019;
+ // Initial load
+ var year = param('year') ? param('year') : new Date().getFullYear();
getEvents(year);
}
-}
+};