智慧园区前端大屏
linwe
2024-11-22 02583d412e6680732829fe32e2af44d88c7ac2e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2024-10-25 15:09:55
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2024-11-22 14:54:14
 * @FilePath: \bigScreen\src\hooks\initMap.js
 * @Description: 
 * 
 * Copyright (c) 2024 by shuishen, All Rights Reserved. 
 */
window.$viewer = null
const { VITE_APP_BASE } = import.meta.env
import { useMap } from 'store/map'
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 store = useMap()
 
  function initMap () {
    if (window.$viewer) return
 
    nextTick(() => {
      DC.ready({
        // Cesium: Cesium,
        baseUrl: `${VITE_APP_BASE}libs/dc-sdk/resources/`,
        turf,
      }).then(() => {
 
        window.$viewer = new DC.Viewer('viewer-container')
        window.$viewer.locationBar.enable = true
 
        window.$viewer.zoomToPosition(new DC.Position(
          115.1048036679409,
          27.276835758787513,
          4000,
          0,
          -90,
          0
        ), () => {
          store.setLoadMap(true)
        })
      })
    })
  }
 
  onMounted(() => {
    initMap()
  })
 
  onUnmounted(() => {
    window.$viewer.destroy()
    window.$viewer = null
    delete window.$viewer
    store.setLoadMap(false)
  })
 
  return {
 
  }
}