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.
这个提交包含在:
Peter Goodhall 2025-08-12 22:31:14 +01:00
父节点 7fe4e7e663
当前提交 32259770a1
共有 2 个文件被更改,包括 34 次插入4 次删除

查看文件

@ -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

查看文件

@ -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();
}
}