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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
export let graphicLayer // 矢量图层对象
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 31.81506, lng: 117.23734, alt: 1768, heading: 322, pitch: -33 },
    fxaa: true
  }
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  // 创建矢量图层
  graphicLayer = new mars3d.layer.GraphicLayer()
  map.addLayer(graphicLayer)
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
export function demoSampleProperty() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,255,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"))
 
  // 演示属性机制
  const property = new Cesium.SampledProperty(Cesium.Cartesian3)
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Cartesian3(400.0, 300.0, 100.0))
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), new Cesium.Cartesian3(400.0, 300.0, 900.0))
  // 让盒子一直存在
  // property.addSample(Cesium.JulianDate.fromDate(new Date('2017-08-26 00:00:00')), new Cesium.Cartesian3(400.0, 300.0, 900.0))
 
  marsBox.setStyle({ dimensions: property })
}
 
export function demoTimeIntervalCollectionProperty() {
  graphicLayer.clear()
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z")
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(255,255,0,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 演示属性机制
  const property = new Cesium.TimeIntervalCollectionProperty()
  property.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:00.00Z/2017-08-25T00:00:02.00Z",
      isStartIncluded: true,
      isStopIncluded: false,
      data: new Cesium.Cartesian3(400.0, 300.0, 200.0)
    })
  )
  property.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:02.00Z/2017-08-25T00:00:04.00Z",
      isStartIncluded: true,
      isStopIncluded: false,
      data: new Cesium.Cartesian3(400.0, 300.0, 400.0)
    })
  )
  property.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:04.00Z/2017-08-25T00:00:06.00Z",
      isStartIncluded: true,
      isStopIncluded: false,
      data: new Cesium.Cartesian3(400.0, 300.0, 500.0)
    })
  )
  property.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:06.00Z/2017-08-25T00:00:08.00Z",
      isStartIncluded: true,
      isStopIncluded: true,
      data: new Cesium.Cartesian3(400.0, 300.0, 700.0)
    })
  )
 
  marsBox.setStyle({ dimensions: property })
}
 
export function demoConstantProperty() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,255,0,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  setTimeout(() => {
    // 演示属性机制
 
    // 会创建一个新的ConstantProperty
    // marsBox.entityGraphic.dimensions = new Cesium.Cartesian3(400.0, 300.0, 200.0)
 
    // 会修改原有的ConstantProperty的值。
    marsBox.entityGraphic.dimensions.setValue(new Cesium.Cartesian3(400.0, 300.0, 700.0))
  }, 2000)
}
 
//
export function demoCompositeProperty() {
  graphicLayer.clear()
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z")
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,255,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 演示属性机制
 
  // 1 sampledProperty
  const sampledProperty = new Cesium.SampledProperty(Cesium.Cartesian3)
  sampledProperty.addSample(Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z"), new Cesium.Cartesian3(400.0, 300.0, 100.0))
  sampledProperty.addSample(Cesium.JulianDate.fromIso8601("2017-08-25T00:00:10.00Z"), new Cesium.Cartesian3(400.0, 300.0, 500.0))
 
  // 2 ticProperty
  const ticProperty = new Cesium.TimeIntervalCollectionProperty()
  ticProperty.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:10.00Z/2017-08-25T00:00:12.00Z",
      isStartIncluded: true,
      isStopIncluded: false,
      data: new Cesium.Cartesian3(400.0, 300.0, 600.0)
    })
  )
  ticProperty.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:12.00Z/2017-08-25T00:00:14.00Z",
      isStartIncluded: true,
      isStopIncluded: false,
      data: new Cesium.Cartesian3(400.0, 300.0, 700.0)
    })
  )
  ticProperty.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:14.00Z/2017-08-25T00:00:16.00Z",
      isStartIncluded: true,
      isStopIncluded: false,
      data: new Cesium.Cartesian3(400.0, 300.0, 800.0)
    })
  )
  ticProperty.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:16.00Z/2017-08-25T00:00:18.00Z",
      isStartIncluded: true,
      isStopIncluded: true,
      data: new Cesium.Cartesian3(400.0, 300.0, 900.0)
    })
  )
 
  // 3 compositeProperty
  const compositeProperty = new Cesium.CompositeProperty()
  compositeProperty.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:00.00Z/2017-08-25T00:00:10.00Z",
      data: sampledProperty
    })
  )
  compositeProperty.intervals.addInterval(
    Cesium.TimeInterval.fromIso8601({
      iso8601: "2017-08-25T00:00:10.00Z/2017-08-25T00:00:20.00Z",
      isStartIncluded: false,
      isStopIncluded: false,
      data: ticProperty
    })
  )
 
  // 4 设置dimensions
  marsBox.setStyle({ dimensions: compositeProperty })
}
 
