From abcb68359e2806c688cedbd5b6a07e3a2bc43db4 Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Thu, 12 Oct 2023 11:51:52 +0800
Subject: [PATCH] 时间文件格式化、地图航线展示修改

---
 src/utils/time.ts                       |   66 +++++++++++++++++---------------
 src/pages/page-web/projects/wayline.vue |   17 +++++---
 2 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/src/pages/page-web/projects/wayline.vue b/src/pages/page-web/projects/wayline.vue
index 77d0775..8c00066 100644
--- a/src/pages/page-web/projects/wayline.vue
+++ b/src/pages/page-web/projects/wayline.vue
@@ -96,6 +96,7 @@
 import { load } from '@amap/amap-jsapi-loader'
 import { getRoot } from '/@/root'
 import * as Cesium from 'cesium'
+import { cesiumOperation } from '/@/hooks/use-cesium-tsa'
 
 const loading = ref(false)
 const { appContext } = getCurrentInstance()
@@ -107,7 +108,7 @@
   total: -1,
   page_size: 10
 }
-
+const kmlEntity = ref<any>([])
 const waylinesData = reactive({
   data: [] as WaylineFile[]
 })
@@ -119,6 +120,7 @@
 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
@@ -204,10 +206,14 @@
  * @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(
@@ -215,10 +221,8 @@
       options
     )).then((res: any) => {
     kmlDataSource = res
+    kmlEntity.value = kmlDataSource.entities.values
     kmlDataSource.show = true
-
-    console.log('Entits数组', kmlDataSource.entities.values)
-
     const kmlEntityArr = kmlDataSource.entities.values[0]._children
     const cartesianArr = []
     for (let i = 0; i < kmlEntityArr.length; i++) {
@@ -229,12 +233,11 @@
         outlineColor: Cesium.Color.WHITE,
       })
       entity.billboard = null
-
       cartesianArr.push(entity.position._value)
     }
-    console.log(cartesianArr, 'cartesianArr')
     const lineEntity = global.$viewer.entities.add({
       name: 'entityLine',
+      id: 'kmzLine',
       polyline: {
         positions: cartesianArr,
         width: 10,
@@ -244,7 +247,7 @@
     })
 
     global.$viewer.flyTo(lineEntity, {
-      offset: new Cesium.HeadingPitchRange(0, -90, 1000)
+      offset: new Cesium.HeadingPitchRange(0, -90, 10000)
     })
   })
 }
diff --git a/src/utils/time.ts b/src/utils/time.ts
index 8720c21..679e502 100644
--- a/src/utils/time.ts
+++ b/src/utils/time.ts
@@ -14,37 +14,41 @@
   return time ? moment.unix(time).format(format) : DEFAULT_PLACEHOLDER
 }
 
-export function dateFormat(date:any, format:string) {
-  format = format || 'yyyy-MM-dd hh:mm:ss';
+export function dateFormat (date:any, format:string) {
+  format = format || 'yyyy-MM-dd hh:mm:ss'
   if (date !== 'Invalid Date') {
-    let o = {
-      "M+": date.getMonth() + 1, //month
-      "d+": date.getDate(), //day
-      "h+": date.getHours(), //hour
-      "m+": date.getMinutes(), //minute
-      "s+": date.getSeconds(), //second
-      "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
-      "S": date.getMilliseconds() //millisecond
+    const o = {
+      'M+': date.getMonth() + 1, // month
+      'd+': date.getDate(), // day
+      'h+': date.getHours(), // hour
+      'm+': date.getMinutes(), // minute
+      's+': date.getSeconds(), // second
+      'q+': Math.floor((date.getMonth() + 3) / 3), // quarter
+      S: date.getMilliseconds() // millisecond
     }
-    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
-        (date.getFullYear() + "").substr(4 - RegExp.$1.length));
-    for (let k in o)
-      if (new RegExp("(" + k + ")").test(format))
+    if (/(y+)/.test(format)) {
+      format = format.replace(RegExp.$1,
+        (date.getFullYear() + '').substr(4 - RegExp.$1.length))
+    }
+    for (const k in o) {
+      if (new RegExp('(' + k + ')').test(format)) {
         format = format.replace(RegExp.$1,
-            RegExp.$1.length === 1 ? o[k] :
-                ("00" + o[k]).substr(("" + o[k]).length));
-    return format;
+          RegExp.$1.length === 1
+            ? o[k]
+            : ('00' + o[k]).substr(('' + o[k]).length))
+      }
+    }
+    return format
   }
-  return '';
-
+  return ''
 }
 
-export function convertTimestampToDate(timestamp:any, format:string) {
-  if (timestamp && (typeof timestamp === "string") && timestamp.indexOf("-") > -1) {
-    timestamp = timestamp.replace(/\-/g, "/")
+export function convertTimestampToDate (timestamp:any, format:string) {
+  if (timestamp && (typeof timestamp === 'string') && timestamp.indexOf('-') > -1) {
+    timestamp = timestamp.replace(/\-/g, '/')
   }
-  let time = new Date(timestamp)
-  let formatterTime = dateFormat(time, format)
+  const time = new Date(timestamp)
+  const formatterTime = dateFormat(time, format)
   return formatterTime
 }
 
@@ -52,12 +56,12 @@
 export const timestampToTime = (timestamp:number) => {
   if (!timestamp) return
   // 时间戳为10位需*1000,时间戳为13位不需乘1000
-  var date = new Date(timestamp);
-  var Y = date.getFullYear() + "-";
-  var M =
+  const date = new Date(timestamp)
+  const Y = date.getFullYear() + '-'
+  const M =
       (date.getMonth() + 1 < 10
-          ? "0" + (date.getMonth() + 1)
-          : date.getMonth() + 1) + "-";
-  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
-  return Y + M + D;
+        ? '0' + (date.getMonth() + 1)
+        : date.getMonth() + 1) + '-'
+  const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
+  return Y + M + D
 }

--
Gitblit v1.9.3