I have the following code (sections) which gives the gist of what I have working. A cgi will sent json updates of target movements where the receiving event source will either add a new entity if it's a new id or update the position of an already created entity:
var targetStreamJson = '../../../cgi-bin/getTargets';
var eventSource = new EventSource( targetStreamJson );
eventSource.addEventListener('message', ProcessTarget );
. . .
function ProcessTarget( event ) {
var eventJson = JSON.parse( event.data );
var ent = entities.getById( eventJson.id );
var pos = Cesium.Cartesian3.fromDegrees( eventJson.Long, eventJson.Lat, 0 );
var head = Cesium.Math.toRadians( eventJson.Heading );
var pitch = Cesium.Math.toRadians(0.0);
var roll = Cesium.Math.toRadians(0.0);
var orient = Cesium.Transforms.headingPitchRollQuaternion( pos, head, pitch, roll );
if( ent === undefined || ent === null ) {
// never seen before target
entities.add({
id : eventJson.id,
position : pos,
orientation : orient,
billboard: { image: 'milkTruck.png',
width : 18,
height : 18 }
});
}
else {
// update position of existing target...
ent.orientation = orient;
ent.position = pos;
}
}
(just a snippet as I'm pretty sure no one want to see all 800 lines)
The code above works. What I would like to do now is add the ability to display a selected entity's path. I've searched and can really only find examples of czml whose addSample() is performed statically upon the initial entities.add(). I've tried various iterations/alterations but no success.
What I suspect needs to be altered is:
var property = new Cesium.SampledPositionProperty();
var time = new Cesium.JulianDate();
Cesium.JulianDate.now( time );
property.addSample( time, position );
if( ent === undefined || ent === null ) {
// never seen before target
entities.add({
id : eventJson.id,
position : property,
orientation : orient,
billboard: { image: 'milkTruck.png',
width : 18,
height : 18 },
// Show the path as a yellow line sampled in 5 second increments.
path : {
resolution : 5,
material : new Cesium.PolylineGlowMaterialProperty({
glowPower : 0.1,
color : Cesium.Color.YELLOW
}),
width : 10
}
});
}
else {
// update position of existing target...
ent.orientation = orient;
ent.position = property; // Argg! Not so sure about this...
}
}
Does anyone See anything wrong with this approach?
I've tried this and cannot get ANY billboards displayed.
Thanks everyone.
Ps. There was recently a post from Patrick Cozzi who pointed out that this group has never had an incident of abusive language. Please don't let my post change that LOL