I'm trying to call viewer.camera.flyTo
from within an event listener (attached to a button click), but the flyTo only works if I call it outside the event listener (i.e. on load). When I trigger it with a button click, nothing happens visually, even though there are no errors in the console.
Here is the minimal code I'm using,
import { Viewer, Cartesian3, Math } from "cesium";
document.addEventListener("DOMContentLoaded", () => {
// Create the viewer with the default render loop enabled
const viewer = new Viewer("cesiumContainer", {
useDefaultRenderLoop: true
});
// Set an initial view that's clearly different from the target
viewer.camera.setView({
destination: Cartesian3.fromDegrees(-90.0, 40.0, 15000000)
});
// Create a control button for testing flyTo
const controlsDiv = document.getElementById("controls");
if (!controlsDiv) return;
controlsDiv.innerHTML = "";
const moveToDebugBtn = document.createElement("button");
moveToDebugBtn.textContent = "Fly To Debug Entity";
controlsDiv.appendChild(moveToDebugBtn);
// This is the code that doesn't work
moveToDebugBtn.addEventListener("click", () => {
console.log("calling flyTo with orientation...");
viewer.camera.flyTo({
destination: Cartesian3.fromDegrees(-117.16, 32.71, 15000.0),
orientation: {
heading: Math.toRadians(0),
pitch: Math.toRadians(-45),
roll: 0
},
duration: 3
});
});
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743744506a4499758.html
评论列表(0条)