forked from drone/command-center-dashboard

张含笑
2025-04-16 b640f46407c19123f95565a5cc597e65cf6d76e2
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2025-04-15 22:41:40
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2025-04-16 15:06:15
 * @FilePath: \command-center-dashboard\src\hooks\useSingleDroneMap\index.js
 * @Description: 
 * 
 * Copyright (c) 2025 by shuishen, All Rights Reserved. 
 */
import { useMapMarkers } from './useMapMarkers'
import { useMapEvents } from './useMapEvents'
import { useMapPopup } from './useMapPopup'
 
/**
 * Cesium地图功能组合Hook
 * @param {Object} options - 配置选项
 * @param {Function} options.fetchMarkers - 获取标注的函数
 * @param {Function} options.fetchEvents - 获取事件的函数
 * @param {Component} options.popupComponent - 弹窗组件
 */
export function useSingleDroneMap (options = {
  dronePosition: {},
  eventLoadType: 'data',
  eventPositions: [],
  eventApi: null,
  eventApiParams: {}
}) {
  let viewer = null
  let currentEntity = null
 
  // 组合各个功能Hook
  const {
    initLayer,
    removeLayer,
  } = useMapMarkers(viewer, {})
 
  const {
    handlerInit,
    removeHandler
  } = useMapEvents(viewer, {
    onEventClick: (entity) => {
      currentEntity = entity // 更新当前实体
 
      addLabel()
    }
  })
 
  const {
    addLabel
  } = useMapPopup(viewer, {
    currentEntity
  })
 
  const init = () => {
    viewer = window.$viewer
 
    initLayer()
    handlerInit()
  }
 
  const removeAll = () => {
    removeLayer()
    removeHandler()
    removeLabel()
  }
 
  // 自动清理
  onUnmounted(() => {
    removeAll()
  })
 
  return {
    init,
    removeAll
  }
}