How I can get time index of the entity?

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

I want to take current time. It should be change over time. There is no iteration in my code. I will take position of an object so I tried this.

var mainObjPos =entity.position.getValue(viewer.clock.currentTime);

in getValue I feed currentTime but it did not change over time. It gave only one sample.

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

function computeCirclularFlight(height) { //this is the path of vehicle

var property = new Cesium.SampledPositionProperty();

for (var i = 0; i <= 74; i += 6) {

var time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());

var position = Cesium.Cartesian3.fromDegrees(lon_lat[i], lon_lat[i+1], height);

property.addSample(time, position);

}

return property;

}

var position = computeCirclularFlight(0.5);

var entity = viewer.entities.add({

//Set the entity availability to the same interval as the simulation time.

availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({

start : start,

stop : stop

})]),

position : position,

orientation : new Cesium.VelocityOrientationProperty(position),

model : {

uri : ‘…/…/…/…/Apps/SampleData/models/CesiumMilkTruck/CesiumMilkTruck.glb’,

minimumPixelSize : 8,

scale: 1,

maximumScale: 2

}});

var mainObjPos = entity.position.getValue(viewer.clock.currentTime); // i think issue is here

var objEntity = viewer.entities.add({

position : mainObjPos,

model : {

uri : ‘…/…/…/…/Apps/SampleData/models/CesiumMilkTruck/CesiumMilkTruck.glb’,

minimumPixelSize : 8,

scale: 1,

maximumScale: 2

}

});

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

So I want to change an entity’s position which respect to another entity.

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

Lastest version, Opera, Win7.

So could you help me to take time index or exact position of the first entity?

It’s hard to tell what the issue is from the code sample (for example, how do you define your “start” and “stop” variables? Providing a complete Sandcastle example helps), but have you verified that the viewer is set to advance simulation time? By default, the viewer sets shouldAnimate to false.

I added to code below, I would like to move objEntity which respect to entity. Thank you.

var viewer = new Cesium.Viewer(‘cesiumContainer’, {

infoBox: false, //Disable InfoBox widget

selectionIndicator: false, //Disable selection indicator

shouldAnimate: true, // Enable animations

//terrainProvider: Cesium.createWorldTerrain()

});

//Enable lighting based on sun/moon positions

viewer.scene.globe.enableLighting = true;

//Enable depth testing so things behind the terrain disappear.

viewer.scene.globe.depthTestAgainstTerrain = true;

//Set bounds of our simulation time

var start = Cesium.JulianDate.fromDate(new Date(2015, 2, 25, 16));

var stop = Cesium.JulianDate.addSeconds(start, 74, new Cesium.JulianDate());

var current = Cesium.JulianDate.now();

//heading of the model object

var heading = Cesium.Math.toRadians(90.0);

var pitch = Cesium.Math.toRadians(0);

var roll = Cesium.Math.toRadians(0);

var hpRoll = new Cesium.HeadingPitchRoll(heading,pitch,roll);

var fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator(‘south’, ‘west’);

viewer.clock.startTime = start.clone();

viewer.clock.stopTime = stop.clone();

viewer.clock.currentTime = start.clone();

viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; //Loop at the end

viewer.clock.multiplier = 0.2;

viewer.timeline.zoomTo(start, stop);

var lon_lat = [29.207734,41.0220831,

29.2102525,41.0200434,

29.206165,41.0178572,];

function computeCirclularFlight(height) {

var property = new Cesium.SampledPositionProperty();

var time_array = ;

for (var i = 0; i <= 5; i += 2) {

var time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());

var position = Cesium.Cartesian3.fromDegrees(lon_lat[i], lon_lat[i+1], height);

property.addSample(time, position);

time_array.push(time);

//Also create a point for each sample we generate.

viewer.entities.add({

position : position,

point : {

pixelSize : 6,

color : Cesium.Color.TRANSPARENT,

outlineColor : Cesium.Color.GREEN,

outlineWidth : 1

}

});

}

return [property,time_array];

}

var [position,timing] = computeCirclularFlight(0.5);

console.log(timing);

var positionOfLabel = computeCirclularFlight(5);

var positionOfLabel = positionOfLabel[0];

var entity = viewer.entities.add({

//Set the entity availability to the same interval as the simulation time.

availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({

start : start,

stop : stop

})]),

//Use our computed positions

position : position,

//Automatically compute orientation based on position movement.

orientation : new Cesium.VelocityOrientationProperty(position),

//Load the Cesium plane model to represent the entity

model : {

uri : ‘…/…/…/…/Apps/SampleData/models/CesiumMilkTruck/CesiumMilkTruck.glb’,

minimumPixelSize : 8,

scale: 1,

maximumScale: 2

},

//Show the path as a pink line sampled in 1 second increments.

path : {

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.1,

color : Cesium.Color.YELLOW

}),

width : 10

}

});

//tracked object is vehicle

var labelEntity = viewer.entities.add({

position: positionOfLabel,

label : {

id : ‘speed’,

text: ‘phil’,

verticalOrigin: Cesium.VerticalOrigin.TOP

},

path : {

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.1,

color : Cesium.Color.YELLOW

}),

width : 10

}

});

var timeofObj = Cesium.JulianDate.addSeconds(start, 5, new Cesium.JulianDate());

var objPosition = Cesium.Cartesian3.fromDegrees( 8.29458,49.0682,0.5);

var objEntity = viewer.entities.add({

position : entity.position.getValue(current),

orientation : new Cesium.VelocityOrientationProperty(position),

model : {

uri : ‘…/…/…/…/Apps/SampleData/models/CesiumMilkTruck/CesiumMilkTruck.glb’,

minimumPixelSize : 8,

scale: 1,

maximumScale: 2

}

});

viewer.trackedEntity = entity;

//interpolation part, there should be one interpolation for each line that the code draw

entity.position.setInterpolationOptions({

interpolationDegree : 2,

interpolationAlgorithm : Cesium.LagrangePolynomialApproximation

});

labelEntity.position.setInterpolationOptions({

interpolationDegree : 2,

interpolationAlgorithm : Cesium.LagrangePolynomialApproximation

});

Thank you for providing your full code. I think I understand what you’re trying to do now.

You can verify that getValue is working by getting its output every frame:

function tick() {
console.log(entity.position.getValue(viewer.clock.currentTime));
Cesium.requestAnimationFrame(tick);
}
tick();

``

And you can see that it does change as it moves. Now if you want to set an entity’s position to something that’s not constant (like another entity’s moving position) then you can use a CallbackProperty.

So instead of:

position : entity.position.getValue(viewer.clock.currentTime)

``

Try:

position : new Cesium.CallbackProperty(function(){

return entity.position.getValue(viewer.clock.currentTime)

},false)

``

Here’s a running example. I made the second milk truck bigger to verify that it is moving with the other entity.