自定义图元

自定义几何图元、光锥、三维热力图、路径漫游与路线规划。下面是该示例的核心 script 片段,供参考学习;完整可运行代码请进入在线 Demo 或查看仓库源码。

在线运行 Demo 全部示例 查看完整源码

示例代码

import * as Cesium from 'cesium'
import { initCesium } from '@/utils/cesiumPluginsExtends/index'

export default {
  mounted () {
    this.initMap()
  },
  methods: {
    async initMap () {
      const { viewer,
        primitive,
        base
      } = new initCesium(
        {
          cesiumGlobal: Cesium,
          containerId: 'cesiumContainer',
          viewerConfig: {
            infoBox: false,
            shouldAnimate: true,
          },
          extraConfig: {
            depthTest: true
          },
          MapImageryList: []
        })


      this.c_viewer = viewer;
      this.primitiveObj = primitive;
      let tiles = await Cesium.Cesium3DTileset.fromUrl('static/data/3DTiles/building/tileset.json');
      let tileset = this.c_viewer.scene.primitives.add(tiles)
      tileset.style = new Cesium.Cesium3DTileStyle({
        color: {
          conditions: [
            ['${height} >= 300', 'rgba(0, 149, 251, 0.3)'],
            ['${height} >= 200', 'rgb(0, 149, 251, 0.3)'],
            ['${height} >= 100', 'rgb(0, 149, 251, 0.3)'],
            ['${height} >= 50', 'rgb(0, 149, 251, 0.3)'],
            ['${height} >= 25', 'rgb(0, 149, 251, 0.3)'],
            ['${height} >= 10', 'rgb(0, 149, 251, 0.3)'],
            ['${height} >= 5', 'rgb(0, 149, 251, 0.3)'],
            ['true', 'rgb(0, 149, 251, 0.3)'],
          ],
        },
      })
      let custPrim = this.primitiveObj.customPrimivive({
        center: [104.0737048186066, 30.634227553819127],
        height1: 0,
        height2: 20,
        scale: 0.00006,
        img: 'static/data/images/Textures/beautiful.jpg'
      })
      this.c_viewer.scene.primitives.add(custPrim)

      base.flyTo({
        position: {
          x: -1335718.3738141463,
          y: 5327996.272508891,
          z: 3230971.826570713,
        },
        orientation: {
          heading: 6.153234780255776,
          pitch: -0.2083363211445124,
          roll: 0.0000016515446423781555
        },
        duration: 3
      })
    },
  },
  beforeUnmount () {
    this.c_viewer = null;
    this.primitives = null;
  }
}

相关 API

安装:npm install cesium_dev_kit cesium