How to prevent reset of camera after initializing trackedEntity?

1,109 views
Skip to first unread message

Qandeel Abbassi

unread,
Feb 19, 2017, 10:26:10 AM2/19/17
to cesium-dev
First I flyTo a location with particular orientation. When the camera animation completes I start animating a pin on a polyline and set viewer.trackedEntity = mypin so the camera starts tracking that pin but the problem is that it also resets my camera orientation which i specified in flyTo. Its exactly above the pin and too much zoomed in. How should I solve this problem? Here is the code:

var entity = viewer.entities.add({
          name: 'Start',
          position: cartesianArray[0],
          billboard: {
            image: Cesium.buildModuleUrl('Assets/Textures/redpin.png'),
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            scale: 0.6
          }
        });
viewer.camera.flyTo({
        destination: cartesianArray[0],
        orientation:{
          pitch : Cesium.Math.toRadians(-40),
        },
        complete: function(){
          viewer.trackedEntity = entity;
          startAnimation();// pin animates on polyline
        },
      });


Hannah Pinkos

unread,
Feb 20, 2017, 8:24:02 AM2/20/17
to cesium-dev
Hello,

You can try using the viewFrom property on the entity.  This is a Cartesian3 property that specifies the position from which the entity should be viewed http://cesiumjs.org/Cesium/Build/Documentation/Entity.html#viewFrom

This is a bit of a complicated problem, you can see the discussion in this thread: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/a8bwwV3BYuE
We also have this GitHub issue written up to try to find a solution for this: https://github.com/AnalyticalGraphicsInc/cesium/issues/3653

Best,

Hannah

Qandeel Abbassi

unread,
Feb 28, 2017, 5:42:32 PM2/28/17
to cesium-dev
Hello Hannah,
I have already tried viewFrom property and it didn't help. When flyTo completes it snaps back to entity's position ignoring viewFrom property. But i have found a workaround for this problem while experimenting and I am attaching the code in case anybody else faces the same problem:
 var entity = viewer.entities.add({
  name: 'Start',
  // viewFrom:  new Cesium.Cartesian3(0,0,10000),
  position: cartesianArray[0],
  billboard: {
  image: Cesium.buildModuleUrl('Assets/Textures/ic_current_loc.png'),
  verticalOrigin: Cesium.VerticalOrigin.CENTER,
  horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  scale: 0.5
  }
 });



 viewer.trackedEntity = entity;
 viewer.camera.flyToBoundingSphere(new Cesium.BoundingSphere(cartesianArray[0], 10), {
  offset: new Cesium.HeadingPitchRange(0.0, Cesium.Math.toRadians(-25), 1000),
  complete: function() {
  viewer.clock.onTick.addEventListener(function(clock) {
  viewer.camera.lookAtTransform(viewer.camera.transform, new Cesium.HeadingPitchRange(viewer.camera.heading + 0.003, Cesium.Math.toRadians(-25), 1000));
  //console.log(viewer.camera.transform);
  });
  tick();
  },
 });
 The tick() is actually the function which animates the position of the entity. This way i can set heading, pitch, and zoom according to my wish. 
Note: The onTick event listener is just there to rotate my camera by 0.003, so it keeps rotating. If you don't want it then you can remove it.

yura....@gmail.com

unread,
Sep 4, 2018, 7:55:15 AM9/4/18
to cesium-dev
I am using this approach
....
// save
savedView.offset = viewer.scene.camera.position.clone();
....
// restore
viewer.trackedEntity._viewFrom._value = savedView.offset;

Left Gully

unread,
Sep 4, 2018, 8:04:34 PM9/4/18
to cesium-dev
Yura-
Yes, i had that issue and solved it by using the 4/14/2017 "chasecam" function example posted by Matt in this thread:
https://groups.google.com/forum/m/#!topic/cesium-dev/-mDNh2qlTZQ
instead of using trackedEntity. The chasecam aporoach retained the camera heading-pitch-roll that I had set before loading the entity.
Reply all
Reply to author
Forward
0 new messages