How to correctly remove a Cesium polyline

1.3k views Asked by At

I have just been starting in Cesium, and I have been trying to plot pushed data. To do this, I have been displaying the track with a billboard and the historical info with a polyline. However, in some instances, the polylines remain on the viewer even though the entity has been removed.

In order to create/update the entity I call ( where track is an object containing the state information for a spesific track, and position is a Cartesian3 object)

function updateTrack(track, position) {
    var entity = map.entities.getById(track.id);
    if (Cesium.defined(entity)) {
        entity.billboard.show = (track.curr && showTracks);
        entity.position = position;
        var heading = Math.atan2(track.vy, track.vx);
        entity.billboard.rotation = heading - Math.PI / 2;

        var polyLineposs = entity.polyline.positions._value;
        polyLineposs.push(position);
        entity.polyline.positions = polyLineposs;
        entity.polyline.show = showTrails;
    }
    else {
        var heading = Math.atan2(track.vy, track.vx);
        map.entities.add(new Cesium.Entity({
            id: track.id,
            position: position,
            parent: trackEntity_parent,
            billboard: { image: trackIconHref, scale: 0.1, rotation: (heading - Math.PI / 2), show: showTracks },
            polyline: { width: 5, material: trailMaterial, positions: [position], show: showTrails }
        }));
    }
}

The remove function is as follows:

function removeTracksAndTrails(oldTracks) {

    //remove any outdated tracks and trails
    for (var i = 0; i < oldTracks.length; i++) {
        var trackToRemove = map.entities.getById(oldTracks[i]);
        //trackToRemove.polyline = undefined;
        map.entities.remove(trackToRemove);
    }
}

I have also read a suggestion in another post, however, this looks like a far more complicated solution with the integration of timing necessary. Is this approach recommended as apposed to the straightforward polyline?

Thanks!

Update: It would appear that this only occurs when "trailMaterial" is a PolylineOutlineMaterialProperty, i.e. when the material is a Cesium.Color object the issue no longer occurs.

0

There are 0 answers