Sandcastle-header.js存盤在Cesium中Apps/Sandcastle/Sandcastle-header.js的位置,該js檔案時用于創建下拉框和帶選中框的按鈕,引入該檔案后,就會有一個Sandcastle全域物件,包含著很多方法, // videoElement = document.getElementById("trailer"); videoElement = "../images/_DSC0718-239.jpg";(視頻匯入有問題,嘗試用圖片替代,完成替代) Cesium.Ion.defaultAccessToken = "token"; const viewer = new Cesium.Viewer("cesiumContainer", { showRenderLoopErrors: false, //如果為 true,如果出現渲染回圈錯誤, //此小部件將自動向用戶顯示包含錯誤的 HTML 面板, shouldAnimate: true, }); const sphere = viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees( 104, 31.75, 1000 //高度 可選 米為單位 ), //從以度為單位的經度和緯度值回傳 Cartesian3 位置, ellipsoid: { radii: new Cesium.Cartesian3(1000, 1000, 1000), //指定橢球半徑的 Cartesian3 屬性, material: videoElement, }, }); viewer.trackedEntity = sphere; //獲取或設定相機當前正在跟蹤的物體實體,
let synchronizer;
Sandcastle.addToggleButton( //外部檔案引入用于進行ui設計 "Clock synchronization", false, function (checked) { if (Cesium.defined(synchronizer)) { synchronizer = synchronizer.destroy(); videoElement.playbackRate = 1.0; return; } synchronizer = new Cesium.VideoSynchronizer({ clock: viewer.clock, element: videoElement, }); } ); let isRepeating = true; Sandcastle.addToggleButton( "Image Repeat", isRepeating, function (checked) { isRepeating = checked; } );
sphere.ellipsoid.material.repeat = new Cesium.CallbackProperty(function ( time, result ) { if (!Cesium.defined(result)) { result = new Cesium.Cartesian2(); } if (isRepeating) { result.x = 8; result.y = 2; } else { result.x = 1; result.y = 1; } return result; }, false);
// Like Image, the video element doesn't have to be part of the DOM or // otherwise on the screen to be used as a texture. Sandcastle.addToggleButton("Video Overlay", true, function (checked) { if (checked) { videoElement.style.display = ""; } else { videoElement.style.display = "none"; } });
// Older browsers do not support WebGL video textures, // put up a friendly error message indicating such. viewer.scene.renderError.addEventListener(function () { if (!videoElement.paused) { videoElement.pause(); } viewer.cesiumWidget.showErrorPanel( "This browser does not support cross-origin WebGL video textures.", "", "" ); });
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/549251.html
標籤:其他
