You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am building one functionality where there are two things, one normal image and one OSD viewer, i need to pass click coordinates whenever image or OSD is clicked, here is this function which gets this done:
const handleMouseClick = ( viewerRef: React.RefObject<OpenSeadragon.Viewer>,
e: any, click_target: string = ""
) => { let el = e.target;
console.log(viewerRef.current);
if (el) { let x, y;
// Check if the click was on the OpenSeadragon viewer
if (click_target === "osd" && viewerRef.current) {
console.log("click on osd");
// Get the click coordinates relative to the viewer
const rect = viewerRef.current.element.getBoundingClientRect();
x = e.clientX - rect.left; y = e.clientY - rect.top;
// Convert the click coordinates from viewport coordinates to image coordinates
const viewportPoint = new OpenSeadragon.Point(x, y);
const imagePoint =
viewerRef.current.viewport.viewportToImageCoordinates(viewportPoint);
x = imagePoint.x;
y = imagePoint.y;
// Adjust for zoom level and pan
const zoom = viewerRef.current.viewport.getZoom(true);
x /= zoom;
y /= zoom;
console.log("x: ", x, "y: ", y);
} else {
console.log("click on image");
// Handle click on the image (as before)
const rect = el.getBoundingClientRect();
x = e.clientX - rect.left;
y = e.clientY - rect.top;
console.log("x: ", x, "y: ", y); }
const imageScale = image ? image.width / el.offsetWidth : 1;
x *= imageScale;
y *= imageScale;
console.log("x: ", x, "y: ", y);
const click = getClick(x, y);
if (click) setClicks([click]);
}
};
here the else statement which is when normal image is pressed, that works with my model as I am implementing SAM model and it needs click coordinates, however click on OSD which is in else statement gives weird output which means i am passing wrong coordiantes, can someone help me to fix it?
The text was updated successfully, but these errors were encountered:
abhinav2712
changed the title
Issue in Passing click coordinates in OSD
Issue in passing Click Coordinates in OSD
Feb 28, 2024
I am building one functionality where there are two things, one normal image and one OSD viewer, i need to pass click coordinates whenever image or OSD is clicked, here is this function which gets this done:
here the else statement which is when normal image is pressed, that works with my model as I am implementing SAM model and it needs click coordinates, however click on OSD which is in else statement gives weird output which means i am passing wrong coordiantes, can someone help me to fix it?
The text was updated successfully, but these errors were encountered: