Skip to content

Commit

Permalink
Added overlay removal by id
Browse files Browse the repository at this point in the history
  • Loading branch information
christof-wittreich committed Oct 16, 2023
1 parent aecfc3b commit d6e3a6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 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()]);
}
});
};
Expand Down Expand Up @@ -144,11 +144,16 @@ function EventTrack () {
}, [showAllTracks]);

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

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

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 d6e3a6a

Please sign in to comment.