如何在Forge viewer的二维绘图中获取X、Y坐标

How to get X, Y coordinates in 2D drawing of Forge viewer

我想通过单击鼠标获得二维图形的 X 和 Y 坐标。然后我可以在这个 2D 图上画一些东西。这是获取鼠标点击坐标的代码,但它不正确。

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);
});

尝试使用 custom viewer tool:

handleSingleClick (e, button) {

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

    if (hitTest) {

        console.log(hitTest.point)
    }
}