Entity vs Primitive update polygon shape

1. A concise explanation of the problem you're experiencing.
I am attempting to show a sensor's swathe as a UAV flies. The swathe for the UAV's flight is fully computed with points corresponding to a specific JulianDate and I would like the polygon showing the swathe to update every so often when the UAV hits the next point in the coordinate/JulianDate pair (start with showing no swathe and then update the polygon to show up-to-date what the sensor has seen).

My question pertains to understanding the relationship between Entities and how they correspond to Primitives. I have achieved my goal using entities and updating the polygon's hierarchy through a CallbackProperty. However, this would create a "blinking" effect as the polygon (swathe) was updated. This led me to look into Primitives and its asynchronous characteristic. I have read that setting asynchronous to false rids the blinking/flickering effect. So I switched over to using Primitives. However, I have run into issues with removing the primitive and adding a new one. I find that it the new primitive being added has an undefined geometryInstance.

I would be fine using entities with the callback (I understand using entities is more computationally expensive) if there was no flicker or blinking when it updated the polygon's shape. I would like to know more about how to control primitives, update the shape of them (e.g. PolygonGeometryUpdater), their performance, and the pros and cons in comparison to using Entities (entities seem much more versatile).

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

Below is a link to a jsfiddle. Might be easier to look through the code in there.
https://jsfiddle.net/parsonsbrett0/k018zbgy/2/

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, Cesium.JulianDate.fromDate(moment(swathe.item1[swathe.item1.length - 1]).toDate())) <= 0) {
            
            // get the vehicle's full swathe
            fullSwathe = Cesium.Cartesian3.unpackArray(swathe.item2);

            // get the date to show up to;
            var dateToIndex = binarySearchSwatheTime(swathe.item1, currentTime); // just returns an index

            // get the vehicle's to date swathe
            currentSwathe = new Cesium.PolygonHierarchy(fullSwathe.slice(0, dateToIndex + 1).concat(fullSwathe.slice(fullSwathe.length - dateToIndex - 1)));

            return currentSwathe;
        } else {
            if (!this.isConstant) {
                this.setCallback(callbackSwathe, true);

                fullSwathe = Cesium.Cartesian3.unpackArray(swathe.item2);
                return new Cesium.PolygonHierarchy(fullSwathe);
            }
        }
    }
}

Using Primitives:

// the original add of the empty swathe
var instance = new Cesium.GeometryInstance({
    geometry: new Cesium.PolygonGeometry({
        polygonHierarchy: new Cesium.PolygonHierarchy()
    }),
    id: result.objectsWithinCzml.id,
    attributes: {
        color: new Cesium.ColorGeometryInstanceAttribute(0.0, 0.5, 0, 0.5)
    }
});

viewer.scene.primitives.add(new Cesium.GroundPrimitive({
    geometryInstances: instance,
    appearance: new Cesium.PerInstanceColorAppearance(),
    asynchronous: false
}));

function onSimClockChange() {

    // run every 60 seconds of simulation
    var currentTime = viewer.clock.currentTime;
    var timeDifference = Cesium.JulianDate.secondsDifference(currentTime, clockChange);
    if (timeDifference >= parseFloat($('#StepTime').val()) || timeDifference < 0) {

        clockChange = 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) {

                    // assign to the geometry now.
                    var primitives = viewer.scene.primitives;
                    for (var j = 0; j < primitives.length; j++) {
                        var currentPrimitive = primitives.get(j);
                        if (currentPrimitive.hasOwnProperty('geometryInstances')) {
                            if (currentPrimitive.geometryInstances.id === vehicles[i].id) {

                                var fullSwathe = Cesium.Cartesian3.unpackArray(vehicles[i].swathe.item2);

                                // get the date to show up to;
                                var dateToIndex = binarySearchSwatheTime(vehicles[i].swathe.item1, currentTime);

                                primitives.remove(currentPrimitive);

                                viewer.scene.primitives.add(new Cesium.GroundPrimitive({
                                    geometryInstances: new Cesium.GeometryInstance({
                                        geometry: new Cesium.PolygonGeometry({
                                            polygonHierarchy: new Cesium.PolygonHierarchy(fullSwathe.slice(0, dateToIndex + 1).concat(fullSwathe.slice(fullSwathe.length - dateToIndex - 1)))
                                        }),
                                        id: vehicles[i].id,
                                        attributes: {
                                            color: new Cesium.ColorGeometryInstanceAttribute(0.0, 0.5, 0, 0.5)
                                        }
                                    }),
                                    appearance: new Cesium.PerInstanceColorAppearance(),
                                    asynchronous: false
                                }));

                                break;
                            }
                        }
                    }
                }

            }
        }
    }
}

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I am trying to update a polygon's points dynamically and without a flicker when updating.

