fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import * as mars3d from "mars3d"
import { Typhoon, PlayTyphoon } from "./Typhoon"
 
export let map // mars3d.Map三维地图对象
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 8.560501, lng: 111.849127, alt: 10725692, heading: 358, pitch: -87 }
  }
}
 
export const eventTarget = new mars3d.BaseClass()
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  // 绘制24/48小时警戒线
  drawWarningLine()
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
// 所有已构造的台风集合
const typhoonListObj = {}
 
// 当前选择的台风
let selectTyphoon
 
// 勾选台风
export function selectOneTyphoon(row) {
  stopPlay()
 
  const id = row.id
  if (!typhoonListObj[id]) {
    typhoonListObj[id] = new Typhoon({ ...row }, map)
  }
 
  const typhoon = typhoonListObj[id]
  typhoon.show = true
  typhoon.flyTo()
 
  selectTyphoon = typhoon
}
 
// 取消勾选台风
export function unSelectOneTyphoon(id) {
  const typhoon = typhoonListObj[id]
  if (!typhoon) {
    return
  }
 
  if (typhoon.playTyphoon) {
    typhoon.playTyphoon.stop()
  }
  typhoon.show = false
 
  selectTyphoon = null
}
 
// 定位到台风
export function clickTyRow(row) {
  const typhoon = typhoonListObj[row.id]
  if (typhoon) {
    typhoon.flyTo()
  }
}
 
// 定位到轨迹点
export function clickPathRow(row) {
  selectTyphoon.showPointFQ(row)
  const graphic = selectTyphoon.getPointById(row.id)
  if (graphic) {
    graphic.flyTo({
      radius: 1600000,
      complete() {
        graphic.openTooltip()
      }
    })
  }
}
 
// 开始播放
export function startPlay() {
  if (!selectTyphoon) {
    return
  }
 
  if (!selectTyphoon.playTyphoon) {
    selectTyphoon.playTyphoon = new PlayTyphoon(selectTyphoon.options, map)
  }
 
  selectTyphoon.playTyphoon.start()
  selectTyphoon.show = false
}
 
// 停止播放
export function stopPlay() {
  if (selectTyphoon?.playTyphoon) {
    selectTyphoon.playTyphoon.stop()
    selectTyphoon.show = true
  }
}
 
// 绘制警戒线
function drawWarningLine() {
  // 绘制24小时警戒线
  const lineWarning24 = new mars3d.graphic.PolylineEntity({
    positions: [
      [127, 34],
      [127, 22],
      [119, 18],
      [119, 11],
      [113, 4.5],
      [105, 0]
    ],
    style: {
      color: "#828314",
      width: 2,
      zIndex: 1
    }
  })
  map.graphicLayer.addGraphic(lineWarning24)
 
  // 注记文本
  const textWarning24 = new mars3d.graphic.RectangleEntity({
    positions: [
      [128.129019, 29.104287],
      [125.850451, 28.424599]
    ],
    style: {
      material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.Text, {
        text: "24小时警戒线",
        font: "80px 楷体",
        color: "#828314",
        backgroundColor: new Cesium.Color(0.0, 0.0, 0.0, 0)
      }),
      rotationDegree: 90
    }
  })
  map.graphicLayer.addGraphic(textWarning24)
 
  // 绘制48小时警戒线
  const lineWarning48 = new mars3d.graphic.PolylineEntity({
    positions: [
      [132, 34],
      [132, 22],
      [119, 0],
      [105, 0]
    ],
    style: {
      width: 2,
      material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.PolylineDash, {
        dashLength: 20.0,
        color: "#4dba3d"
      })
    }
  })
  map.graphicLayer.addGraphic(lineWarning48)
 
  // 注记文本
  const textWarning48 = new mars3d.graphic.RectangleEntity({
    positions: [
      [130.502492, 25.959716],
      [133.423638, 26.772991]
    ],
    style: {
      material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.Text, {
        text: "48小时警戒线",
        font: "80px 楷体",
        color: "#4dba3d",
        backgroundColor: new Cesium.Color(0.0, 0.0, 0.0, 0)
      }),
      rotationDegree: 90,
      zIndex: 4
    }
  })
  map.graphicLayer.addGraphic(textWarning48)
}
 
export const formatDate = mars3d.Util.formatDate