Tom Denby
Tom Denby

Reputation: 53

Geo Location on click _ Forge viewer

i'm looking for some guidance on how best to display real world coordinates when i click on the screen or select a model element in the forge viewer.

i have had a look around and done some research but with little success, however i have found this post that helps however the coordinate read out seems to be completely diffent to the cordantes that i would expect to see.

https://github.com/apprentice3d/ForgeViewerExtensions/blob/master/assets/js/extensions/transformationExplorer.js

As you can tell i dont know much about the viewer geo extension, any guidance on this would be great.

Thanks Tom.

Upvotes: 1

Views: 420

Answers (2)

Petr Broz
Petr Broz

Reputation: 9942

If it's enough to get the world coordinates of a point you clicked on in the viewer, you can simply use the viewer's clientToWorld method, for example like so:

viewer.container.addEventListener('click', function (ev) {
    const result = viewer.clientToWorld(ev.clientX, ev.clientY);
    if (result) {
        console.log(result.point);
    }
});

Upvotes: 1

Tom Denby
Tom Denby

Reputation: 53

i managed to get it to work by using NOP_VIEWER.model.getData().globalOffset

Example

this.infoX.innerText = nodeData.position.x + NOP_VIEWER.model.getData().globalOffset.x;

Upvotes: 0

Related Questions