You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GCSGUI/src/components/map/SceneViewer.vue

84 lines
2.5 KiB
Vue

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!--
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-07 14:15:35
* @LastEditors: cbwu
* @LastEditTime: 2024-04-12 09:22:20
* @Description:
-->
<template>
<div id="cesium-viewer" ref="viewerDivRef"></div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { Viewer, Ion, Cartesian3, CustomDataSource, Color } from 'cesium'
import 'cesium/Build/Cesium/Widgets/widgets.css'
import {
TDTLayerType,
TDTProjectionType,
getTDTProvider,
getTDTTerrainProvider,
} from '@/utils/map/TDTProvider'
import { initViewer, perfViewer, showNavigator } from '@/utils/map/sceneViewer'
import { flyToChina } from '@/utils/map/camera'
import CreatePolyline from '@/utils/map/draw/drawPolyline'
// import DrawPoint from '@/utils/map/draw/drawPoint'
import { DrawPolygon } from '@/utils/map/draw/drawPolygon'
const viewerDivRef = ref<HTMLDivElement>()
let viewer: Viewer
window.CESIUM_BASE_URL = 'node_modules/cesium/Build/Cesium/'
// window.CESIUM_BASE_URL = 'libs/cesium/' //打包部署
Ion.defaultAccessToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3YjU4MjJlMS0wMWE4LTRhOWQtYjQ1OC04MTgzMzFhMzQ5ZjAiLCJpZCI6MTE1ODUxLCJpYXQiOjE2NjkyMDM1MzN9.8ajEuv3VKYg8wvFiQlUWWY6Ng6JfY4PuVgRyStL1B-E'
// 修改相机的默认矩形范围
// window.Cesium.Camera.DEFAULT_VIEW_RECTANGLE =
// window.Cesium.Rectangle.fromDegrees(
// 75.0, // 西经
// 0.0, // 南纬
// 140.0, // 东经
// 60.0, // 北纬
// )
onMounted(() => {
//初始化
viewer = initViewer(viewerDivRef.value as HTMLElement)
// 性能优化
perfViewer(viewer)
// 定位到中国
flyToChina(viewer)
// 显示罗盘和比例尺
showNavigator(viewer)
//添加天地图影像
viewer.imageryLayers.addImageryProvider(
getTDTProvider(TDTLayerType.Img, TDTProjectionType.WebMercator),
)
//添加天地图影像注记
viewer.imageryLayers.addImageryProvider(
getTDTProvider(TDTLayerType.Cia, TDTProjectionType.WebMercator),
)
// 添加三维地形服务
viewer.terrainProvider = getTDTTerrainProvider()
// 标记点图层,存储所有地标点
const markerLayer = new CustomDataSource('Marker')
viewer.dataSources.add(markerLayer)
// 挂载在window供全局组件共享
window.viewer = viewer
//绘制多边形
// const drawPolyline = new CreatePolyline(viewer)
// drawPolyline.start()
const drawPolygon = new DrawPolygon(viewer)
drawPolygon.start()
})
</script>
<style scoped>
#cesium-viewer {
width: 100%;
height: 100%;
}
</style>