How to change camera zoom, heading and pitch while tracking an entity?

I am using following code to animate a polyline and a pin on a given path:

viewer.trackedEntity = entity;

function tick() {

iterator++;

console.log(“tick”);

var strt_pos = positions[positions.length-1];

var end_pos = Cesium.Cartesian3.fromDegrees(cods[iterator][0],cods[iterator][1]);

var cart_strt_pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(strt_pos);

var cart_end_pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(end_pos);

var geodesic = new Cesium.EllipsoidGeodesic(cart_strt_pos, cart_end_pos, ellipsoid);

var duration = geodesic.surfaceDistance/800;

duration*=1000.0;

interpolate(performance.now(),duration, geodesic);

}

function interpolate(startTime, duration, geodesic){

var now = performance.now();

var t = Math.min(1.0, (now - startTime) / duration);

console.log(“intr”);

var cart = geodesic.interpolateUsingFraction(t);

var newpos = Cesium.Ellipsoid.WGS84.cartographicToCartesian(cart);

positions.push(newpos);

polyline.positions = positions;

entity.position = newpos;

if(t<1){

setTimeout(function() { interpolate(startTime, duration, geodesic); }, 16);

}else{

tick();

}

}

setTimeout(function() { tick(); }, 3000);

``

As you can see i have set viewer.trackedEntity=entity and enity is actually my pin (Billboard), therefore my camera is following it correctly. But the problem is that i want to change zoom, heading, and pitch of the camera at my wish. I tried different solution but to no avail. The problems i faced are:

  • viewer.camera.zoomOut() doesn’t work
  • and even if i set properties of camera using viewer.camera.setView prior to calling tick() function, the camera resets itself to default tracking orientation.
    How should I change camera zoom, heading, pitch and may be roll while tracking entity?