【超图+CESIUM】【基础API使用示例】38、超图|CESIUM - 特效-云层设置

前言

	缺少前置学习使用资料,请自行查阅:[https://blog.csdn.net/weixin_44402694/article/details/123110136](https://blog.csdn.net/weixin_44402694/article/details/123110136)
	以下示例使用到的公共静态资料,不建议下载,建议官网自行下载超图Build资源,示例所涉及图片会在示例使用到时提供出来。如有需要可下载:[https://download.csdn.net/download/weixin_44402694/82180350](https://download.csdn.net/download/weixin_44402694/82180350)。
	特效-云层设置。

使用

  • 效果
    在这里插入图片描述
    在这里插入图片描述

  • 完整代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>特效 - 云层设置</title>
    <link href="./public/Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
    <script
      type="text/javascript"
      src="./public/Build/Cesium/Cesium.js"
    ></script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      html,
      body,
      #cesium-container {
        width: 100%;
        height: 100%;
      }
      .panel {
        position: fixed;
        left: 10px;
        top: 10px;
        z-index: 1;
        background-color: #fff;
        padding: 10px;
      }
      .panel .btn {
        cursor: pointer;
        display: none;
      }
      .panel .check {
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div id="cesium-container" />
    <div class="panel">
      <p class="check">开启云层 <input type="checkbox" /></p>
      <p class="btn">云层纹理1</p>
      <p class="btn">云层纹理2</p>
    </div>
    <script>
      let viewer, cloudBox
      window.onload = function () {
        viewer = new Cesium.Viewer('cesium-container', {
          sceneModePicker: true,
          navigation: false,
        })
        initCreateCloudBoxHandler()
        initBindDrawEventHandler()
      }

      // 初始化绑定按钮的绘制事件
      function initBindDrawEventHandler() {
        const check = document.querySelector('.check input')
        const btns = document.querySelectorAll('.panel .btn')
        check.addEventListener('change', () => {
          Array.from(btns).forEach((btn) => {
            btn.style.display = check.checked ? 'block' : 'none'
          })
          if (check.checked) {
            // 开启云层
            viewer.scene.cloudBox = cloudBox
            // 默认高亮云层纹理1
            viewer.scene.cloudBox.url =
              'http://support.supermap.com.cn:8090/webgl/examples/webgl/images/clouds-supermap-sm.png'
            activeCurrentClickBtnHandler(0)
          } else {
            viewer.scene.cloudBox = null
          }
        })
        btns[0].addEventListener('click', () => {
          activeCurrentClickBtnHandler(0)
          viewer.scene.cloudBox.url =
            'http://support.supermap.com.cn:8090/webgl/examples/webgl/images/clouds-supermap-sm.png'
        })
        btns[1].addEventListener('click', () => {
          activeCurrentClickBtnHandler(1)
          viewer.scene.cloudBox.url =
            'http://support.supermap.com.cn:8090/webgl/examples/webgl/images/clouds.png'
        })
      }
      // 初始化创建云层box
      function initCreateCloudBoxHandler() {
        cloudBox = new Cesium.CloudBox({
          url: 'http://support.supermap.com.cn:8090/webgl/examples/webgl/images/clouds-supermap-sm.png',
        })
      }

      // 高亮当前点击的按钮
      function activeCurrentClickBtnHandler(idx) {
        const btns = document.querySelectorAll('.panel .btn')
        Array.from(btns).forEach((btn, index) => {
          btn.style.color = index === idx ? 'red' : '#000'
        })
      }
    </script>
  </body>
</html>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值