ficed Bug when wrong Object is selected initialy
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user