click a point on the terrainprovider ?

Hi,

viewer.camera.pickEllipsoid(click.position)
returns a cartesian3 of the ellipsoid, but I'm using a terrainprovider and I would like to click a point on that surface, is that possible ?
I can construct a ray from the camera, but I can't seem to find a reference to the terrain mesh/model to intersect with.

Help is appreciated.

Sander

Hello Sander,

You can use globe.pick to get the intersection with the terrain. Here is an example:

    var ray = viewer.camera.getPickRay(movement.endPosition);
    var position = viewer.scene.globe.pick(ray, viewer.scene);

``

Just keep in mind that this value may vary depending on the level of detail for the terrain tile that is currently loaded. For a consistent result, you may want to use the sampleTerrain function to query the terrain for the height of the position at a given cartographic coordinate.

Best,

Hannah

Hi hannah, I am looking to do the same thing. If I am in 3D mode with terrain, will the getPickRay get the position exactly where the mouse is? Or will it ray through to the ellipsoid and then give height at that point, which would be further away.

1 Like

@Mitchell_Day

If I am understanding your use-case correctly, getPickRay should get the exact position of the mouse intersecting with the ellipsoid. Could you provide a screenshot that showcases exactly what you are asking? I want to ensure that I understand your question.

-Sam