4. The Cesium version you're using, your operating system and browser.
"cesium": "^1.52.0"
Windows 10 Pro Version 1809 OS build 17763.292
Google Chrome Version 71.0.3578.98

I think if the entity with a callback property is flickering, that would be a bug and perhaps something that we could fix. If you could provide a Sandcastle example (https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/) of this happening we could open a bug report on GitHub.

There’s unfortunately not a lot of resources written about primitives that I’m aware of. Your best bet might be reading the source code to see how they’re used. If you can show a minimal example of updating a primitive that resulted in an undefined geometry instance that I can run on Sandcastle I can try to look into that as well.

So I found that my Primitive code worked if I added the following to both the initial declaration of the primitive and in the new primitive that is created to "updated" the old (and now deleted) primitive.

releaseGeometryInstances: false, in the following code:

viewer.scene.primitives.add(new Cesium.GroundPrimitive({
                        geometryInstances: instance,
                        appearance: new Cesium.PerInstanceColorAppearance(),
                        releaseGeometryInstances: false,
                        asynchronous: false
                    }));

As for using an entity and updating its shape here is a sandcastle with the given problem. The swathe is being drawn to the left of the Great Lakes. Put the clock on x350 to see the issue as the polygon shape is supposed to update every minute of cesium clock time.

I also see that if you change the clock to x5000 or greater, it shows sort of how I need the update to look like. I just need it to look like that at any speed.

var viewer = new Cesium.Viewer('cesiumContainer');

