Reputation: 97
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);
});
Upvotes: 0
Views: 1029
Reputation: 4375
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)
}
}
Upvotes: 2