Entities vs Primitives Polygon Points Update

CesiumJs

by parsonsbrett0

JavaScript

// Using Entities:

// the original add of the empty swathe
viewer.entities.add({
                        id: result.objectsWithinCzml.id,
                        name: result.objectsWithinCzml.name + 'swathe',
                        polygon: {
                            hierarchy: new Cesium.CallbackProperty(callbackSwathe, false),
                            material: Cesium.Color.GREEN.withAlpha(0.5),
                            height: 0,
                            outline: true // height is required for outline to display
                        }
                    });


// update the callback to allow a non static return
function onSimulationClockChange() {
    // run every 60 seconds of simulation
    var currentTime = viewer.clock.currentTime;

    for (var i = 0; i < vehicles.length; i++) {
        if (vehicles[i].swathe !== null) {
            if (Cesium.JulianDate.compare(currentTime, Cesium.JulianDate.fromDate(moment(vehicles[i].swathe.item1[vehicles[i].swathe.item1.length - 1]).toDate())) <= 0 && viewer.entities.getById(vehicles[i].id).polygon.hierarchy.isConstant) {
                viewer.entities.getById(vehicles[i].id).polygon.hierarchy.setCallback(callbackSwathe, false);
                clockChange = currentTime;
            }
        }
    }
}

// callback to update the swathe to the current time and also update the callback to keep the final swathe shown if the current time is after the flight end time
function callbackSwathe() {
    //alert('this is it');
    // run every 60 seconds of simulation
    var currentTime = viewer.clock.currentTime;
    var swathe = vehicles.find(x => x.id === this.id).swathe;
    var fullSwathe;
    var currentSwathe;
    var timeDifference = Cesium.JulianDate.secondsDifference(currentTime, clockChange);
    if (timeDifference >= parseFloat($('#StepTime').val()) || timeDifference < 0) {
        clockChange = currentTime;
        if (Cesium.JulianDate.compare(currentTime,...