Search code examples
javascriptreferencepolygoncesiumjs

How to reference positions of other entities in polygon hierarchy of Cesium using javascript?


I am using Cesium to visualize my scenario and I want to create a polygon in JavaScript using position of other moving entities as references for its endpoints. As suggested in the answer of this question by using CZML.

I was wondering if I can do it (referencing positions of other entities as endpoints of my polygon) in JavaScript. I tried a few things and it didn't work, for example, following is my code:

var newPoly= viewer.entities.add({                                            
    id : resourceSet[objIndex].id+"poly",
    name:resourceSet[objIndex].id+"poly",
    availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
        start : start,
        stop : stop
    })]),
    polygon:{
        hierarchy :{
            positions:{
                references:[
                     Cesium.ReferenceProperty.fromString(collection, ''+entityName+'#position'),
                     Cesium.ReferenceProperty.fromString(collection, ''+baseEntity[0].id+'#position'),
                     Cesium.ReferenceProperty.fromString(collection, ''+baseEntity[1].id+'#position')
                ]
            }
        },
        material :Cesium.Color.AQUA.withAlpha(0.5),
        perPositionHeight : true,
        show : true
    },
    show: true
})

For references I also tried :

  • just using entity and positions like: entity.position
  • Using entity$position.

None of them worked!


Solution

  • Entity properties have a function getValue that takes a JulianDate time as a parameter and returns the value at that time. To get a position, you should be able to do something like

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