completed Marker conflikt handler
This commit is contained in:
@@ -37,17 +37,14 @@ export const AircraftMarker = (props: any) => {
|
|||||||
);
|
);
|
||||||
const aircrafts = useAircraftsStore((state) => state.aircrafts);
|
const aircrafts = useAircraftsStore((state) => state.aircrafts);
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const [markersAdjusted, setMarkersAdjusted] = useState(false);
|
|
||||||
|
|
||||||
const getMarkerHTML = (
|
const getMarkerHTML = (
|
||||||
aircraft: Aircraft,
|
aircraft: Aircraft,
|
||||||
anchor: "topleft" | "topright" | "bottomleft" | "bottomright",
|
anchor: "topleft" | "topright" | "bottomleft" | "bottomright",
|
||||||
) => {
|
) => {
|
||||||
return `<div
|
return `<div
|
||||||
data-aircraft-id="${aircraft.id}"
|
|
||||||
id="aircraft-marker-${aircraft.id}"
|
|
||||||
class="${cn(
|
class="${cn(
|
||||||
"aircraft-marker relative w-[140px] transform flex items-center gap-2 px-2 z-100",
|
" relative w-[140px] transform flex items-center gap-2 px-2 z-100",
|
||||||
anchor.includes("right") && "-translate-x-full",
|
anchor.includes("right") && "-translate-x-full",
|
||||||
anchor.includes("bottom") && "-translate-y-full",
|
anchor.includes("bottom") && "-translate-y-full",
|
||||||
)}"
|
)}"
|
||||||
@@ -55,18 +52,18 @@ export const AircraftMarker = (props: any) => {
|
|||||||
background-color: ${FMS_STATUS_COLORS[aircraft.fmsStatus]};
|
background-color: ${FMS_STATUS_COLORS[aircraft.fmsStatus]};
|
||||||
${openAircraftMarker.includes(aircraft.id) ? "opacity: 0;" : ""}
|
${openAircraftMarker.includes(aircraft.id) ? "opacity: 0;" : ""}
|
||||||
">
|
">
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="${cn(
|
class="${cn(
|
||||||
"absolute w-4 h-4 z-99",
|
"absolute w-4 h-4 z-99",
|
||||||
anchor.includes("left") ? "-left-[2px]" : "-right-[2px]",
|
anchor.includes("left") ? "-left-[2px]" : "-right-[2px]",
|
||||||
anchor.includes("top") ? "-top-[2px]" : "-bottom-[2px]",
|
anchor.includes("top") ? "-top-[2px]" : "-bottom-[2px]",
|
||||||
)}"
|
)}"
|
||||||
style="
|
style="
|
||||||
${anchor.includes("left") ? `border-left: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};` : `border-right: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};`}
|
${anchor.includes("left") ? `border-left: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};` : `border-right: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};`}
|
||||||
${anchor.includes("top") ? `border-top: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};` : `border-bottom: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};`}
|
${anchor.includes("top") ? `border-top: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};` : `border-bottom: 3px solid ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};`}
|
||||||
|
"
|
||||||
">
|
></div>
|
||||||
</div>
|
|
||||||
<span
|
<span
|
||||||
class="font-semibold text-xl"
|
class="font-semibold text-xl"
|
||||||
style="color: ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};"
|
style="color: ${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]};"
|
||||||
@@ -76,6 +73,15 @@ export const AircraftMarker = (props: any) => {
|
|||||||
<span class="text-white text-[15px]">
|
<span class="text-white text-[15px]">
|
||||||
${aircraft.bosName}
|
${aircraft.bosName}
|
||||||
</span>
|
</span>
|
||||||
|
<div
|
||||||
|
data-aircraft-id="${aircraft.id}"
|
||||||
|
id="aircraft-marker-${aircraft.id}"
|
||||||
|
class="${cn(
|
||||||
|
"aircraft-marker absolute w-[200%] h-[200%] top-0 left-0 transform",
|
||||||
|
anchor.includes("left") && "-translate-x-1/2",
|
||||||
|
anchor.includes("top") && "-translate-y-1/2",
|
||||||
|
)}"
|
||||||
|
></div>
|
||||||
</div>`;
|
</div>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,29 +116,7 @@ export const AircraftMarker = (props: any) => {
|
|||||||
>("topleft");
|
>("topleft");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
/* const testRef = setInterval(() => {
|
|
||||||
positionMarker();
|
|
||||||
}, 1000); */
|
|
||||||
|
|
||||||
const handleZoom = () => {
|
const handleZoom = () => {
|
||||||
setAnchor("topleft");
|
|
||||||
setMarkersAdjusted(false);
|
|
||||||
};
|
|
||||||
map.on("zoom", handleZoom);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
map.off("zoom", handleZoom);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* return () => {
|
|
||||||
clearInterval(testRef);
|
|
||||||
}; */
|
|
||||||
}, [map]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (markersAdjusted) return;
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
console.log(`Iteration ${i}`);
|
|
||||||
const otherMarkers = document.querySelectorAll(".aircraft-marker");
|
const otherMarkers = document.querySelectorAll(".aircraft-marker");
|
||||||
// get markers and check if they are overlapping
|
// get markers and check if they are overlapping
|
||||||
const ownMarker = document.querySelector(
|
const ownMarker = document.querySelector(
|
||||||
@@ -141,7 +125,7 @@ export const AircraftMarker = (props: any) => {
|
|||||||
|
|
||||||
if (!otherMarkers || !ownMarker) return;
|
if (!otherMarkers || !ownMarker) return;
|
||||||
|
|
||||||
const overlappingMarkers = Array.from(otherMarkers).filter((marker) => {
|
const marksersInCluster = Array.from(otherMarkers).filter((marker) => {
|
||||||
// if (marker.id === `aircraft-marker-${aircraft.id}`) return false;
|
// if (marker.id === `aircraft-marker-${aircraft.id}`) return false;
|
||||||
const rect1 = (marker as HTMLElement).getBoundingClientRect();
|
const rect1 = (marker as HTMLElement).getBoundingClientRect();
|
||||||
const rect2 = (ownMarker as HTMLElement).getBoundingClientRect();
|
const rect2 = (ownMarker as HTMLElement).getBoundingClientRect();
|
||||||
@@ -154,7 +138,7 @@ export const AircraftMarker = (props: any) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
// get the center of all overlapping markers
|
// get the center of all overlapping markers
|
||||||
const markersPosition = overlappingMarkers.map((marker) => {
|
const markersPosition = marksersInCluster.map((marker) => {
|
||||||
const rect = (marker as HTMLElement).getBoundingClientRect();
|
const rect = (marker as HTMLElement).getBoundingClientRect();
|
||||||
return {
|
return {
|
||||||
x: rect.left + rect.width / 2,
|
x: rect.left + rect.width / 2,
|
||||||
@@ -182,13 +166,8 @@ export const AircraftMarker = (props: any) => {
|
|||||||
y: 0,
|
y: 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
console.log(
|
if (marksersInCluster.length > 1) {
|
||||||
"overlapping markers",
|
if (centerOfOverlappingMarkers.y < ownMarkerPosition.y) {
|
||||||
centerOfOverlappingMarkers,
|
|
||||||
ownMarkerPosition,
|
|
||||||
);
|
|
||||||
if (overlappingMarkers.length >= 1) {
|
|
||||||
if (centerOfOverlappingMarkers.y > ownMarkerPosition.y) {
|
|
||||||
if (centerOfOverlappingMarkers.x > ownMarkerPosition.x) {
|
if (centerOfOverlappingMarkers.x > ownMarkerPosition.x) {
|
||||||
setAnchor("topright");
|
setAnchor("topright");
|
||||||
} else {
|
} else {
|
||||||
@@ -201,14 +180,17 @@ export const AircraftMarker = (props: any) => {
|
|||||||
setAnchor("bottomleft");
|
setAnchor("bottomleft");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Default
|
||||||
|
setAnchor("topleft");
|
||||||
}
|
}
|
||||||
// TODO: Once markers are readjusted they dont overlap to these they did in the first iteration, but when all markers are adjusted they overlap whit ones they didnt in the first interation
|
};
|
||||||
}
|
map.on("zoom", handleZoom);
|
||||||
setMarkersAdjusted(true);
|
|
||||||
}, [setAnchor, setMarkersAdjusted, aircraft.id, markersAdjusted]);
|
|
||||||
|
|
||||||
// EG. if 3 markers are overlapping and they are left and right
|
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
map.off("zoom", handleZoom);
|
||||||
|
};
|
||||||
|
}, [map]);
|
||||||
return (
|
return (
|
||||||
<Fragment key={aircraft.id}>
|
<Fragment key={aircraft.id}>
|
||||||
<Marker
|
<Marker
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user