Watch current position in Cesium with angular

Hi,
I'm new to Cesium, and I'm trying to get the current position.
I hooked into the viewer.scene.camera.position variable.
Here's the code:

scope.cesium.camera = viewer.scene.camera;
scope.$watchCollection(function(){
                return {
                    longitude: scope.cesium.camera.positionCartographic.longitude,
                    latitude: scope.cesium.camera.positionCartographic.latitude,
                    height: scope.cesium.camera.positionCartographic.height}
            }, function(newPositions, oldPositions){
                console.log(newPositions);
                console.log(oldPositions);
            });

It works fine tracking changes after flyToo or lookAt, but not after mouse movement (e.g. zoom, drag).

Taking a look at the camera variable itself shows the camera position doesn't change with the mouse controls. Any way to see the current view of the camera after mouse move?

I haven’t used AngularJS, but the Cesium camera positionCartographic value does correctly update in response to mouse movements.

This simple Sandcastle example logs positionCartographic on an interval. You can see that the value changes as you move around with the mouse.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

setInterval(function() {

console.log(viewer.scene.camera.positionCartographic);

}, 100);

Thanks. Your interval gave me the solution eventually.
Whenever I'm using angularjs $interval, it forces a digest, which updates my view.

What's still a mystery to me is why my $watch was not working. I tried to:

scope.cesium.viewer = new Cesium.Viewer('cesiumContainer');
$watch('cesium.viewer.scene.camera.positionCartographic', function(new, old){console.log(new); console.log(old);}, true);

It enters the function only once (on startup), gives the correct starting coordinates, and then doesn't fire when I change the coordinates.

If anyone has any idea why this isn't working, I'll appreciate it.
Thanks again :slight_smile:

Hi,
check this file in cesium directory

cesium/Apps/Sandcastle/gallery/Picking.html

this will give you current coords on mouse move.

Thanks