全部代码
<template><div id="cesiumContainer" style="height: 100vh;"></div><div id="toolbar" style="position: fixed;top:20px;left:220px;"><el-breadcrumb :separator-icon="ArrowRight"><el-breadcrumb-item>三维分析</el-breadcrumb-item><el-breadcrumb-item>可视区域分析</el-breadcrumb-item></el-breadcrumb><el-row class="mb-4" style="margin-top: 15px"><el-button type="primary" @click="shootAreaAnalysis">分析</el-button><el-button type="primary" @click="handleIntervisibilityCancel">清除</el-button></el-row></div>
</template>
<script setup>
import {ArrowRight} from '@element-plus/icons-vue'
import {onMounted, ref} from "vue";
import * as Cesium from "cesium";
import InitCesium from "../js/InitCesiumHide.js";
import ViewShed from "../js/8/ViewShed.js";let viewer = null;onMounted(() => {let initCesium = new InitCesium('cesiumContainer');viewer = initCesium.initViewer({});flyToRight2();
})const shootAreaAnalysis = (type) => {// store.setSelected('shootArea')let i = 0let horizontalViewAngle = 90 //视角水平张角let verticalViewAngle = 60 //视角垂直张角let endPosition = nulllet viewShed = nulllet handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)handler.setInputAction(movement => {i++if (i === 1) {var startPosition = viewer.scene.pickPosition(movement.position) //鼠标点击一次获取开始坐标if (!startPosition) returnviewShed = new ViewShed(viewer, {viewPosition: startPosition,viewPositionEnd: startPosition,horizontalViewAngle: horizontalViewAngle,verticalViewAngle: verticalViewAngle})// 鼠标移动的事件handler.setInputAction(movement => {endPosition = viewer.scene.pickPosition(movement.endPosition)if (!endPosition) returnviewShed.updatePosition(endPosition)if (!viewShed.sketch) {viewShed.drawSketch()}}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)}// 鼠标点击两次获取结束坐标if (i === 2) {i = 0endPosition = viewer.scene.pickPosition(movement.position)viewShed.updatePosition(endPosition)viewShed.update()handler && handler.destroy() //销毁鼠标事件// store.setSelected(null)}}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
}const flyToRight2 = async () => {let tileset = await Cesium.Cesium3DTileset.fromUrl('/src/assets/tileset/12/tileset.json', {});update3dtilesMaxtrix(tileset);viewer.scene.primitives.add(tileset);viewer.flyTo(tileset);/*viewer.camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(113.06408124924124, 22.64479293609514, 800.0), // 设置位置orientation: {heading: Cesium.Math.toRadians(20.0), // 方向pitch: Cesium.Math.toRadians(-90.0),// 倾斜角度roll: 0},duration: 5, // 设置飞行持续时间,默认会根据距离来计算