Creating a flyby feature

Hi,

I am trying to achieve the following:

  • A GPS route plotted on a cesium map (path?)

  • A marker which then moves along this route (path?)

  • A camera that follows the marker as it moves

I had to take a short break from cesium development, so I am just getting back into it. I would like to confirm what I am thinking…

  1. I have the lat, lng and heights of the gps trace (from another mapping source) - I will therefore need to first “sample the terrain” to get the correct heights?

  2. I would then follow something like the interpolation demo?

Any help would be great.

Thanks

Aaron

Hello Aaron.

If the gps trace has height data associated with it, you might not need to sample the terrain. It depends on whether the heights are relative to the terrain or relative to sea level.

And yes, the interpolation demo looks like it would be a good place to start for what you’re trying to do.

Best,

Hannah

Hi Hannah

It does have height data but its relative to the wrong level (as you noted).

I have used the promise callback to sample the terrain but this then gives Cartographic which I am then not sure how to use the the property.addSample

I have found this https://cesiumjs.org/Cesium/Build/Documentation/Ellipsoid.html (converts from cartographicToCartesian) but not sure if this is the right thing to do i.e.

  • Perform the request to get my waypoints in radians

  • Create an array of cartographics from my waypoints

  • Pass to the sampleTerrain

  • Convert sampled terrain to Cartesian

  • Build the property for use with the entity

Thanks

Aaron

Yep, that is what I would do. In the callback function for sampleTerrain, you will have an array of cartographic positions with a height equal to the terrain height. You’ll have to add your gps data height to that (something along the lines of terrainSamplePositions[i].height+= gpsData[i].height )

Then you can use scene.globe.ellipsoid.cartographicArrayToCartesianArray to convert your array of Cartographics to an array of Cartesian3 positions to give to the entity.

-Hannah

Hi

I have implemented this but the path is still not flush to the terrain in some areas, and it goes under in others.

It is a ground level activity, and I have used the sampleTerrain + added a small amount so the path is visible, but its a bit hit and miss if its flush to the surface.

Any ideas?

You can try passing a larger number for the level value to the sampleTerrain function. This may take longer to compute, but it should be more accurate. We are planning to support polylines on terrain sometime soon, but for now this method is the best workaround we have.

I am passing in level 11. Not really sure how I can make it more accurate?