// holds all the data for a single UAV with a simple conic sensor. The swathe shows roughly where that sensor sees on the ground
var vehicles = [{ name:"UAV", id:"1a150f73-717b-4985-b2b8-f7409de89acd", waypointsOculus:[{order:1, name:"Waypoint", id:"399e8d28-4273-450e-b30e-0ca337739ed0",uavId:"1a150f73-717b-4985-b2b8-f7409de89acd",latitude:43.3117,longitude:-93.69754,altitude:10000,groundSpeed:200,rateOfClimb:0},{order:2,name:"Waypoint 2",id:"9ae9ead3-0854-42c2-aee3-bb69cef0f641",uavId:"1a150f73-717b-4985-b2b8-f7409de89acd",latitude:41.24664,longitude:-91.96659,altitude:10000,groundSpeed:200,rateOfClimb:0},{order:3,name:"Waypoint 3",id:"3e72259b-efe0-413d-9190-4950f4282b23",uavId:"1a150f73-717b-4985-b2b8-f7409de89acd",latitude:41.17983,longitude:-94.80914,altitude:10000,groundSpeed:200,rateOfClimb:0}],returnToStart:true,sensor:{coneHalfAngle:25,platformID:null,name:"Simple Conic Sensor: Sensor 1",type:1,radius:Infinity},swathe:{item1:["2019-02-19T11:08:00Z","2019-02-19T11:09:00Z","2019-02-19T11:10:00Z","2019-02-19T11:11:00Z","2019-02-19T11:12:00Z","2019-02-19T11:13:00Z","2019-02-19T11:14:00Z","2019-02-19T11:15:00Z","2019-02-19T11:16:00Z","2019-02-19T11:17:00Z","2019-02-19T11:18:00Z","2019-02-19T11:19:00Z","2019-02-19T11:20:00Z","2019-02-19T11:21:00Z","2019-02-19T11:22:00Z","2019-02-19T11:23:00Z","2019-02-19T11:24:00Z","2019-02-19T11:25:00Z","2019-02-19T11:26:00Z","2019-02-19T11:27:00Z","2019-02-19T11:28:00Z","2019-02-19T11:29:00Z","2019-02-19T11:30:00Z","2019-02-19T11:31:00Z","2019-02-19T11:32:00Z","2019-02-19T11:33:00Z","2019-02-19T11:34:00Z","2019-02-19T11:35:00Z","2019-02-19T11:36:00Z","2019-02-19T11:37:00Z","2019-02-19T11:38:00Z","2019-02-19T11:39:00Z","2019-02-19T11:40:00Z","2019-02-19T11:41:00Z","2019-02-19T11:42:00Z","2019-02-19T11:43:00Z","2019-02-19T11:44:00Z","2019-02-19T11:45:00Z","2019-02-19T11:46:00Z","2019-02-19T11:47:00Z","2019-02-19T11:48:00Z","2019-02-19T11:49:00Z","2019-02-19T11:50:00Z","2019-02-19T11:51:00Z","2019-02-19T11:52:00Z","2019-02-19T11:53:00Z","2019-02-19T11:54:00Z","2019-02-19T11:55:00Z","2019-02-19T11:56:00Z","2019-02-19T11:57:00Z","2019-02-19T11:58:00Z","2019-02-19T11:59:00Z","2019-02-19T12:00:00Z","2019-02-19T12:01:00Z","2019-02-19T12:02:00Z","2019-02-19T12:03:00Z","2019-02-19T12:04:00Z","2019-02-19T12:05:00Z","2019-02-19T12:06:00Z","2019-02-19T12:07:00Z","2019-02-19T12:08:00Z","2019-02-19T12:09:00Z","2019-02-19T12:10:00Z","2019-02-19T12:11:33.0733632Z"], item2:[-298551.02212218475,-4635511.566947003,4356104.348196525,-302091.52183639864,-4635709.4892738955,4355652.655589143,-304263.1819076564,-4637582.151526664,4353521.859902124,-303796.0732331637,-4640027.7125567915,4350965.138953235,-297811.6330796229,-4647364.255316106,4343592.132443942,-291826.1534670838,-4654684.36273009,4336203.649550307,-285839.6555481943,-4661988.008550037,4328799.71625515,-279852.1604801085,-4669275.166584215,4321380.358597322,-273863.6894244116,-4676545.8106979765,4313945.602671607,-267874.26354703866,-4683799.914813848,4306495.474628642,-261883.90401821435,-4691037.452911641,4299030.000674835,-255892.63201236576,-4698258.399028544,4291549.207072277,-249900.46870805437,-4705462.727259222,4284053.120138667,-243907.43528790827,-4712650.411755929,4276541.766247207,-237913.55293853517,-4719821.42672859,4269015.17182654,-231918.8428504549,-4726975.746444919,4261473.363360644,-225923.3262180276,-4734113.345230502,4253916.367388765,-219927.0242393772,-4741234.197468905,4246344.210505319,-213929.95811631618,-4748338.277601773,4238756.919359804,-207932.14905427283,-4755425.560128928,4231154.520656725,-201933.61826221802,-4762496.019608463,4223537.041155501,-195934.3869525859,-4769549.630656855,4215904.507670369,-189934.47634120224,-4776586.36794904,4208256.9470703155,-183933.9076472113,-4783606.206218537,4200594.386278977,-177932.70209301118,-4790609.120257524,4192916.852274555,-171930.88090414528,-4797595.084916955,4185224.372089726,-170592.31022816946,-4796499.530294717,4186525.8816784467,-182587.29006669673,-4796187.813848242,4186378.042725879,-194581.6253557358,-4795859.158735981,4186215.341120658,-206575.2737626789,-4795513.566110171,4186037.7774341274,-218568.19295727604,-4795151.037182121,4185845.3522898196,-230560.34061177692,-4794771.573222221,4185638.066363448,-242551.67440107316,-4794375.17555992,4185415.920382922,-254542.15200284796,-4793961.845583734,4185178.915128336,-266531.73109771207,-4793531.584741244,4184927.051431954,-278520.36936935346,-4793084.394539072,4184660.3301782347,-290508.0245046815,-4792620.276542907,4184378.7523038005,-302494.65419396665,-4792139.232377471,4184082.3187974505,-314480.2161309922,-4791641.263726528,4183771.0307001607,-326464.66801318846,-4791126.37233288,4183444.8891050653,-338447.9675417859,-4790594.559998355,4183103.895157463,-350430.0724219537,-4790045.828583802,4182748.0500548203,-362410.94036294526,-4789480.180009092,4182377.3550467505,-374390.52907824185,-4788897.616253104,4181991.8114350243,-386368.7962856993,-4788298.139353721,4181591.4205735573,-398345.6997076881,-4787681.7514078235,4181176.1838684143,-395816.0461279093,-4787686.922973826,4181408.9249679735,-390948.00451959803,-4780665.486714553,4189835.1736817043,-386078.56361914636,-4773627.126828197,4198246.480861144,-381207.7407025825,-4766571.868637169,4206642.816872868,-376335.5530500216,-4759499.737522611,4215024.152138298,-371462.01794560254,-4752410.758924297,4223390.457133815,-366587.15267742216,-4745304.958340529,4231741.702390839,-361710.97453747777,-4738182.361328047,4240077.858495936,-356833.50082159456,-4731042.993501916,4248398.896090909,-351954.74882938527,-4723886.880535431,4256704.785872903,-347074.7358641612,-4716714.048160018,4264995.498594485,-342193.479232892,-4709524.522165132,4273271.005063753,-337310.9962461285,-4702318.328398149,4281531.276144426,-332427.3042179451,-4695095.492764275,4289776.282755943,-327542.4204658889,-4687856.041226437,4298005.995873547,-322656.362310897,-4680599.999805181,4306220.386528398,-317769.1470772515,-4673327.3945785845,4314419.425807643,-312880.79209251533,-4666038.251682125,4322603.084854537,-307991.3146874534,-4658732.597308611,4330771.334868511,-303100.73219599435,-4651410.457708056,4338924.147105283,-295512.20343215443,-4640019.629773424,4351540.359887921,-295408.0606761849,-4637572.81665719,4354137.480684811,-297858.33225147845,-4635704.772547448,4355947.221198001,-301427.77750088566,-4635514.7902224455,4355904.150869566,-304018.16133653355,-4637114.464135809,4354033.675693556,-311606.6916458678,-4648505.316362364,4341417.485638447,-316497.2751559629,-4655827.471693188,4333264.688052514,-321386.7535972357,-4663133.141852149,4325096.452688722,-326275.10963581025,-4670422.300589208,4316912.8082911465,-331162.32594097144,-4677694.921711538,4308713.783660145,-336048.38518521376,-4684950.979083637,4300499.407652255,-340933.27004430717,-4692190.446627404,4292269.709180122,-345816.9631973675,-4699413.298322271,4284024.717212379,-350699.4473269041,-4706619.50820528,4275764.460773573,-355580.7051188938,-4713809.0503712045,4267488.968944059,-360460.7192628389,-4720981.898972638,4259198.270859909,-365339.4724518206,-4728138.0282201,4250892.395712818,-370216.94738257804,-4735277.412382137,4242571.3727500085,-375093.1267555604,-4742400.025785422,4234235.231274133,-379967.993274989,-4749505.842814858,4225884.000643177,-384841.5296489156,-4756594.83791368,4217517.7102703685,-389713.7185892967,-4763666.985583549,4209136.389624078,-394584.5428120452,-4770722.260384663,4200740.06822772,-399453.9850370982,-4777760.636935843,4192328.7756596636,-404322.02798847394,-4784782.089914647,4183902.5415531257,-398419.1030428742,-4793832.081719427,4174163.5339569203,-386442.19962243387,-4794448.471998046,4174578.772685739,-374463.9324040378,-4795047.951147116,4174979.1654987256,-362484.3436657325,-4795630.517069722,4175364.7109897872,-350503.47569007927,-4796196.167727945,4175735.407804977,-338521.37076401425,-4796744.901142867,4176091.2546425057,-326538.0711787015,-4797276.715394588,4176432.250252731,-314553.6192293895,-4797791.60862223,4176758.393438159,-302568.05721526546,-4798289.5790239265,4177069.6830534763,-290581.4274393173,-4798770.624856849,4177366.118005519,-278593.7722081795,-4799234.7444372075,4177647.697253293,-266605.1338320001,-4799681.936140248,4177914.419807982,-254615.55462428782,-4800112.198400263,4178166.2847329364,-242625.0769017734,-4800525.5297105955,4178403.2911436907,-230633.7429842645,-4800921.9286236465,4178625.438207957,-218641.59519449653,-4801301.393750875,4178832.725145628,-206648.6758579969,-4801663.923762815,4179025.1512287785,-194655.02730293467,-4802009.51738905,4179202.715781683,-182660.69185997878,-4802338.1734182555,4179365.418180794,-170665.71186215564,-4802649.890698177,4179513.257854758,-163857.45801719945,-4794673.441034807,4188870.1864769547,-169859.27835214874,-4787687.45402561,4196562.647139618,-175860.4830266515,-4780684.517713442,4204240.161623132,-181861.05081526886,-4773664.657247381,4211902.702895104,-187860.96049572097,-4766627.897835282,4219550.243977604,-193860.19084898103,-4759574.26474366,4227182.757947276,-199858.72065933215,-4752503.783297607,4234800.217935412,-205856.52871445686,-4745416.478880677,4242402.597128052,-211853.59380549868,-4738312.376934807,4249989.8687660545,-217849.89472714523,-4731191.502960202,4257562.006145194,-223845.4102777062,-4724053.882515245,4265118.982616248,-229840.11925916714,-4716899.541216395,4272660.771585077,-235834.00047728652,-4709728.504738089,4280187.346512716,-241827.0327416613,-4702540.79881264,4287698.680915463,-247819.19486579997,-4695336.449230139,4295194.748364953,-253810.46566719338,-4688115.481838359,4302675.5224882625,-259800.8239673996,-4680877.922542653,4310140.976967967,-265790.2485921052,-4673623.797305851,4317591.085542257,-271778.718371208,-4666353.13214816,4325025.822004999,-277766.21213888814,-4659065.953147069,4332445.160205834,-283752.70873368287,-4651762.286437242,4339849.074050256,-289738.1869985562,-4644442.158210427,4347237.537499691,-295722.6257809786,-4637105.594715341,4354610.524571598]}, show:true}];

