From 53e837cbc8c20c3dd1c635bf133edbe3b4afba40 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Tue, 29 Apr 2025 13:57:48 -0700 Subject: [PATCH] Fixed Marker collision --- apps/dispatch/app/_components/SmartPopup.tsx | 22 ++++++++----------- .../_components/map/AircraftMarker.tsx | 3 +++ .../_components/map/MissionMarkers.tsx | 3 +++ .../map/_components/MarkerCluster.tsx | 4 +++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/apps/dispatch/app/_components/SmartPopup.tsx b/apps/dispatch/app/_components/SmartPopup.tsx index 3ff5b0dc..068f3077 100644 --- a/apps/dispatch/app/_components/SmartPopup.tsx +++ b/apps/dispatch/app/_components/SmartPopup.tsx @@ -24,7 +24,7 @@ export const useSmartPopup = () => { export const calculateAnchor = ( id: string, mode: "popup" | "marker", - ignoreMarker?: boolean, + options?: { ignoreMarker?: boolean; ignoreCluster?: boolean }, ) => { const otherMarkers = document.querySelectorAll(".map-collision"); // get markers and check if they are overlapping @@ -37,7 +37,8 @@ export const calculateAnchor = ( const marksersInCluster = Array.from(otherMarkers).filter((marker) => { if (mode === "popup" && marker.id === `marker-${id}`) return false; - if (ignoreMarker && marker.id.startsWith("marker")) return false; + if (options?.ignoreMarker && marker.id.startsWith("marker")) return false; + if (options?.ignoreCluster && marker.id.startsWith("cluster")) return false; const rect1 = (marker as HTMLElement).getBoundingClientRect(); const rect2 = (ownMarker as HTMLElement).getBoundingClientRect(); @@ -76,12 +77,6 @@ export const calculateAnchor = ( centerOfOverlappingMarkers.x /= markersPosition.length; centerOfOverlappingMarkers.y /= markersPosition.length; - if (id == "2") { - console.log("markersInCluser", marksersInCluster); - console.log("ownMarkerPosition", ownMarkerPosition); - console.log("centerOfOverlappingMarkers", centerOfOverlappingMarkers); - } - if (marksersInCluster.length > 1) { if (centerOfOverlappingMarkers.y < ownMarkerPosition.y) { if (centerOfOverlappingMarkers.x > ownMarkerPosition.x) { @@ -107,24 +102,25 @@ export interface SmartPopupRef { } export const SmartPopup = ( - props: PopupProps & { ignoreMarker?: boolean } & RefAttributes & { + props: PopupProps & { + options?: { ignoreMarker?: boolean; ignoreCluster?: boolean }; + } & RefAttributes & { smartPopupRef?: Ref; id: string; wrapperClassName?: string; }, ) => { const [showContent, setShowContent] = useState(false); - const { smartPopupRef, id, className, wrapperClassName, ignoreMarker } = - props; + const { smartPopupRef, id, className, wrapperClassName, options } = props; const [anchor, setAnchor] = useState< "topleft" | "topright" | "bottomleft" | "bottomright" >("topleft"); const handleConflict = useCallback(() => { - const newAnchor = calculateAnchor(id, "popup", ignoreMarker); + const newAnchor = calculateAnchor(id, "popup", options); setAnchor(newAnchor); - }, [id, ignoreMarker]); + }, [id, options]); useImperativeHandle(smartPopupRef, () => ({ handleConflict, diff --git a/apps/dispatch/app/dispatch/_components/map/AircraftMarker.tsx b/apps/dispatch/app/dispatch/_components/map/AircraftMarker.tsx index e29a3b26..89cb72e1 100644 --- a/apps/dispatch/app/dispatch/_components/map/AircraftMarker.tsx +++ b/apps/dispatch/app/dispatch/_components/map/AircraftMarker.tsx @@ -356,6 +356,9 @@ const AircraftMarker = ({ aircraft }: { aircraft: Aircraft }) => { /> {openAircraftMarker.some((m) => m.id === aircraft.id) && !hideMarker && ( { /> {openMissionMarker.some((m) => m.id === mission.id) && !hideMarker && ( { <> {cluster.map((c, i) => (