Change camera event

Hi!

Is there a method to know if camera properties changed? I mean, if the user has moved the map, zoom, or has changed view?

Thanks!

The camera can change all of the time, ideally you would only want to be notified once a frame with the camera being used to actually render the scene. The best way to do this is to store a copy of the camera in your render loop and check it every frame. For example:

var cesiumWidget = viewer.cesiumWidget;

var camera = cesiumWidget.scene.getCamera();

var lastCamera = camera.clone();

cesiumWidget.clock.onTick.addEventListener(function() {

if (!camera.position.equals(lastCamera.position) ||

!camera.direction.equals(lastCamera.direction) ||

!camera.up.equals(lastCamera.up) ||

!camera.right.equals(lastCamera.right) ||

!camera.transform.equals(lastCamera.transform) ||

!camera.frustum.equals(lastCamera.frustum)) {

console.log(‘camera movied’);

lastCamera = camera.clone();

}

});

The problem here is that you are going to get hundreds of changed events. Things like camera inertia means the camera is going to change by minute amounts for a few seconds after you. In order to combat this, I would recommend changing the above to use equalsEpsilon, and then pass an epsilon amount large enough so that you don’t get constant changes, but small enough that you don’t miss anything. Of course if what you are doing really does depend on the exact camera position, then taking action every changed event is perfectly acceptable.

Hope this helps.

Thank you, Matthew

I did exactly it. I thought there was an event to fire when the camera change.