From 6cc2eb5ed9a6bdfe5fa3d9fe2313e04e6d7ebc9d Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Thu, 14 Nov 2024 08:57:35 +0800
Subject: [PATCH] 回滚

---
 src/hooks/initMap.js |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/hooks/initMap.js b/src/hooks/initMap.js
index 2675406..f2cd3fa 100644
--- a/src/hooks/initMap.js
+++ b/src/hooks/initMap.js
@@ -2,7 +2,7 @@
  * @Author: shuishen 1109946754@qq.com
  * @Date: 2024-10-25 15:09:55
  * @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2024-11-04 18:08:12
+ * @LastEditTime: 2024-11-13 16:37:17
  * @FilePath: \bigScreen\src\hooks\initMap.js
  * @Description: 
  * 
@@ -11,11 +11,12 @@
 let viewer = null
 const { VITE_APP_BASE } = import.meta.env
 import { useMap } from 'store/map'
-import { nextTick } from 'vue'
+import { nextTick, onMounted, onUnmounted } from 'vue'
+import * as turf from '@turf/turf'
+import * as Cesium from 'cesium'
+import 'cesium/Build/Cesium/Widgets/widgets.css'
 
 export function readyViewer () {
-  const Cesium = DC.getLib('Cesium')
-  const { appContext } = getCurrentInstance()
   const store = useMap()
 
   function initMap () {
@@ -23,15 +24,16 @@
 
     nextTick(() => {
       DC.ready({
-        baseUrl: `${VITE_APP_BASE}libs/dc-sdk/resources/`
+        // Cesium: Cesium,
+        baseUrl: `${VITE_APP_BASE}libs/dc-sdk/resources/`,
+        turf,
       }).then(() => {
 
         viewer = new DC.Viewer('viewer-container')
+        viewer.locationBar.enable = true
+        window.$viewer = viewer
 
-        const global = appContext.config.globalProperties
-        global.$viewer = viewer
-
-        global.$viewer.zoomToPosition(new DC.Position(
+        window.$viewer.zoomToPosition(new DC.Position(
           115.1048036679409,
           27.276835758787513,
           4000,
@@ -39,15 +41,22 @@
           -90,
           0
         ), () => {
-
-
           store.setLoadMap(true)
         })
       })
     })
   }
 
-  initMap()
+  onMounted(() => {
+    initMap()
+  })
+
+  onUnmounted(() => {
+    viewer.destroy()
+    viewer = null
+    delete window.$viewer
+    store.setLoadMap(false)
+  })
 
   return {
 

--
Gitblit v1.9.3