Skip to content

Commit

Permalink
Added createOverlayMapping function
Browse files Browse the repository at this point in the history
  • Loading branch information
christof-wittreich committed Oct 16, 2023
1 parent dcbf658 commit 4bbd453
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions web/js/map/natural-events/event-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,17 @@ function EventTrack () {
showAllTracksRef.current = showAllTracks;
}, [showAllTracks]);

const removeAllTracks = (mapArg) => {
const createOverlayMapping = (mapArg) => {
const overlayMapping = {};
mapArg?.getOverlays().forEach((overlay) => {
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;
Expand All @@ -159,9 +164,10 @@ function EventTrack () {

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 @@ -331,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

0 comments on commit 4bbd453

Please sign in to comment.