我想在鼠标点击时获得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);
});
答案 0 :(得分:1)
handleSingleClick (e, button) {
var hitTest = this.viewer.clientToWorld(e.canvasX, e.canvasY, true)
if (hitTest) {
console.log(hitTest.point)
}
}