Issues when drawing using scale

半世苍凉 提交于 2019-12-11 04:13:52

问题


I have a KonvaJS application and I'm dealing with an issue using the scale option.

You can see the problem here: Issue example

I use the KonvaJS Line class to draw and it's working fine. But when I change the Stage scale then the problem comes up. It's like the cursor is in a different position.

I tried different solutions without luck.

Any ideas on how to solve this issue?

Thanks in advance.


回答1:


You just need to adapt mouse position to stage transform. You can do this:

  const pos = stage.getPointerPosition();

  const stageTransform = stage.getAbsoluteTransform().copy();
  const position = stageTransform.invert().point(pos);

  layer.add(new Konva.Circle({
    x: position.x,
    y: position.y,
    radius: 10,
    fill: 'red'
  }));

Demo: http://jsbin.com/gaqepodivu/1/edit?js,output



来源:https://stackoverflow.com/questions/52615553/issues-when-drawing-using-scale

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!