2021-07-22

(一)、Cesium 简单使用

使用在线资源

  1. 新建html文件
  2. 引入js文件
  3. 编写代码

例子:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <!--Cesium js文件引入 -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.83/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.83/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
 <!-- 视图显示容器 -->
  <div id="cesiumContainer"></div>
  <script>
    // 注册密钥: https://cesium.com/ion/tokens.
    // 账号密钥
    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5YjdiMzE0OC04OGE5LTQ4NGEtODZkMC1kN2U1MmMyMWYwNzIiLCJpZCI6MTYwNjUsInNjb3BlcyI6WyJsZ24iLCJwciIsImFjdyIsImFzbCIsImFzciIsImFzdyIsImFzcyIsImdjIiwibHIiLCJsdyIsInRyIiwidHciLCJ1c2ciXSwiaWF0IjoxNjI2OTYwOTM1LCJleHAiOjE2Mjc1NjU3MzV9.VcNEmfaN_fYKeuLt7mXXQg77v-SRIIP7Cy-ZsgPuj5I';

    // 初始化容器 (容器:`cesiumContainer` )
    const viewer = new Cesium.Viewer('cesiumContainer', {
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // 添加资源
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // 视图缩放至加载资源位置
    viewer.camera.flyTo({
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
 </div>
</body>
</html>
上一篇:关于python 3.8 的新特性 - PEP 570 Positional-Only Argument


下一篇:4、cesium位置初始化