// update dates to sandcastle sim dates.
var startTime = viewer.clock.startTime;
var clockChange = viewer.clock.startTime;

// using this function instead of Cesium.JulianDate.addMinutes() because use of that function
// resulted in the startTime being added only. Weird. So I used this.
function addMinutes(date, minutes) {
    return new Date(date.getTime() + minutes*60000);
}

// This allows the swathe dates to be current with the sim time of your sandcastle instance.
// The dates in vehicles before the below code come from sample data from the project I am working on.
vehicles[0].swathe.item1 = ;
for (var i = 0; i < 64; i++) {
    var startDate = Cesium.JulianDate.toDate(startTime);
    var newDate = addMinutes(startDate, i);
    vehicles[0].swathe.item1.push(Cesium.JulianDate.fromDate(newDate));
}

// add the entity initially to the viewer's entities.
// it is important to note that most of this was pulled out of a project and therefore
// hardcoded in this sandcastle (such as the entity id)
viewer.entities.add({
    id: '1a150f73-717b-4985-b2b8-f7409de89acd',
    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
    }
});

// add onTick event to handle scrubbing of timeline in sim
viewer.clock.onTick.addEventListener(
    // Runs on each tick.
    // update the callback to allow a non static return
    function onSimulationClockChange() {
        // run every 60 seconds of simulation
        var currentTime = viewer.clock.currentTime;

        // Go through all the vehicles
        // in this case we only have one. In my project, I have several
        for (var i = 0; i < vehicles.length; i++) {
            if (vehicles[i].swathe !== null) {
                if (Cesium.JulianDate.compare(currentTime, vehicles[i].swathe.item1[vehicles[i].swathe.item1.length - 1]) <= 0 && viewer.entities.getById(vehicles[i].id).polygon.hierarchy.isConstant) {
                    // this is to optimize the amount of return data. So this essential allows the callback to return
                    // changing values each time. In the call back, I set this to true so that I reduce the computation
                    // when possible
                    viewer.entities.getById(vehicles[i].id).polygon.hierarchy.setCallback(callbackSwathe, false);
                    clockChange = currentTime;
                }
            }
        }
    },
    this
);

