question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose actualClampedPosition for Points

See original GitHub issue

Here’s the scenario which came up on the forum:

You’re trying to draw a polyline from the air to the ground so it looks something like this:

chrome_2018-09-02_12-01-44

You can’t use polylines clamped to ground because one of the points is in the air. One way to do it is to use sampleTerrainMostDetailed to get the actual terrain height and just use that as the other point.

// Plane position
var position = Cesium.Cartesian3.fromDegrees(-122.0744619, 44.0503706, 1600);
var groundPosition = new Cesium.Cartographic(-2.1305346621060743, 0.7688285707007808);

var promise = Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, [groundPosition]);
Cesium.when(promise, function(updatedPositions) {
    var finalGroundPos = Cesium.Cartographic.toCartesian(groundPosition);
    viewer.entities.add({
        polyline : {
            positions : [position,finalGroundPos],
            width : 10,
            material : new Cesium.PolylineArrowMaterialProperty(Cesium.Color.RED)
        }
    });
});

But then this doesn’t work well if the point on the ground is moving. So to achieve something like this:

ground_line

I created a point that was clamped to ground and used its position as the end point of the line. But that position doesn’t take into account the clamping to ground. So I had to dig it out of the private API:

var PointViz = viewer.dataSourceDisplay._defaultDataSource._visualizers[4];
var pos = new Cesium.BoundingSphere();

viewer.entities.add({
    polyline : {
        positions : new Cesium.CallbackProperty(function(time) {
            PointViz.getBoundingSphere(groundPoint,pos);
            return [position, pos.center];
            //return [position, groundPoint.position.getValue(time)];
    }, false),
        width : 10,
        material : new Cesium.PolylineArrowMaterialProperty(Cesium.Color.RED)
    }
});

Here it is running in Sandcastle.

It seems like the Billboard at least does keep track of its actual clamped position:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Billboard.js#L916-L929

If it doesn’t degrade performance it would be nice to expose this for points (especially if it’s already computed every time the point updates). It would be a really easy way/fast way to get terrain height at any location in real time.

(I tried to look if there was an issue about this already but I couldn’t anything. If there’s already a way to accomplish this feel free to close).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mramatocommented, Sep 4, 2018

Also, if you just want the height of the current visual terrain (so it always matches what the user sees on screen) scene.globe.getHeight() will give you that. Bonus that it’s synchronous so great for interactive editing. You’ll just want to do a single sampleTerrainMostDetailed call at the end though so that you have the “real” position. Documentation for getHeight could probably use some polish.

1reaction
hpinkoscommented, Sep 4, 2018

@OmarShehata the best method for achieving something like this is to position = viewer.scene.globe.pick(viewer.scene.camera.getPickRay(mousePosition)) to get a rough position while the mouse is moving, then you can call sampleTerrainMostDetailed to get the final accurate position once the position is set.

You never want to dig into the private API like that. There are usually ways to accomplish what you are trying to do using the public API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expose actualClampedPosition for Points · Issue #6995 - GitHub
I created a point that was clamped to ground and used its position as the end point of the line. But that position...
Read more >
Exposed point - Wikipedia
In mathematics, an exposed point of a convex set C {\displaystyle C} C is a point x ∈ C ... are examples of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found