From 54849757852f6ab40eb17afbd03d1d839b60a38d Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 13 Nov 2023 17:09:15 +0800
Subject: [PATCH] 重复定时和连续执行
---
src/pages/page-web/projects/wayline.vue | 108 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 75 insertions(+), 33 deletions(-)
diff --git a/src/pages/page-web/projects/wayline.vue b/src/pages/page-web/projects/wayline.vue
index aa9e67f..e532830 100644
--- a/src/pages/page-web/projects/wayline.vue
+++ b/src/pages/page-web/projects/wayline.vue
@@ -84,7 +84,7 @@
import { reactive } from '@vue/reactivity'
import { message } from 'ant-design-vue'
import { onMounted, onUpdated, ref } from 'vue'
-import { deleteWaylineFile, downloadWaylineFile, getWaylineFiles, importKmzFile } from '/@/api/wayline'
+import { deleteWaylineFile, downloadWaylineFile, getWaylineFiles, importKmzFile, getWayLineFile } from '/@/api/wayline'
import { ELocalStorageKey, ERouterName } from '/@/types'
import { EllipsisOutlined, RocketOutlined, CameraFilled, UserOutlined, SelectOutlined } from '@ant-design/icons-vue'
import { EDeviceType } from '/@/types/device'
@@ -95,28 +95,32 @@
import { CURRENT_CONFIG } from '/@/api/http/config'
import { load } from '@amap/amap-jsapi-loader'
import { getRoot } from '/@/root'
-import kmz from '/@/assets/kmz/test.kmz'
-import togeojson from '@mapbox/togeojson'
+import * as Cesium from 'cesium'
+import { cesiumOperation } from '/@/hooks/use-cesium-tsa'
const loading = ref(false)
+const { appContext } = getCurrentInstance()
+const global = appContext.config.globalProperties
const store = useMyStore()
+let kmlDataSource = null
const pagination :IPage = {
page: 1,
total: -1,
page_size: 10
}
-
+const kmlEntity = ref<any>([])
const waylinesData = reactive({
data: [] as WaylineFile[]
})
const root = getRoot()
-const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
+const workspaceId = computed(() => store.state.common.projectId || localStorage.getItem(ELocalStorageKey.WorkspaceId))
const deleteTip = ref(false)
const deleteWaylineId = ref<string>('')
const canRefresh = ref(true)
const importVisible = ref<boolean>(root.$router.currentRoute.value.name === ERouterName.WAYLINE)
const height = ref()
+const { removeById, } = cesiumOperation()
onMounted(() => {
const parent = document.getElementsByClassName('scrollbar').item(0)?.parentNode as HTMLDivElement
@@ -132,6 +136,13 @@
pagination.page++
getWaylines()
}, 1000)
+ console.log(workspaceId.value)
+})
+onUnmounted(() => {
+ if (kmlDataSource) {
+ global.$viewer.dataSources.remove(kmlDataSource)
+ }
+ removeById('kmzLine')
})
function getWaylines () {
@@ -139,7 +150,7 @@
return
}
canRefresh.value = false
- getWaylineFiles(workspaceId, {
+ getWaylineFiles(workspaceId.value, {
page: pagination.page,
page_size: pagination.page_size,
order_by: 'update_time desc'
@@ -161,9 +172,9 @@
}
function deleteWayline () {
- deleteWaylineFile(workspaceId, deleteWaylineId.value).then(res => {
+ deleteWaylineFile(workspaceId.value, deleteWaylineId.value).then(res => {
if (res.code === 0) {
- message.success('Wayline file deleted')
+ message.success('文件删除成功')
}
deleteWaylineId.value = ''
deleteTip.value = false
@@ -176,7 +187,7 @@
function downloadWayline (waylineId: string, fileName: string) {
loading.value = true
- downloadWaylineFile(workspaceId, waylineId).then(res => {
+ downloadWaylineFile(workspaceId.value, waylineId).then(res => {
if (!res) {
return
}
@@ -188,38 +199,69 @@
}
function selectRoute (wayline: WaylineFile) {
- store.commit('SET_SELECT_WAYLINE_INFO', wayline)
- console.log(wayline, 'wayline')
- downloadWaylineFile(workspaceId, wayline.id).then(async res => {
- if (!res) {
- return
- }
- console.log(res, 'res')
- const data = new Blob([res], { type: 'application/kmz' })
- // downloadFile(data, fileName + '.kmz')
- await analysisKMLFile(data)
+ loading.value = true
+ getWayLineFile(workspaceId.value, wayline.id).then(res => {
+ store.commit('SET_SELECT_WAYLINE_INFO', wayline)
+ initKmlFile(res.data)
}).finally(() => {
loading.value = false
})
}
+/**
+ * 加载kml文件
+ * @param file
+ */
+function initKmlFile (file:string) {
+ removeById('kmzLine')
+ const options = {
+ camera: global.$viewer.scene.camera,
+ canvas: global.$viewer.scene.canvas,
+ screenOverlayContainer: global.$viewer.container,
+ }
+ if (kmlDataSource) {
+ global.$viewer.dataSources.remove(kmlDataSource)
+ }
+ global.$viewer.dataSources.add(
+ Cesium.KmlDataSource.load(
+ file,
+ options
+ )).then((res: any) => {
+ kmlDataSource = res
+ kmlEntity.value = kmlDataSource.entities.values
+ kmlDataSource.show = true
+ const kmlEntityArr = kmlDataSource.entities.values[0]._children
+ const cartesianArr = []
+ for (let i = 0; i < kmlEntityArr.length; i++) {
+ const entity = kmlEntityArr[i]
+ entity.point = new Cesium.PointGraphics({
+ pixelSize: 12,
+ color: Cesium.Color.RED,
+ outlineColor: Cesium.Color.WHITE,
+ })
+ entity.billboard = null
+ cartesianArr.push(entity.position._value)
+ }
+ const lineEntity = global.$viewer.entities.add({
+ name: 'entityLine',
+ id: 'kmzLine',
+ polyline: {
+ positions: cartesianArr,
+ width: 10,
+ material: new Cesium.PolylineArrowMaterialProperty(Cesium.Color.CYAN),
+ clampToGround: false, // 关闭贴地效果,保留高度
+ },
+ })
+ global.$viewer.flyTo(lineEntity, {
+ offset: new Cesium.HeadingPitchRange(0, -90, 8000)
+ })
+ })
+}
function onScroll (e: any) {
const element = e.srcElement
if (element.scrollTop + element.clientHeight >= element.scrollHeight - 5 && Math.ceil(pagination.total / pagination.page_size) > pagination.page && canRefresh.value) {
pagination.page++
getWaylines()
- }
-}
-// 解析kml文件
-const analysisKMLFile = file => {
- const reader = new FileReader()
- reader.readAsText(file, 'utf-8')
- reader.onload = function (e) {
- const xml = new DOMParser().parseFromString(e.target.result, 'text/xml')
- const geojson = togeojson.kml(xml, {
- style: true
- })
- console.log(geojson, 'geojson')
}
}
interface FileItem {
@@ -245,9 +287,9 @@
fileList.value.forEach(async (file: FileItem) => {
const fileData = new FormData()
fileData.append('file', file, file.name)
- await importKmzFile(workspaceId, fileData).then((res) => {
+ await importKmzFile(workspaceId.value, fileData).then((res) => {
if (res.code === 0) {
- message.success(`${file.name} file uploaded successfully`)
+ message.success(`${file.name} 文件上传成功`)
canRefresh.value = true
pagination.total = 0
pagination.page = 1
--
Gitblit v1.9.3