Skip to content

Commit

Permalink
feat: update home component for initialize file desc state
Browse files Browse the repository at this point in the history
  • Loading branch information
Styx11 committed May 12, 2021
1 parent e9010f7 commit e49f24f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
45 changes: 44 additions & 1 deletion views/src/pages/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
</template>

<script lang='ts'>
import { defineComponent, defineAsyncComponent, computed } from 'vue'
import { defineComponent, defineAsyncComponent, computed, watch, onBeforeUnmount, toRaw, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { useStore } from '@/store'
import TitleBar from '@/components/TitleBar/index.vue'
import ToolBar from '@/components/ToolBar/index.vue'
import ToolDrawer from '@/components/ToolBar/ToolDrawer.vue'
import { Spin } from 'ant-design-vue'
import { RootStateMutation } from '@/store'
import { ModelFileMutation } from '@/store/file'
import { CesiumEntityMutation } from '@/store/entity'
import { ElevationPointMutation } from '@/store/elevation'
import IPCRendererManager from '@/ipc/IPCRendererManager'
export default defineComponent({
name: 'Home',
Expand All @@ -39,6 +44,44 @@
const uid = computed(() => route.query.uid)
const model = computed(() => store.state.modelFile.fileList.filter(f => f.uid === uid.value)[0])
const entityDataList = computed(() => store.state.cesiumEntity.entityList)
const elevationDataList = computed(() => store.state.elevationPoint.list)
// 将选中的模型文件信息初始化至 Cesium 相关 store 数据中
if (model.value.measureData)
{
store.commit(CesiumEntityMutation.INIT_ENTITY, [...toRaw(model.value.measureData)])
}
if (model.value.elevationData)
{
store.commit(ElevationPointMutation.INIT_ELEVATION, [...toRaw(model.value.elevationData)])
}
// 监听测绘工具数据,更新至模型文件数据
const unwatchEntity = watch(entityDataList, (newData) =>
{
const newModel = Object.assign({}, toRaw(model.value), { measureData: [...toRaw(newData)] })
store.commit(ModelFileMutation.UPDATE_FILE, newModel)
nextTick().then(() => IPCRendererManager.getInstance().invokeUpdateModelDesc(newModel))
}, { deep: true })
const unwatchElevation = watch(elevationDataList, (newData) =>
{
const newModel = Object.assign({}, toRaw(model.value), { elevationData: [...toRaw(newData)] })
store.commit(ModelFileMutation.UPDATE_FILE, newModel)
nextTick().then(() => IPCRendererManager.getInstance().invokeUpdateModelDesc(newModel))
}, { deep: true })
onBeforeUnmount(() =>
{
unwatchEntity()
unwatchElevation()
store.commit(RootStateMutation.INIT_STATE)
store.commit(CesiumEntityMutation.INIT_ENTITY)
store.commit(ElevationPointMutation.INIT_ELEVATION, [])
})
return {
model,
}
Expand Down
3 changes: 3 additions & 0 deletions views/src/pages/home/components/Model.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
ScreenPosition,
flyTo,
flyToInOrtho,
initEntity,
} from '../../../hooks/cesium'
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiZjc1MGI5NC0wYTcyLTQ3YWYtYTNiMi03YmU5MjQ0ZTE1MDkiLCJpZCI6NDk1NjIsImlhdCI6MTYxNzQxNjIzMH0.OKpUIs85S_LatHupyCtso-ZtcpMjdrYVmSf61N93Ihg'
Expand Down Expand Up @@ -137,6 +138,8 @@
zoomToTileset(tileset)
tilesetReady.value = true
initEntity(store)
})
})
Expand Down

0 comments on commit e49f24f

Please sign in to comment.