// 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() {
    var currentTime = viewer.clock.currentTime;
    var swathe = vehicles[0].swathe;
    var fullSwathe;
    var currentSwathe;
    var timeDifference = Cesium.JulianDate.secondsDifference(currentTime, clockChange);
    // run every 60 seconds of simulation or if the user has scrubbed back to an earlier time
    if (timeDifference >= parseFloat(60) || timeDifference < 0) {
        clockChange = currentTime;
        // check if the flight is in progress, therefore requiring us to update the swathe
        if (Cesium.JulianDate.compare(currentTime, swathe.item1[swathe.item1.length - 1]) <= 0) {
            
            // get the vehicle's full swathe
            fullSwathe = Cesium.Cartesian3.unpackArray(swathe.item2);

            // get the date to show up to;
            var dateToIndex = binarySearchSwatheTime(swathe.item1, currentTime); // just returns an index
            
            // get the vehicle's to date swathe
            currentSwathe = new Cesium.PolygonHierarchy(fullSwathe.slice(0, dateToIndex + 4).concat(fullSwathe.slice(fullSwathe.length - dateToIndex - 1)))

            return currentSwathe;
        } else { // update the callback so we can optimize computation time
            if (!this.isConstant) {
                this.setCallback(callbackSwathe, true);

                fullSwathe = Cesium.Cartesian3.unpackArray(swathe.item2);
                return new Cesium.PolygonHierarchy(fullSwathe);
            }
        }
    }
}

