Polyline with two points. Achieve one point follow the terrain surface, and the other has elevation?

1. A concise explanation of the problem you’re experiencing.

hi. This is my first time to ask questions at this group. Thank you for your contribution to the Cesium project.

i want to draw polyline with two points. How to draw it with one point follow the terrain surface(without elevation), and the other point has elevation.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

var fieldPath = viewer.entities.add({
    name : uav.uavNum + ' view field path',
    polyline : {
        positions : new Cesium.CallbackProperty(function() {
            return [uavUpdateInfo[uav.uavNum]['pos'], viewFieldGlobalPositions[uav.uavNum]]
        }, false),
        material : Cesium.Color.BLUE.withAlpha(0.5),
        outline : false,
        width: 2,
        outlineColor : Cesium.Color.BLACK,
        granularity: Cesium.Math.toRadians(0.5),
    }
});

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

uav emits the laser at about 2km above the terrain, i want to draw a line from uav to the emit center(terrain surface)

4. The Cesium version you’re using, your operating system and browser.

cesium 1.48. win7. Chrome

The responses to this should help if I understand your question.

Scott

Thanks for the link Scott! I was already looking at this so I’ll add my thoughts as well:

If your ground position does not move, I think the easiest way would be to use sampleTerrainMostDetailed to get the terrain height at that location and use that as the second point in your polyline like in this Sandcastle example.

If your ground location is changing however, my approach was to use a point that’s clamped to ground, and take its position as the polyline’s second point (and then make that point invisible). Unfortunately, there’s no way to do that with the public API. I opened an issue here to discuss it:

https://github.com/AnalyticalGraphicsInc/cesium/issues/6995

I also included an example of what it would look like.

i will try. Thank you

在 2018年9月2日星期日 UTC+8下午11:40:01,Scott Reynolds写道:

Thanks for the Sandcastle demo. Awesome. There should be a high level api to do this.