1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| const viewer = new Cesium.Viewer("cesiumContainer", { geocoder: false, homeButton: false, navigationHelpButton: false, navigationInstructionsInitiallyVisible: false, animation: false, timeline: false, fullscreenButton: false, skyBox: false, sceneModePicker: false, baseLayerPicker: false, }); viewer.cesiumWidget.creditContainer.style.display = "none";
const scene = viewer.scene; const globe = scene.globe;
scene.screenSpaceCameraController.enableCollisionDetection = false;
const longitude = -3.82518; const latitude = 53.11728; const height = -500.0; const position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height); const url = "../SampleData/models/ParcLeadMine/ParcLeadMine.glb";
const entity = viewer.entities.add({ name: url, position: position, model: { uri: url, }, });
viewer.scene.camera.setView({ destination: new Cesium.Cartesian3( 3827058.651471591, -256575.7981065622, 5078738.238484612, ), orientation: new Cesium.HeadingPitchRoll( 1.9765540737339418, -0.17352018581162754, 0.0030147639151465455, ), endTransform: Cesium.Matrix4.IDENTITY, });
const originalColor = Cesium.Color.BLACK; const originalNearDistance = 1000.0; const originalFarDistance = 1000000.0; const originalNearAlpha = 0.0; const originalFarAlpha = 1.0;
let color = originalColor;
const viewModel = { enabled: true, nearDistance: originalNearDistance, farDistance: originalFarDistance, nearAlpha: originalNearAlpha, farAlpha: originalFarAlpha, };
Cesium.knockout.track(viewModel); const toolbar = document.getElementById("toolbar"); Cesium.knockout.applyBindings(viewModel, toolbar); for (const name in viewModel) { if (viewModel.hasOwnProperty(name)) { Cesium.knockout.getObservable(viewModel, name).subscribe(update); } }
Sandcastle.addToolbarButton("随机分配一种颜色", function () { color = Cesium.Color.fromRandom({ alpha: 1.0, }); update(); });
Sandcastle.addToolbarButton("清除", function () { color = originalColor; viewModel.enabled = true; viewModel.nearDistance = originalNearDistance; viewModel.farDistance = originalFarDistance; viewModel.nearAlpha = originalNearAlpha; viewModel.farAlpha = originalFarAlpha; update(); });
function update() { globe.undergroundColor = viewModel.enabled ? color : undefined;
let nearDistance = Number(viewModel.nearDistance); nearDistance = isNaN(nearDistance) ? originalNearDistance : nearDistance;
let farDistance = Number(viewModel.farDistance); farDistance = isNaN(farDistance) ? originalFarDistance : farDistance;
if (nearDistance > farDistance) { nearDistance = farDistance; }
let nearAlpha = Number(viewModel.nearAlpha); nearAlpha = isNaN(nearAlpha) ? 0.0 : nearAlpha;
let farAlpha = Number(viewModel.farAlpha); farAlpha = isNaN(farAlpha) ? 1.0 : farAlpha;
globe.undergroundColorAlphaByDistance.near = nearDistance; globe.undergroundColorAlphaByDistance.far = farDistance; globe.undergroundColorAlphaByDistance.nearValue = nearAlpha; globe.undergroundColorAlphaByDistance.farValue = farAlpha; }
color = Cesium.Color.LIGHTSLATEGRAY; update();
|