Compass / Navigator

Hi,

Is it possible to add a compass navigator to show which way is North or NSEW, etc. on the Cesium viewer?

PS - I have tried viewer Cesium Navigation (3rd party) but that is not working out for me. Getting some JS errors. Wondering if Cesium JS has a native support for this feature?

Thanks,

Sincerely,

Qasim

Sure, here’s the most important part where you pull the heading from the camera, the rest is just visual candy you can build out of Cesium, or SVG or HTML anywhere you like;

var heading = ( viewer.camera.heading * 180 / Math.PI ).toFixed(1);

This gives you the camera heading in degrees with 1 point resolution. Look up, for example, SVG circle with a line through it at [heading] degrees. I find most available solutions a bit over the top so I roll my own to make it snappy.

Happy coding.

Cheers,

Alex

Thanks for the helpful suggestion. Building on your proposal, do you know what Cesium event is fired / or what event to trap when the view is moved around so that the heading can be updated constantly with the changing view?

EDIT: I read online to play around with viewer.camera.changed.addEventListener. I shall give that a try.

Thanks.