// Custom binary search to find the proper swathe time
function binarySearchSwatheTime(items, match) {

    var low = 0;
    var high = items.length - 1;

    while (low <= high) {
        if (high - low < 2) {
            return low;
        } else {
            var mid = parseInt((low + high) / 2);

            // result = pos if currentTime (match) is after the time in the index
            // result = neg if currentTime (match) is before the time in the index
            // result = neg if currentTime (match) is equal to the time in the index
            var result = Cesium.JulianDate.compare(match, items[mid]);

            if (result < 0) {
                high = mid - 1;
            } else if (result > 0) {
                low = mid + 1;
            } else {
                return mid;
            }
        }
    }

    return -1;
}

Thanks for providing a Sandcastle! I see the problem now.

A callback function is not a function that updates a position. It’s a function that, given a time, returns a position. The idea being, regardless of whether time is moving forwards, backwards, or just paused at a particular time, it will tell you where this entity is/what it should look like at that particular given time.

In your case, since you only return a position when something it changes, and otherwise the function returns nothing, you will only see the entity during those update steps. The “right” way to do it is to compute the swathe based on the given time, as opposed to checking for time deltas, but you can keep this design and make it work just by saving the last computed position and always returning that. Here’s a Sandcastle of what this looks like.

You’re still going to get a flicker at the very end because of the entity switching from a static to a dynamic, which I think forces it to recreate the primitive asynchronously. There’s no way to mark an entity as synchronous right now, but there was some discussion here about enabling that:

https://github.com/AnalyticalGraphicsInc/cesium/issues/4727#issuecomment-464546572

This is quite helpful. Thank you, Omar. However, I am looking into the performance benefits of only updating every stepTime and not updating in between (even though we are just returning the last swathe). So I am going to look into using the isConstant field to perhaps speed up the process.

Again, I have gotten this process to work using primitives and I have read that using primitives is quite computationally less expensive than using entities. I think I will keep using primitives but all this is quite helpful. I found there was not too much documentation on updating shape but rather just postion so all of this is good discussion.

What about this how to fix it?

// This is an example of using Cesium “Offline”, meaning disconnected from the
// external Internet. It must still be served from a local web server, but
// does not rely on any outside resources or services. For more info, see:
// Offline Guide · CesiumGS/cesium Wiki · GitHub
var viewer = new Cesium.Viewer(“cesiumContainer”, {
imageryProvider: new Cesium.TileMapServiceImageryProvider({
url: Cesium.buildModuleUrl(“Assets/Textures/NaturalEarthII”),
}),
baseLayerPicker: false,
geocoder: false,
});
var i = 0;
var b = [{
lon: 4.25832182,
lat: 51.28233363,
alt: 0
}, {
lon: 4.25824362,
lat: 51.2823683,
alt: 0
}]

var c = [
[4.25827565, 51.28237055, 4.25839278, 51.28231875, 4.258368, 51.28229672, 4.25825087, 51.28234852, 4.25827565, 51.28237055],
[4.25819675, 51.28240487, 4.25831485, 51.28235395, 4.2582905, 51.28233173, 4.25817238, 51.28238265, 4.25819675, 51.28240487]]

var entity = viewer.entities.add({
model: {
uri: “…/SampleData/models/GroundVehicle/GroundVehicle.glb”,
},
position: new Cesium.Cartesian3.fromDegrees(b[i].lon, b[i].lat, b[i].alt)
})

var polygon = viewer.entities.add({
height: 0,
polygon: {
hierarchy: new Cesium.CallbackProperty(
() =>
new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(c[i])),
true
),
material: Cesium.Color.RED,
//heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
extrudedHeight: 2.0,
}
})

setInterval(function() {
if (i < b.length) {
entity.position = new Cesium.Cartesian3.fromDegrees(b[i].lon, b[i].lat, b[i].alt)
polygon.polygon.hierarchy = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(c[i]));

    i += 1;
} else {
    i = 0
}

}, 1000);

viewer.zoomTo(viewer.entities);