<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Update the camera in a 3D view | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
background-color: rgba(200, 200, 200, 0.5);
background-color: rgba(100, 100, 100, 0.8);
camera-position="7.654, 45.919, 5183"
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-compass slot="top-left"> </arcgis-compass>
<button id="rotateAntiClockwiseSpan" title="Rotate 90°">↻</button>
<button id="indicatorSpan"></button>
<button id="rotateClockwiseSpan" title="Rotate 90°">↺</button>
const [reactiveUtils] = await $arcgis.import(["@arcgis/core/core/reactiveUtils.js"]);
/*****************************************************************
* Get a reference to the Scene component
*****************************************************************/
const viewElement = document.querySelector("arcgis-scene");
await viewElement.viewOnReady();
// create the event's callback functions
const rotateView = async (direction) => {
let heading = viewElement.camera.heading;
// Set the heading of the view to the closest multiple of 90 degrees,
// depending on the direction of rotation
heading = Math.floor((heading + 1e-3) / 90) * 90 + 90;
heading = Math.ceil((heading - 1e-3) / 90) * 90 - 90;
if (error.name != "AbortError") {
const tiltView = async () => {
// Get the camera tilt and add a small number for numerical inaccuracies
let tilt = viewElement.camera.tilt + 1e-3;
// Switch between 3 levels of tilt
if (error.name != "AbortError") {
const updateIndicator = (camera) => {
let heading = camera.heading;
// Update the indicator to reflect the current tilt/heading using
const transform = `rotateX(${0.8 * tilt}deg) rotateY(0) rotateZ(${-heading}deg)`;
indicatorSpan.style["transform"] = transform;
indicatorSpan.style["-webkit-transform"] = transform; // Solution for Safari
// Register events to control
const rotateAntiClockwiseSpan = document.getElementById("rotateAntiClockwiseSpan");
const rotateClockwiseSpan = document.getElementById("rotateClockwiseSpan");
const indicatorSpan = document.getElementById("indicatorSpan");
rotateClockwiseSpan.addEventListener("click", () => {
rotateAntiClockwiseSpan.addEventListener("click", () => {
indicatorSpan.addEventListener("click", tiltView);
// Watch the change on viewElement.camera
() => viewElement.camera,
updateIndicator(viewElement.camera);