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
| const viewer = new Cesium.Viewer("cesiumContainer", { geocoder: false, sceneModePicker: false, homeButton: false, navigationHelpButton: false, baseLayerPicker: false, navigationInstructionsInitiallyVisible: false, fullscreenButton: false, selectionIndicator: false, skyBox: false, timeline: false, animation: false, shouldAnimate: true, terrain: Cesium.Terrain.fromWorldTerrain({ requestVertexNormals: true, requestWaterMask: true, }), });
viewer.cesiumWidget.creditContainer.style.display = "none";
const customElevationMaterial = new Cesium.Material({ fabric: { type: "ElevationLand", materials: { waterMaskMaterial: { type: "WaterMask", }, elevationRampMaterial: { type: "ElevationRamp", }, }, components: { diffuse: "elevationRampMaterial.diffuse", alpha: "1.0 - waterMaskMaterial.alpha", }, }, translucent: false, });
const minHeight = -414.0; const maxHeight = 8777.0; const elevationRamp = [0.0, 0.045, 0.45, 0.5, 0.55, 1.0]; function getColorRamp() { const ramp = document.createElement("canvas"); ramp.width = 100; ramp.height = 1; const ctx = ramp.getContext("2d");
const values = elevationRamp;
const grd = ctx.createLinearGradient(0, 0, 100, 0);
grd.addColorStop(values[0], "#344f31"); grd.addColorStop(values[1], "#5b8742"); grd.addColorStop(values[2], "#e6daa5"); grd.addColorStop(values[3], "#fdc771"); grd.addColorStop(values[4], "#b99d89"); grd.addColorStop(values[5], "#f0f0f0");
ctx.fillStyle = grd; ctx.fillRect(0, 0, 100, 1);
return ramp; }
const globe = viewer.scene.globe; const material = customElevationMaterial; const shadingUniforms = material.materials.elevationRampMaterial.uniforms; shadingUniforms.minimumHeight = minHeight; shadingUniforms.maximumHeight = maxHeight; shadingUniforms.image = getColorRamp();
globe.material = material;
globe.showWaterEffect = false; globe.enableLighting = true; globe.maximumScreenSpaceError = 0.5;
const scene = viewer.scene; scene.light = new Cesium.DirectionalLight({ direction: new Cesium.Cartesian3(1, 0, 0), });
const scratchNormal = new Cesium.Cartesian3(); scene.preRender.addEventListener(function (scene, time) { const surfaceNormal = globe.ellipsoid.geodeticSurfaceNormal( scene.camera.positionWC, scratchNormal ); const negativeNormal = Cesium.Cartesian3.negate(surfaceNormal, surfaceNormal);
scene.light.direction = Cesium.Cartesian3.normalize( Cesium.Cartesian3.add(negativeNormal, scene.camera.rightWC, surfaceNormal), scene.light.direction ); });
|