From 537ddec4d6ba9cc08702fd6d149ac8fbcf371259 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 5 Aug 2025 13:43:46 -0500 Subject: [PATCH] fix: improve RF path line cleanup to prevent persistent lines - Add clearRfPathLines() method for centralized cleanup logic - Clear RF paths when clearing all markers - Clear RF paths in destroyed() lifecycle hook - Add error handling to prevent failures during cleanup - Fix issue where path lines could persist after hover ends --- assets/js/map.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/assets/js/map.ts b/assets/js/map.ts index 34e1065..71b7dd4 100644 --- a/assets/js/map.ts +++ b/assets/js/map.ts @@ -1214,14 +1214,7 @@ let MapAPRSMap = { // Handle clearing RF path lines self.handleEvent("clear_rf_path", () => { - if (self.rfPathLines) { - self.rfPathLines.forEach((line) => { - if (self.map && self.map.hasLayer(line)) { - self.map.removeLayer(line); - } - }); - self.rfPathLines = []; - } + self.clearRfPathLines(); }); // Handle bounds-based marker filtering @@ -1651,6 +1644,9 @@ let MapAPRSMap = { clearAllMarkers() { const self = this as unknown as LiveViewHookContext; + + // Clear any RF path lines first + self.clearRfPathLines(); // Instead of clearing all markers, only remove non-historical and non-current markers const markersToPreserve = new Map(); @@ -1743,6 +1739,22 @@ let MapAPRSMap = { markersToRemove.forEach((id) => self.removeMarkerWithoutTrail(String(id))); }, + clearRfPathLines() { + const self = this as unknown as LiveViewHookContext; + if (self.rfPathLines && self.rfPathLines.length > 0) { + self.rfPathLines.forEach((line) => { + try { + if (self.map && self.map.hasLayer(line)) { + self.map.removeLayer(line); + } + } catch (e) { + console.debug("Error removing RF path line:", e); + } + }); + self.rfPathLines = []; + } + }, + removeMarkerWithoutTrail(id: string) { const self = this as unknown as LiveViewHookContext; // Ensure id is a string @@ -1935,6 +1947,9 @@ let MapAPRSMap = { self.mapEventHandlers.clear(); } + // Clear any RF path lines + self.clearRfPathLines(); + // Remove all event listeners from markers before clearing layers if (self.markers !== undefined) { self.markers.forEach((marker: APRSMarker) => {