How to calculate the length of a polyline across the Earth

How does one calculate the length of a polyline as a great circle distance? In this case the line only has two positions in it; i know there’s a cartesian3 distance function, but that’s a straight line distance.

I found this method, but it seems to be based on outdated and removed functions.

Created a methodology using the CallbackProperty showcase example.

This is assuming that a polyline already exists.

   var geodesic = new Cesium.EllipsoidGeodesic();
   let totalDistanceInKm = 0.0
   let distLine = viewer.entities.getById("examplePoly").polyline;

   if (distLine && distLine.positions) {
     let startPos = distLine.positions.getValue([0];
     let endPos = distLine.positions.getValue([1];


     var totalDistanceInMeters = Math.round(geodesic.surfaceDistance);

     totalDistanceInKm = totalDistanceInMeters * 0.001;

   return totalDistanceInKm;