如何在锻造查看器的2D绘图中获取X,Y坐标



我想通过鼠标单击获取 2D 绘图的 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);
});

使用自定义查看器工具尝试此操作:

handleSingleClick (e, button) {
    var hitTest = this.viewer.clientToWorld(e.canvasX, e.canvasY, true)
    if (hitTest) {
        console.log(hitTest.point)
    }
}

最新更新