This sample demonstrates how to create an animated tour of the slides in a WebScene by using the applyTo() method. apply
returns a promise that resolves after the slide has been applied to the view. By chaining the apply
method of the slides, we can play through all the slides without user input.
The chaining is done with a recursive function:
// slides is the array of slides from the webscene
const slides = scene.presentation.slides;
function goToSlide(i) {
const slide = slides.getItemAt(i);
if (i < slides.length) {
infoDiv.innerHTML = slide.title.text;
// call the applyTo method on the current slide
slide
.applyTo(view, { duration: 3000 })
// and after the slide was applied to the view wait for 8 seconds
// and then call goToSlide for the next slide
.then(() => {
window.setTimeout(() => {
goToSlide(i + 1);
}, 8000);
});
}
}
// go to the first slide - this function triggers the chaining
goToSlide(1);