Atlaslog
Atlaslog / Examples / Cesium / I3s Building Scene Layer
Cesium · Runnable Example

I3s Building Scene Layer

Runnable Cesium example: I3s Building Scene Layer. 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-i3s-building-scene-layer.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-i3s-building-scene-layer.html
<!--
  示例:建筑场景图层
  说明:一栋楼分四个子图层,点击楼层可单独隐藏或显示
  核心逻辑:分组实体 → 点击拾取楼层 → 切换楼层 show
  依赖: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%}
  .tip{position:absolute;left:12px;top:12px;z-index:5;
       background:rgba(23,28,35,.9);border:1px solid #2a313b;border-radius:6px;
       padding:8px 12px;font-size:12px;color:#a2a9b6;max-width:320px;line-height:1.6}

  .info{position:absolute;right:12px;top:12px;background:rgba(23,28,35,.92);
        border:1px solid #2a313b;border-radius:6px;padding:8px 12px;font-size:12px;color:#cfe2f5}
  .cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
  .cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="tip">点击任意一层会把该层抽出来,再点一次恢复。</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('#1c2733');
  scene.backgroundColor = Cesium.Color.fromCssColorString('#0e1116');
  scene.skyBox.show = false;
  scene.sun.show = false;
  scene.moon.show = false;
  if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;

  var floors = [];
  var baseLon = 116.3895, baseLat = 39.9035;

  for (var f = 0; f < 6; f++) {
    var parent = viewer.entities.add(new Cesium.Entity());
    for (var k = 0; k < 6; k++) {
      viewer.entities.add({
        parent: parent,
        position: Cesium.Cartesian3.fromDegrees(
          baseLon + (k % 3) * 0.00042 - 0.00042,
          baseLat + Math.floor(k / 3) * 0.00040 - 0.00020,
          f * 7 + 3.5
        ),
        box: {
          dimensions: new Cesium.Cartesian3(38, 36, 6.6),
          material: Cesium.Color.fromCssColorString(
            ['#5b6f86', '#657a92', '#6f859e'][f % 3]
          ).withAlpha(0.96)
        }
      });
    }
    floors.push(parent);
  }

  var info = document.createElement('div');
  info.className = 'info';
  info.style.display = 'none';
  document.body.appendChild(info);

  var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  handler.setInputAction(function (click) {
    var picked = scene.pick(click.position);
    if (!Cesium.defined(picked) || !picked.id) return;

    /* 找到被点实体所属的楼层分组 */
    var target = picked.id;
    while (target && floors.indexOf(target) === -1) { target = target.parent; }
    if (!target) return;

    floors.forEach(function (p) { p.show = (p === target); });
    info.style.display = 'block';
    info.textContent = '第 ' + (floors.indexOf(target) + 1) + ' 层 · 6 个构件';
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.3856, 39.8998, 150),
    orientation: { heading: Cesium.Math.toRadians(35), pitch: Cesium.Math.toRadians(-12), 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 · EXAMPLEI3s Feature Picking Cesium · EXAMPLEI3s Integratedmesh Layer Cesium · EXAMPLEImage Based Lighting