Skip to content

Commit

Permalink
Consolidated track removal into reusable function
Browse files Browse the repository at this point in the history
  • Loading branch information
christof-wittreich committed Oct 18, 2023
1 parent faec5dd commit 74dec81
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions web/js/map/natural-events/event-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,24 @@ function EventTrack () {
return overlayMapping;
};

const removeTrackById = (mapArg, overlayMapping, track) => {
const id = track?.id;
if (overlayMapping[id]) {
overlayMapping[id].forEach((subTrack) => {
mapArg.removeOverlay(subTrack);
});
} else {
mapArg.removeOverlay(track);
}
};

const removeAllTracks = (mapArg) => {
if (!mapArg) return;
const overlayMapping = createOverlayMapping(mapArg);
allTrackDetailsRef.current?.forEach((trackDetail) => {
const { pointsAndArrows } = trackDetail.newTrackDetails;
const { track } = trackDetail.newTrackDetails;
if (overlayMapping[track.id]) {
overlayMapping[track.id].forEach((subTrack) => {
mapArg.removeOverlay(subTrack);
});
} else {
mapArg.removeOverlay(track);
}
removeTrackById(mapArg, overlayMapping, track);
removePointOverlays(mapArg, pointsAndArrows, overlayMapping);
});
};
Expand All @@ -182,13 +187,7 @@ function EventTrack () {
if (!mapArg) return;
const overlayMapping = createOverlayMapping(mapArg);
const { track, pointsAndArrows } = trackDetailsRef.current;
if (overlayMapping[track?.id]) {
overlayMapping[track.id].forEach((subTrack) => {
mapArg.removeOverlay(subTrack);
});
} else {
mapArg.removeOverlay(track);
}
removeTrackById(mapArg, overlayMapping, track);
removePointOverlays(mapArg, pointsAndArrows, overlayMapping);

return {};
Expand Down

0 comments on commit 74dec81

Please sign in to comment.