From 32259770a1a721432a0ddcdd985c81cd6ef7f4b6 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 12 Aug 2025 22:31:14 +0100 Subject: [PATCH] Add callsign label clearing to map updates Introduced clearCallsignLabels() to remove callsign labels when map data is refreshed or markers are removed. Ensures label state is reset and UI button appearance is updated, preventing stale labels from persisting after data changes. --- application/views/map/custom_date.php | 33 +++++++++++++++++++++++---- assets/js/leaflet/leafembed.js | 5 ++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/application/views/map/custom_date.php b/application/views/map/custom_date.php index 65794ec2..69636328 100644 --- a/application/views/map/custom_date.php +++ b/application/views/map/custom_date.php @@ -433,6 +433,28 @@ function toggleFullscreen() { let callsignLabelsVisible = false; let callsignLabels = []; +function clearCallsignLabels() { + // Remove all existing callsign labels from the map + callsignLabels.forEach(function(labelMarker) { + if (map.hasLayer(labelMarker)) { + map.removeLayer(labelMarker); + } + }); + + // Clear the labels array + callsignLabels = []; + + // Reset the visibility state + callsignLabelsVisible = false; + + // Reset button appearance + const button = document.getElementById('callsign-labels-btn'); + if (button) { + button.classList.remove('btn-success'); + button.classList.add('btn-outline-success'); + } +} + function toggleCallsignLabels() { const button = document.getElementById('callsign-labels-btn'); @@ -518,11 +540,14 @@ function updateMapStatistics(plotjson) { }, 3000); } + // Handle callsign labels when new data is loaded + const labelsWereVisible = callsignLabelsVisible; + + // Clear any existing callsign labels before processing new data + clearCallsignLabels(); + // Reapply callsign labels if they were previously enabled - if (callsignLabelsVisible) { - // Reset state and toggle to reapply labels to new markers - callsignLabelsVisible = false; - callsignLabels = []; + if (labelsWereVisible) { setTimeout(() => { toggleCallsignLabels(); }, 100); // Small delay to ensure markers are fully rendered diff --git a/assets/js/leaflet/leafembed.js b/assets/js/leaflet/leafembed.js index 432c6e39..5c57e689 100644 --- a/assets/js/leaflet/leafembed.js +++ b/assets/js/leaflet/leafembed.js @@ -124,4 +124,9 @@ function removeMarkers() { map.removeLayer(plotlayers[i]); } plotlayers=[]; + + // Clear callsign labels if the function exists (for custom map page) + if (typeof clearCallsignLabels === 'function') { + clearCallsignLabels(); + } } \ No newline at end of file