Skip to content

Commit

Permalink
WV-2913: Multiple Tracks Incorrectly Highlighted Simultaneously FIX (#…
Browse files Browse the repository at this point in the history
…4739)

* Added overlay removal by id

* Fixed failing test

* Added createOverlayMapping function

* Added support for multiple tracks of the same id

* Consolidated track removal into reusable function

* Fixed linting issue
  • Loading branch information
christof-wittreich authored Oct 19, 2023
1 parent a58c558 commit 4d3b7aa
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions web/js/map/natural-events/event-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import {
const removePointOverlays = (map, pointsAndArrows, overlayMapping) => {
lodashEach(pointsAndArrows, (pointOverlay) => {
if (map.getOverlayById(pointOverlay.getId())) {
map.removeOverlay(overlayMapping[pointOverlay.getId()] || pointsAndArrows);
if (overlayMapping[pointOverlay.getId()]) {
overlayMapping[pointOverlay.getId()].forEach((subPointsAndArrows) => {
map.removeOverlay(subPointsAndArrows);
});
} else {
map.removeOverlay(pointsAndArrows);
}
}
});
};
Expand Down Expand Up @@ -146,18 +152,33 @@ function EventTrack () {
const createOverlayMapping = (mapArg) => {
const overlayMapping = {};
mapArg.getOverlays().forEach((overlay) => {
overlayMapping[overlay.getId()] = overlay;
if (!overlay.getId()) return;
if (!overlayMapping[overlay.getId()]) {
overlayMapping[overlay.getId()] = [];
}
overlayMapping[overlay.getId()].push(overlay);
});
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;
mapArg.removeOverlay(overlayMapping[track.id] || track);
removeTrackById(mapArg, overlayMapping, track);
removePointOverlays(mapArg, pointsAndArrows, overlayMapping);
});
};
Expand All @@ -166,7 +187,7 @@ function EventTrack () {
if (!mapArg) return;
const overlayMapping = createOverlayMapping(mapArg);
const { track, pointsAndArrows } = trackDetailsRef.current;
mapArg.removeOverlay(overlayMapping[track?.id] || track);
removeTrackById(mapArg, overlayMapping, track);
removePointOverlays(mapArg, pointsAndArrows, overlayMapping);

return {};
Expand Down

0 comments on commit 4d3b7aa

Please sign in to comment.