ficed Bug when wrong Object is selected initialy

This commit is contained in:
PxlLoewe
2025-06-17 21:10:44 -07:00
parent fe77ef2c03
commit 29b57b2c37
3 changed files with 58 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ import toast from "react-hot-toast";
import { Popup, useMap } from "react-leaflet";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { editMissionAPI } from "_querys/missions";
import { findClosestPolygon } from "_helpers/findClosestPolygon";
export const ContextMenu = () => {
const map = useMap();
@@ -113,30 +114,16 @@ export const ContextMenu = () => {
onClick={async () => {
const { parsed } = await getOsmAddress(contextMenu.lat, contextMenu.lng);
const objects = await addOSMobjects(true);
const closestToContext = objects.reduce((prev, curr) => {
const prevLat = prev.nodes?.[0]?.lat ?? 0;
const prevLon = prev.nodes?.[0]?.lon ?? 0;
const currLat = curr.nodes?.[0]?.lat ?? 0;
const currLon = curr.nodes?.[0]?.lon ?? 0;
const prevDistance = Math.sqrt(
Math.pow(prevLat - contextMenu.lat, 2) + Math.pow(prevLon - contextMenu.lng, 2),
);
const currDistance = Math.sqrt(
Math.pow(currLat - contextMenu.lat, 2) + Math.pow(currLon - contextMenu.lng, 2),
);
return prevDistance < currDistance ? prev : curr;
}, [] as any);
const closestObject = findClosestPolygon(objects, {
lat: contextMenu.lat,
lon: contextMenu.lng,
});
setOpen(true);
const nodeWay: [number, number][] = [];
closestToContext.nodes?.forEach((node: { lat: number; lon: number }) =>
nodeWay.push([node.lat, node.lon]),
);
if (closestToContext) {
toggleSearchElementSelection(closestToContext.wayID, true);
if (closestObject) {
toggleSearchElementSelection(closestObject.wayID, true);
}
setMissionFormValues({