Returning and unpacking multiple values in their original types

I’m looking for advise, please.

I wish to create and then populate two sampled items (a sampledProperty and a sampledPositionProperty) within a single function. Having done so, I wish to retrieve values at a specific clock time.

This code stores the data and then returns the two samples.

function storeHPR**() {**

var hdg = new Cesium.SampledProperty**(Cesium.Quaternion)**; // Heading, pitch, roll quarternion

var ctr = new Cesium.SampledPositionProperty(); // Entity position: specified as latitude, longitude, altitude

**var **date = **new **Cesium.JulianDate; // Sample time

var center = Cesium.Cartesian3(); // Re-used many times as temporary value

center = Cesium.Cartesian3.fromDegrees**(-106.401210, 31.80056,1182)**; // Stores lat, lon, alt to be used in new sample

date = Cesium.JulianDate.fromIso8601**(‘2012-08-04T17:53:11.125’)**; // JulianDate for new sample

hdg.addSample**(date, Cesium.Transforms.headingPitchRollQuaternion(center, Cesium.HeadingPitchRoll.fromDegrees(302.8,-1.2305,-0.8789)))**;

ctr.addSample**(date, center)**;

console.log**(center)**; // Correctly shows a Cartesian3 (with x, y and z values)

console.log**(date)**; // Correctly shows a JulianDate

console.log**(hdg)**; // Correctly shows an array: x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, …etc.,

console.log**(ctr)**; // Correctly shows an array: lat, lon, alt, lat, lon, alt, lat, lon, alt, …etc.,

            *[Add lots more samples]*
            **return** [hdg, ctr**]**;

}

``

Having done the above, I need the values of hdg and ctr at specific points in time.

var pos = storeHPR(); // Calls the function storeHPR, above.

currentTime = viewer.clock.currentTime; // Gets the current time defined in the widget

**var position = Cesium.Cartesian3() **

position = pos**[1].getValue(currentTime)**; // Get the lat, lon, alt data stored in the second element of the returned array

hdg = pos**[0].getValue(currentTime)**; // Get the attitude quarternion stored in the first element of the returned array

console.log**(**’--------------------------------’);

console.log**(position)**; // Results in ‘undefined’.

``

So, in essence, my query is: “I am returning an array of arrays from a function. Can I retrieve samples of each subarray at a specific time and as the same type as they went in?

The task is to use data defined as latitude / longitude / altitude / heading / pitch / roll into Cesium to show the track of three airborne entities. My understanding is that lat / lon / alt defined in a CZML file are ECEF and cannot be oriented to ENU in the same way as the headingPitchRollQuaternion transform used above. If I define two functions (one for storing positions, one for storing attitude quarternions) I can get it to work. However, this involves duplication of the lat / lon / alt data (for position and as the center of the transform to quarternion) and the sample times, resulting in much larger files.

Any assistance would be gratefully received. Apologies if my query is the result of misunderstanding or simply being thick!

  • Hugh

With the initial vars outside the function it works OK.

It doesn’t have to return anything. The value can be obtained by

f = hdg.getValue(Cesium.JulianDate.fromIso8601(‘2012-08-04T17:55:45.125’))

``

Hi there,

This seems like a lot of questions all wrapped up into one, so please let me know if I miss an important aspect!

Any JavaScript specific questions like scoping, arrays, functions, etc. will get better answers on a more generic forum, like Stack Overflow.

Cesium mot often uses Cartesian3 objects for position. There are functions to convert from lat / long / alt can be used to specify a position, or Transform function available to convert between different reference frames.

Finally, here’s an example of using SampledPositionProperty, hopefully that helps point you in the right direction.

Thanks!

Gabby

Thanks, Gabby.