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
This commit is contained in:
Graham McIntire 2025-08-05 13:43:46 -05:00
parent db456f84a6
commit 537ddec4d6
No known key found for this signature in database

View file

@ -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) => {