Atlaslog
Atlaslog / Examples / Cesium / Globe Translucency
Cesium · Runnable Example

Globe Translucency

Runnable Cesium example: Globe Translucency. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.

Open standalone → Chinese notes All Cesium examples
/demos/cesium-globe-translucency.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-globe-translucency.html
<!--
  示例:把地球做成半透明,看穿球体内部
  要点:globe.translucency 控制正反面透明度,undergroundColor 决定球内底色
  依赖:CesiumJS 1.121 · jsDelivr CDN,无影像与地形服务
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>半透明地球</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
  html,body{height:100%;margin:0}
  body{background:#0e1116;color:#e6e8ec;overflow:hidden;
       font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
  #c{height:100%}
  .hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.9);
       border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
       color:#a2a9b6;max-width:250px}
  .hud b{color:#e6e8ec;font-weight:600}
  .hud .row{margin-top:6px}
  input[type=range]{width:100%}
  .cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
  .cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
  <div><b>半透明地球</b></div>
  <div class="row">正面 alpha <span id="aVal">0.45</span></div>
  <div class="row"><input id="alpha" type="range" min="0" max="0.95" step="0.05" value="0.45"></div>
  <div class="row">球心处放了一个发光球体</div>
  <div class="row">对面大陆的点也能看到</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
  'use strict';

  var viewer = new Cesium.Viewer('c', {
    baseLayer: false,
    baseLayerPicker: false, geocoder: false, homeButton: false,
    sceneModePicker: false, navigationHelpButton: false,
    animation: false, timeline: false, fullscreenButton: false,
    infoBox: false, selectionIndicator: false
  });

  var scene = viewer.scene;
  scene.globe.baseColor = Cesium.Color.fromCssColorString('#2a4f73');
  scene.backgroundColor = Cesium.Color.fromCssColorString('#0b0f15');
  scene.skyBox.show = false;
  scene.sun.show = false;
  scene.moon.show = false;
  if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
  scene.globe.showGroundAtmosphere = false;

  scene.globe.translucency.enabled = true;
  scene.globe.translucency.frontFaceAlpha = 0.45;
  scene.globe.translucency.backFaceAlpha = 0.15;
  scene.globe.undergroundColor = Cesium.Color.fromCssColorString('#0f2030');

  /* 球心处的发光球:半透明地球下能直接看到 */
  viewer.entities.add({
    position: new Cesium.Cartesian3(0, 0, 0),
    ellipsoid: {
      radii: new Cesium.Cartesian3(2200000, 2200000, 2200000),
      material: Cesium.Color.fromCssColorString('#ffb13d').withAlpha(0.85)
    }
  });

  /* 球面上的点:一部分在背面,透过球体可以看到 */
  var CITIES = [
    [116.39, 39.90, '北京'],
    [-74.0, 40.7, '纽约'],
    [2.35, 48.85, '巴黎'],
    [139.69, 35.68, '东京'],
    [-46.63, -23.55, '圣保罗'],
    [151.2, -33.87, '悉尼']
  ];
  CITIES.forEach(function (c) {
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(c[0], c[1]),
      point: {
        pixelSize: 7,
        color: Cesium.Color.fromCssColorString('#eaf2ff'),
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      },
      label: {
        text: c[2],
        font: '500 12px "Microsoft YaHei", sans-serif',
        fillColor: Cesium.Color.fromCssColorString('#cfe4ff'),
        pixelOffset: new Cesium.Cartesian2(0, -16),
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    });
  });

  /* 一条贯穿球体的参考轴,强调球内空间 */
  viewer.entities.add({
    polyline: {
      positions: Cesium.Cartesian3.fromDegreesArrayHeights([-60, 0, -4200000, 120, 0, 4200000]),
      width: 1.5,
      material: new Cesium.PolylineDashMaterialProperty({
        color: Cesium.Color.fromCssColorString('#ff8f4d').withAlpha(0.7),
        dashLength: 24
      })
    }
  });

  document.getElementById('alpha').addEventListener('input', function () {
    var v = parseFloat(this.value);
    scene.globe.translucency.frontFaceAlpha = v;
    document.getElementById('aVal').textContent = v.toFixed(2);
  });

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(100, 10, 26000000),
    orientation: {
      heading: 0,
      pitch: Cesium.Math.toRadians(-72),
      roll: 0
    },
    duration: 0
  });
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.

More Cesium examples

Cesium · EXAMPLEGltf PBR Extensions Cesium · EXAMPLEGoogle Earth Enterprise Cesium · EXAMPLEGoogle Photorealistic 3D Tiles