Skip to content

Commit

Permalink
WV-2913: Multiple Tracks Incorrectly Highlighted Simultaneously (#4736)
Browse files Browse the repository at this point in the history
* Added overlay removal by id

* Fixed failing test

* Added createOverlayMapping function
  • Loading branch information
christof-wittreich authored Oct 17, 2023
1 parent 7bc6c6d commit a0557e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions web/js/map/natural-events/event-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
getTrackLines, getTrackPoint, getArrows, getClusterPointEl,
} from './util';

const removePointOverlays = (map, pointsAndArrows) => {
const removePointOverlays = (map, pointsAndArrows, overlayMapping) => {
lodashEach(pointsAndArrows, (pointOverlay) => {
if (map.getOverlayById(pointOverlay.getId())) {
map.removeOverlay(pointOverlay);
map.removeOverlay(overlayMapping[pointOverlay.getId()] || pointsAndArrows);
}
});
};
Expand Down Expand Up @@ -143,20 +143,31 @@ function EventTrack () {
showAllTracksRef.current = showAllTracks;
}, [showAllTracks]);

const createOverlayMapping = (mapArg) => {
const overlayMapping = {};
mapArg.getOverlays().forEach((overlay) => {
overlayMapping[overlay.getId()] = overlay;
});
return overlayMapping;
};

const removeAllTracks = (mapArg) => {
if (!mapArg) return;
const overlayMapping = createOverlayMapping(mapArg);
allTrackDetailsRef.current?.forEach((trackDetail) => {
const { pointsAndArrows } = trackDetail.newTrackDetails;
const { track } = trackDetail.newTrackDetails;
mapArg.removeOverlay(track);
removePointOverlays(mapArg, pointsAndArrows);
mapArg.removeOverlay(overlayMapping[track.id] || track);
removePointOverlays(mapArg, pointsAndArrows, overlayMapping);
});
};

const removeTrack = (mapArg) => {
if (!mapArg) return;
const overlayMapping = createOverlayMapping(mapArg);
const { track, pointsAndArrows } = trackDetailsRef.current;
mapArg.removeOverlay(track);
removePointOverlays(mapArg, pointsAndArrows);
mapArg.removeOverlay(overlayMapping[track?.id] || track);
removePointOverlays(mapArg, pointsAndArrows, overlayMapping);

return {};
};
Expand Down Expand Up @@ -326,7 +337,7 @@ function EventTrack () {
if (prevMap) {
update(null);
removeTrack(prevMap);
removePointOverlays(prevMap, trackDetailsRef.current.pointsAndArrows);
removePointOverlays(prevMap, trackDetailsRef.current.pointsAndArrows, createOverlayMapping(prevMap));
if (showAllTracksRef.current) {
removeAllTracks(prevMap);
}
Expand Down
2 changes: 1 addition & 1 deletion web/js/map/natural-events/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const getTrackLines = function(map, trackCoords, eventID, date, callback,
insertFirst: true,
stopEvent: false,
element: svgEl,
id: 'event-track',
id: `event-track-${eventID}`,
});
};

Expand Down

0 comments on commit a0557e6

Please sign in to comment.