// 使盒子进行移动
export function demoSampledPositionProperty() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.198461, 31.834956, 40.2],
    style: {
      dimensions: new Cesium.Cartesian3(100.0, 200.0, 300.0),
      color: "rgba(2,255,123,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"))
 
  // 演示属性机制
  const property = new Cesium.SampledPositionProperty()
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), Cesium.Cartesian3.fromDegrees(117.198461, 31.834956, 40.2))
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), Cesium.Cartesian3.fromDegrees(117.231979, 31.833411, 35.6))
 
  marsBox.position = property
}
 
//
export function demoColorMaterialProperty() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,0,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 演示属性机制
  setTimeout(() => {
    marsBox.setStyle({ material: new Cesium.ColorMaterialProperty(new Cesium.Color(0, 1, 0)) })
    // 以上代码等同于
    // marsBox.setStyle({ material: new Cesium.Color(0, 1, 0) })
  }, 3000)
}
 
export function demoColorMaterialProperty2() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,0,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"))
 
  // 演示属性机制
  const colorProperty = new Cesium.SampledProperty(Cesium.Color)
  colorProperty.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Color(0, 0, 1))
  colorProperty.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:10")), new Cesium.Color(1, 1, 0))
 
  marsBox.setStyle({ material: new Cesium.ColorMaterialProperty(colorProperty) })
}
 
//
export function demoCallbackProperty() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,255,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 演示属性机制
  let len = 100.0
  const property = new Cesium.CallbackProperty(function (time, result) {
    result = result || new Cesium.Cartesian3(400.0, 300.0, 500.0)
 
    len += 3.0
    if (len > 900.0) {
      len = 100.0
    }
 
    result.x = 400.0
    result.y = 300.0
    result.z = len
 
    return result
  }, false)
 
  marsBox.setStyle({ dimensions: property })
}
 
//
export function demoReferenceProperty() {
  graphicLayer.clear()
 
  // 创建蓝色盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,0,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"))
 
  // 演示属性机制
  const property = new Cesium.SampledProperty(Cesium.Cartesian3)
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Cartesian3(400.0, 300.0, 100.0))
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), new Cesium.Cartesian3(400.0, 300.0, 900.0))
  property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-26 00:00:00")), new Cesium.Cartesian3(400.0, 300.0, 900.0)) // 让盒子一直存在
  marsBox.setStyle({ dimensions: property })
 
  // 另外一个红色盒子
  const redBox = new mars3d.graphic.BoxEntity({
    position: [117.225643, 31.843242, 37.9],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(255,0,0,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(redBox)
 
  // 演示属性机制
  const collection = graphicLayer.dataSource.entities
  const dimensions = new Cesium.ReferenceProperty(collection, marsBox.uuid, ["box", "dimensions"])
  redBox.setStyle({ dimensions: dimensions })
}
 
//
export function demoPropertyBag() {
  graphicLayer.clear()
 
  // 创建盒子
  const marsBox = new mars3d.graphic.BoxEntity({
    position: [117.220164, 31.834887, 39.6],
    style: {
      dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
      color: "rgba(0,0,255,0.8)",
      outline: true
    }
  })
  graphicLayer.addGraphic(marsBox)
 
  // 指定固定时间 ,方便写演示代码。
  map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"))
 
  // 演示属性机制
  const zp = new Cesium.SampledProperty(Number)
  zp.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), 100.0)
  zp.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:10")), 800.0)
 
  const dimensions = new Cesium.PropertyBag({
    x: 400.0,
    y: 300.0,
    z: zp
  })
  marsBox.setStyle({ dimensions: dimensions })
}
 
//
export function demoVelocityVectorProperty() {
  graphicLayer.clear()
 
  const propertyFJ = getSampledPositionProperty([
    [117.198461, 31.834956, 40.2],
    [117.231979, 31.833411, 35.6]
  ])
  const graphic = new mars3d.graphic.BillboardEntity({
    position: propertyFJ,
    orientation: new Cesium.VelocityOrientationProperty(propertyFJ),
    style: {
      image: "img/marker/huojian.svg",
      scale: 0.5,
      alignedAxis: new Cesium.VelocityVectorProperty(propertyFJ, true)
    }
  })
  graphicLayer.addGraphic(graphic)
}
 
// 计算演示的SampledPositionProperty轨迹
function getSampledPositionProperty(points) {
  const property = new Cesium.SampledPositionProperty()
 
  const start = map.clock.currentTime
  const positions = mars3d.LngLatArray.toCartesians(points)
  for (let i = 0; i < positions.length; i++) {
    const time = Cesium.JulianDate.addSeconds(start, i * 20, new Cesium.JulianDate())
    const position = positions[i]
    property.addSample(time, position)
  }
  return property
}