0

I would like to get the X and Y coordinates of a 2D drawing on mouse click. Then I can draw something on top of this 2D drawing. Here is the code to get the coordinates on mouse click but it is not correct.

viewer.impl.canvas.addEventListener('mousedown', function (e) {
    // Get 2D drawing dimension
    var layoutBox = viewer.impl.getVisibleBounds();
    var width = layoutBox.max.x - layoutBox.min.x;
    var height = layoutBox.max.y - layoutBox.min.y;

    var viewport = viewer.impl.clientToViewport(e.clientX, e.clientY);
    var point = [viewport.x * width, viewport.y * height, viewport.z];

    // Show the 2D drawing X, Y coordinates on mouse click
    console.log(point);
});
Khoa Ho
  • 87
  • 2
  • 13

1 Answers1

2

Try this using a custom viewer tool:

handleSingleClick (e, button) {

    var hitTest = this.viewer.clientToWorld(e.canvasX, e.canvasY, true)

    if (hitTest) {

        console.log(hitTest.point)
    }
}
Felipe
  • 4,325
  • 1
  • 14
  • 19