扇形扫描

雷达扫描、卫星扫描、圆形/扇形/锥形扫描与矩阵控制。下面是该示例的核心 script 片段,供参考学习;完整可运行代码请进入在线 Demo 或查看仓库源码。

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

示例代码

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

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

      this.c_viewer = viewer

      this.material = material
      this.graphics = graphics
      this.material.setDefSceneConfig()
      this.material.setBloomLightScene()
      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)"]
          ]
        }
      })

      this.c_viewer.flyTo(tileset)

      this.createAEllipsoid();
      this.createAFanShape();
    },
    createCustMaterialWall (imgUrl, colorVal, durationNum, countNum, directionStr) {
      return this.material.getCustomMaterialWall({
        image: imgUrl,
        freely: 'cross',
        direction: directionStr || '+',
        count: countNum,
        color: colorVal,
        duration: durationNum
      })
    },
    // 创建椭圆体
    createAEllipsoid () {
      var position = Cesium.Cartesian3.fromDegrees(
        104.06417395476578,
        30.636185094244944
      )
      var ellipsoid = this.graphics.getEllipsoidGraphics({
        radii: 700,
        material: Cesium.Color.AQUAMARINE.withAlpha(0.3),
        outline: true,
        outlineColor: Cesium.Color.AQUAMARINE.withAlpha(0.5),
      })
      let three2 = this.c_viewer.entities.add({
        name: 'oneEllipsoid',
        position: position,
        ellipsoid: ellipsoid
      });

    },
    // 创建一个扫描扇形
    createAFanShape () {
      /**
        * @param {Object} viewer cesium 视图对象
        * @param {Material} custMaterial 自定义材质
        * @param {Number} speed 运动速度(为0停止扫描)
        * @param {Number} longitude 纬度
        * @param {Number} latitude 经度
        * @param {Number} alt 高度(z轴)
        * @param {String} direction 扫描方向("-"顺时针,"+"逆时针)
       */
      const fanEntity = this.graphics.createFanShape({
        viewer: this.c_viewer,
        longitude: 104.06417395476578,
        latitude: 30.636185094244944,
        alt: 700,
        speed: 2.0,
        direction: '+',
        // custMaterial: Cesium.Color.AQUAMARINE.withAlpha(0.5)
        custMaterial: this.createCustMaterialWall(
          'static/data/images/Textures/b2.png',
          Cesium.Color.GOLD,
          2000,
          1.0,
          '+'
        )
      })
    }
  },
  beforeUnmount () {
    this.c_viewer = null;
    this.material = null;
    this.graphics = null;
  }
}

相关 API

安装:npm install cesium_dev_kit cesium