On Konva (React-Konva to be precise) there is a Stage with a Layer with an Image. Clicking on that Image gives the position of the Click on that Image. But after Dragging (either the Stage or the Image), the position is different.
In React-Konva code this looks basically like this:
<Stage width={2000} height={2000} draggable={true}>
<Layer>
<MyImage url="_some_url_pointing_to_a_png_" />
</Layer>
</Stage>
The MyImage Component:
const MyImage = (props) => {
const url = props.url;
const [image, status, width, height] = useImage(url);
return (
<Image
image={image}
width={width}
height={height}
onClick={clickHandler}
/>
);
};
(Yes, I modified the useImage React-Hook to also return width and height)
The clickHandler is quite simple:
const clickHandler = (e) => {
const stage = e.target.getStage();
const stageLocation = stage.getPointerPosition();
console.table(stageLocation);
};
The problem is that clicking on that image does give me a position, which seems to look ok. But when I drag the image, due to 'draggable={true}' on the Stage (so, 'drag the Stage' to be precise) and then click on the same position in the Image again, I get another location. This is probably obvious because it gives me the position of the Click on the Stage and not the position of the Click on the Image.
When making the Stage not Draggable and the Image Draggable, then the same problem applies.
So, question remains:
How to get the position of the Click on the Image when it (or its Stage) is Draggable?
stage.getPointerPosition()
returns absolute position of the pointer. – lavrton