Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cesium JS Save Camera Position

I'm thinking of saving a camera position (specifically rotation) so changing back and forth between 2D and 3D will always go back to my last viewed position in 3D. What is the best way to do this?

I would also like to save it as a cookie or in local storage so that the user would go straight into that saved view on the page with Cesium from other pages (which may not be the US).

like image 672
bcm Avatar asked Mar 08 '14 10:03

bcm


1 Answers

I would recommend just creating a simple JS object and storing the properties of the camera before you switch views. Then just store it into localStorage. I find store.js a really useful wrapper for browser agnostic local storage.

If you need more help I can come up with an example later tonight.

    var camera = $scope.viewer.scene.camera;
    var store = {
      position: camera.position.clone(),
      direction: camera.direction.clone(),
      up: camera.up.clone(),
      right: camera.right.clone(),
      transform: camera.transform.clone(),
      frustum: camera.frustum.clone()
    };
like image 180
Mike LP Avatar answered Sep 19 '22 23:09

Mike LP