Files
global-navigation-satellite…/src/render/components/EarthView.vue

99 lines
3.2 KiB
Vue
Raw Normal View History

2021-09-14 07:31:59 +08:00
<template>
2021-12-22 18:46:05 +08:00
<vc-viewer class="vc-viewer" :animation="true" :showCredit="false" :shouldAnimate="true" :sceneModePicker="true" @ready="onViewerReady" @trackedEntityChanged="onTrackedEntityChanged">
2021-09-14 07:31:59 +08:00
<vc-layer-imagery>
2021-12-22 18:46:05 +08:00
<vc-provider-imagery-singletile
:url="earth"
></vc-provider-imagery-singletile>
2021-09-14 07:31:59 +08:00
</vc-layer-imagery>
<vc-navigation :offset="[10, 40]" :position="'top-left'" :printOpts="false" :locationOpts="false" :otherOpts="false" />
<vc-datasource-czml v-if="czml" :czml="czml" @ready="onDataSourceReady" />
</vc-viewer>
</template>
2021-12-22 18:46:05 +08:00
<script lang="ts" setup>
import { ref, computed, watch } from 'vue'
2021-09-14 07:31:59 +08:00
import { useStore } from 'vuex'
import { VcViewer, VcLayerImagery, VcProviderImageryTianditu, VcNavigation, VcDatasourceCzml } from 'vue-cesium'
2021-12-22 18:46:05 +08:00
// import 'vue-cesium/dist/index.css'
import earth from '../assets/earth.jpg'
2021-12-22 19:32:34 +08:00
import entity from '../api/entity'
2021-12-22 18:46:05 +08:00
const store = useStore()
const czml = computed(() => './CZML/' + store.state.satelliteSystem.name + '.czml')
let entities = null
const getEntityById = id => {
if (!entities) return null
return entities.find(entity => entity.id === id)
}
const onDataSourceReady = ({ viewer, cesiumObject }) => {
viewer.flyTo(cesiumObject)
2021-12-22 19:32:34 +08:00
entity.load(cesiumObject.entities.values)
2021-12-22 18:46:05 +08:00
// 显示卫星导航系统的科普信息
2021-12-22 19:32:34 +08:00
viewer.selectedEntity = entity.find('Constellation')
2021-12-22 18:46:05 +08:00
}
2021-12-22 19:32:34 +08:00
let vcViewerInstance = null
// const trackedSatelliteId = computed(() => store.state.trackedSatellite.id)
// watch(trackedSatelliteId, (value) => {
// const entity = getEntityById(value)
// if (!entity || !vcViewerInstance) return
// vcViewerInstance.selectedEntity = entity
// vcViewerInstance.trackedEntity = entity
// })
2021-12-22 18:46:05 +08:00
// 显示/隐藏卫星
store.subscribe(({ type, payload }) => {
if (type === 'satellites/toggleShow') {
2021-12-22 19:32:34 +08:00
const satellite = entity.get(payload)
if (!satellite) return
2021-12-22 18:46:05 +08:00
2021-12-22 19:32:34 +08:00
satellite.show = !satellite.show
2021-09-14 07:31:59 +08:00
}
2021-12-22 18:46:05 +08:00
2021-12-22 19:32:34 +08:00
if (type === 'satellites/track') {
const satellite = entity.get(payload)
if (!satellite || !vcViewerInstance) return
2021-12-22 18:46:05 +08:00
2021-12-22 19:32:34 +08:00
vcViewerInstance.selectedEntity = satellite
vcViewerInstance.trackedEntity = satellite
}
2021-12-22 18:46:05 +08:00
})
const onTrackedEntityChanged = entity => {
2021-12-22 19:32:34 +08:00
if (!entity) store.commit('trackedSatellite/set', null)
2021-12-22 18:46:05 +08:00
}
const onViewerReady = ({ viewer }) => {
vcViewerInstance = viewer
viewer.scene.debugShowFramesPerSecond = false
// 限定缩放大小
viewer.scene.screenSpaceCameraController.minimumZoomDistance = 10000000 // 相机高度的最小值设定为 10000000 米
// 修改infobox的样式
const infoBox = viewer.infoBox.frame;
infoBox.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms')
infoBox.setAttribute('src', '') //必须设置src为空 否则不会生效
infoBox.addEventListener('load', function () {
const infoBoxDescriptionElement = infoBox.contentWindow.document.getElementsByClassName('cesium-infoBox-description')[0]
infoBoxDescriptionElement.style.fontSize = 'larger'
infoBoxDescriptionElement.style.paddingLeft = '20px'
infoBoxDescriptionElement.style.paddingRight = '20px'
})
}
2021-12-13 16:06:03 +08:00
</script>
<style>
.vc-viewer .cesium-viewer .cesium-viewer-animationContainer svg > g > g text:not(:last-of-type) {
display: none;
}
</style>