added onClick events for marker-cluster #4
@@ -26,6 +26,7 @@ export const calculateAnchor = (
|
|||||||
mode: "popup" | "marker",
|
mode: "popup" | "marker",
|
||||||
options?: { ignoreMarker?: boolean; ignoreCluster?: boolean },
|
options?: { ignoreMarker?: boolean; ignoreCluster?: boolean },
|
||||||
) => {
|
) => {
|
||||||
|
console.log("calculateAnchor", id, mode, options);
|
||||||
const otherMarkers = document.querySelectorAll(".map-collision");
|
const otherMarkers = document.querySelectorAll(".map-collision");
|
||||||
// get markers and check if they are overlapping
|
// get markers and check if they are overlapping
|
||||||
const ownMarker =
|
const ownMarker =
|
||||||
@@ -36,9 +37,9 @@ export const calculateAnchor = (
|
|||||||
if (!otherMarkers || !ownMarker) return "topleft";
|
if (!otherMarkers || !ownMarker) return "topleft";
|
||||||
|
|
||||||
const marksersInCluster = Array.from(otherMarkers).filter((marker) => {
|
const marksersInCluster = Array.from(otherMarkers).filter((marker) => {
|
||||||
if (mode === "popup" && marker.id === `marker-${id}`) return false;
|
if (mode === "popup" && marker.id === `marker-domain-${id}`) return false;
|
||||||
if (options?.ignoreMarker && marker.id.startsWith("marker")) return false;
|
if (options?.ignoreMarker && marker.id.includes("marker")) return false;
|
||||||
if (options?.ignoreCluster && marker.id.startsWith("cluster")) return false;
|
if (options?.ignoreCluster && marker.id.includes("cluster")) 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();
|
||||||
@@ -51,6 +52,8 @@ export const calculateAnchor = (
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (id.includes("13")) console.log(ownMarker, marksersInCluster);
|
||||||
|
|
||||||
// get the center of all overlapping markers
|
// get the center of all overlapping markers
|
||||||
const markersPosition = marksersInCluster.map((marker) => {
|
const markersPosition = marksersInCluster.map((marker) => {
|
||||||
const rect = (marker as HTMLElement).getBoundingClientRect();
|
const rect = (marker as HTMLElement).getBoundingClientRect();
|
||||||
@@ -102,9 +105,9 @@ export interface SmartPopupRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SmartPopup = (
|
export const SmartPopup = (
|
||||||
props: PopupProps & {
|
props: PopupProps &
|
||||||
options?: { ignoreMarker?: boolean; ignoreCluster?: boolean };
|
RefAttributes<LPopup> & {
|
||||||
} & RefAttributes<LPopup> & {
|
options?: { ignoreMarker?: boolean; ignoreCluster?: boolean };
|
||||||
smartPopupRef?: Ref<SmartPopupRef>;
|
smartPopupRef?: Ref<SmartPopupRef>;
|
||||||
id: string;
|
id: string;
|
||||||
wrapperClassName?: string;
|
wrapperClassName?: string;
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ const AircraftMarker = ({ aircraft }: { aircraft: Aircraft }) => {
|
|||||||
>("topleft");
|
>("topleft");
|
||||||
|
|
||||||
const handleConflict = useCallback(() => {
|
const handleConflict = useCallback(() => {
|
||||||
const newAnchor = calculateAnchor(aircraft.id, "marker");
|
const newAnchor = calculateAnchor(`aircraft-${aircraft.id}`, "marker");
|
||||||
setAnchor(newAnchor);
|
setAnchor(newAnchor);
|
||||||
}, [aircraft.id]);
|
}, [aircraft.id]);
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ const AircraftMarker = ({ aircraft }: { aircraft: Aircraft }) => {
|
|||||||
anchor: "topleft" | "topright" | "bottomleft" | "bottomright",
|
anchor: "topleft" | "topright" | "bottomleft" | "bottomright",
|
||||||
) => {
|
) => {
|
||||||
return `<div
|
return `<div
|
||||||
id="marker-${aircraft.id}"
|
id="marker-aircraft-${aircraft.id}"
|
||||||
class="${cn(
|
class="${cn(
|
||||||
"relative w-auto transform inline-flex items-center gap-2 px-2 z-100",
|
"relative w-auto transform inline-flex items-center gap-2 px-2 z-100",
|
||||||
anchor.includes("right") && "-translate-x-full",
|
anchor.includes("right") && "-translate-x-full",
|
||||||
@@ -332,7 +332,7 @@ const AircraftMarker = ({ aircraft }: { aircraft: Aircraft }) => {
|
|||||||
data-id="${aircraft.id}"
|
data-id="${aircraft.id}"
|
||||||
data-anchor-lat="${aircraft.location.lat}"
|
data-anchor-lat="${aircraft.location.lat}"
|
||||||
data-anchor-lng="${aircraft.location.lng}"
|
data-anchor-lng="${aircraft.location.lng}"
|
||||||
id="marker-domain-${aircraft.id}"
|
id="marker-domain-aircraft-${aircraft.id}"
|
||||||
class="${cn(
|
class="${cn(
|
||||||
"map-collision absolute w-[200%] h-[200%] top-0 left-0 transform pointer-events-none",
|
"map-collision absolute w-[200%] h-[200%] top-0 left-0 transform pointer-events-none",
|
||||||
anchor.includes("left") && "-translate-x-1/2",
|
anchor.includes("left") && "-translate-x-1/2",
|
||||||
|
|||||||
@@ -258,7 +258,10 @@ const MissionMarker = ({ mission }: { mission: Mission }) => {
|
|||||||
>("topleft");
|
>("topleft");
|
||||||
|
|
||||||
const handleConflict = useCallback(() => {
|
const handleConflict = useCallback(() => {
|
||||||
const newAnchor = calculateAnchor(mission.id.toString(), "marker");
|
const newAnchor = calculateAnchor(
|
||||||
|
`mission-${mission.id.toString()}`,
|
||||||
|
"marker",
|
||||||
|
);
|
||||||
setAnchor(newAnchor);
|
setAnchor(newAnchor);
|
||||||
}, [mission.id]);
|
}, [mission.id]);
|
||||||
|
|
||||||
@@ -288,7 +291,7 @@ const MissionMarker = ({ mission }: { mission: Mission }) => {
|
|||||||
anchor: "topleft" | "topright" | "bottomleft" | "bottomright",
|
anchor: "topleft" | "topright" | "bottomleft" | "bottomright",
|
||||||
) => {
|
) => {
|
||||||
return `<div
|
return `<div
|
||||||
id="marker-${mission.id}"
|
id="marker-mission-${mission.id}"
|
||||||
class="${cn(
|
class="${cn(
|
||||||
"relative w-auto transform inline-flex items-center gap-2 px-2 z-100",
|
"relative w-auto transform inline-flex items-center gap-2 px-2 z-100",
|
||||||
anchor.includes("right") && "-translate-x-full",
|
anchor.includes("right") && "-translate-x-full",
|
||||||
@@ -318,7 +321,7 @@ const MissionMarker = ({ mission }: { mission: Mission }) => {
|
|||||||
data-anchor-lat="${mission.addressLat}"
|
data-anchor-lat="${mission.addressLat}"
|
||||||
data-anchor-lng="${mission.addressLng}"
|
data-anchor-lng="${mission.addressLng}"
|
||||||
data-id="${mission.id}"
|
data-id="${mission.id}"
|
||||||
id="marker-domain-${mission.id}"
|
id="marker-domain-mission-${mission.id}"
|
||||||
class="${cn(
|
class="${cn(
|
||||||
"map-collision absolute w-[200%] h-[200%] top-0 left-0 transform pointer-events-none",
|
"map-collision absolute w-[200%] h-[200%] top-0 left-0 transform pointer-events-none",
|
||||||
anchor.includes("left") && "-translate-x-1/2",
|
anchor.includes("left") && "-translate-x-1/2",
|
||||||
@@ -345,7 +348,7 @@ const MissionMarker = ({ mission }: { mission: Mission }) => {
|
|||||||
options={{
|
options={{
|
||||||
ignoreCluster: true,
|
ignoreCluster: true,
|
||||||
}}
|
}}
|
||||||
id={`cluster-${mission.id.toString()}`}
|
id={`mission-${mission.id.toString()}`}
|
||||||
ref={popupRef}
|
ref={popupRef}
|
||||||
position={[mission.addressLat, mission.addressLng]}
|
position={[mission.addressLat, mission.addressLng]}
|
||||||
autoClose={false}
|
autoClose={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user