实现基本功能

master
叶志超 2021-12-22 18:46:05 +08:00
parent 462ba303b6
commit 5e1601c8ea
1 changed files with 67 additions and 75 deletions

View File

@ -1,10 +1,9 @@
<template>
<vc-viewer ref="vcViewer" class="vc-viewer" :animation="true" :showCredit="false" :shouldAnimate="true" :sceneModePicker="true" @ready="onViewerReady">
<vc-viewer class="vc-viewer" :animation="true" :showCredit="false" :shouldAnimate="true" :sceneModePicker="true" @ready="onViewerReady" @trackedEntityChanged="onTrackedEntityChanged">
<vc-layer-imagery>
<vc-provider-imagery-tianditu mapStyle="img_c" :token="token" />
</vc-layer-imagery>
<vc-layer-imagery>
<vc-provider-imagery-tianditu mapStyle="cva_c" :token="token" />
<vc-provider-imagery-singletile
:url="earth"
></vc-provider-imagery-singletile>
</vc-layer-imagery>
<vc-navigation :offset="[10, 40]" :position="'top-left'" :printOpts="false" :locationOpts="false" :otherOpts="false" />
@ -13,87 +12,80 @@
</vc-viewer>
</template>
<script lang="ts">
import { ref, defineComponent } from 'vue'
<script lang="ts" setup>
import { ref, computed, watch } from 'vue'
import { useStore } from 'vuex'
import { VcViewer, VcLayerImagery, VcProviderImageryTianditu, VcNavigation, VcDatasourceCzml } from 'vue-cesium'
import 'vue-cesium/dist/index.css'
export default defineComponent({
setup: () => {
const vcViewer = ref(null)
const token = '436ce7e50d27eede2f2929307e6b33c0'
// import 'vue-cesium/dist/index.css'
import earth from '../assets/earth.jpg'
const czml = ref('')
const loadSatelliteOrbit = ss => czml.value = './CZML/' + ss + '.czml'
const store = useStore()
const czml = computed(() => './CZML/' + store.state.satelliteSystem.name + '.czml')
const onViewerReady = ({ viewer }) => {
viewer.scene.debugShowFramesPerSecond = false
//
const { imageryLayers } = viewer
imageryLayers.remove(imageryLayers.get(0))
let entities = null
const getEntityById = id => {
if (!entities) return null
//
// viewer.scene.screenSpaceCameraController.maximumZoomDistance = 50000000 // 50000000
// 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'
})
}
return entities.find(entity => entity.id === id)
}
const onDataSourceReady = ({ viewer, cesiumObject }) => {
viewer.flyTo(cesiumObject)
let entities = null
const store = useStore()
const onDataSourceReady = ({ viewer, cesiumObject }) => {
viewer.flyTo(cesiumObject)
entities = cesiumObject.entities.values
entities = cesiumObject.entities.values
//
viewer.selectedEntity = entities.find(entity => entity.id.startsWith('Constellation'))
// viewer.selectedEntity = entities[entities.length - 1]
//
viewer.selectedEntity = entities.find(entity => entity.id.startsWith('Constellation'))
// store
const satellites = entities.filter(entity => entity.id.startsWith('Satellite'))
const satellite_state_arr = satellites.map(({ id, show }) => { return { id, show } })
store.commit('satellites/set', satellite_state_arr)
}
// /
store.subscribe(({ type, payload }) => {
if (type === 'satellites/toggleShow') {
const entity = getEntityById(payload)
if (!entity) return
// store
const satellites = entities.filter(entity => entity.id.startsWith('Satellite'))
const satellite_state_arr = satellites.map(({ id, show }) => { return { id, show } })
store.commit('satellites/set', satellite_state_arr)
}
// /
store.subscribe(({ type, payload }) => {
if (type === 'satellites/toggleShow') {
const entity = getEntityById(payload)
if (!entity) return
entity.show = !entity.show
}
})
//
const trackSatellite = id => {
const entity = getEntityById(id)
if (!entity) return
const viewer = vcViewer.value.getCesiumObject()
viewer.selectedEntity = entity
viewer.trackedEntity = entity
}
const getEntityById = id => {
if (!entities) return null
return entities.find(entity => entity.id === id)
}
return { vcViewer, token, czml, loadSatelliteOrbit, trackSatellite, onViewerReady, onDataSourceReady }
},
components: {
VcViewer, VcLayerImagery, VcProviderImageryTianditu, VcNavigation, VcDatasourceCzml
entity.show = !entity.show
}
})
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
})
const onTrackedEntityChanged = entity => {
console.log(entity, '==============');
store.commit('trackedSatellite/set', null)
}
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'
})
}
</script>
<style>