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
import * as mars3d from "mars3d"
 
export let map
let graphic
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 25.389914, lng: 119.084961, alt: 1179575, heading: 346, pitch: -60 }
  }
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  const graphicLayer = new mars3d.layer.GraphicLayer()
  map.addLayer(graphicLayer)
 
  graphic = new mars3d.graphic.EllipsoidEntity({
    position: [107.39956, 29.719738, 100.9],
    style: {
      radii: new Cesium.Cartesian3(2500.0, 2500.0, 1000.0),
      maximumConeDegree: 90, // 半球
      fill: false,
      subdivisions: 64,
      stackPartitions: 32,
      slicePartitions: 32,
      outline: true,
      outlineColor: Cesium.Color.YELLOW,
 
      // 高亮时的样式(默认为鼠标移入,也可以指定type:'click'单击高亮),构造后也可以openHighlight、closeHighlight方法来手动调用
      highlight: {
        outlineColor: Cesium.Color.RED
      }
    },
    // 添加扫描面
    scanPlane: {
      step: 0.5, // 步长
      style: {
        color: "#ffff00",
        opacity: 0.4
      }
    }
  })
  graphicLayer.addGraphic(graphic)
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
 
export function onUnmounted() {
  map = null
}
 
// **************************** 景点视角演示********************** //
export function changeView1() {
  map.setCameraView({ lat: 39.904128, lng: 116.391643, alt: 1054, heading: 0, pitch: -39 })
}
 
export function changeView2() {
  map.setCameraView({ lat: 28.13059, lng: 86.835138, alt: 7627, heading: 148, pitch: -7 })
}
 
export function changeView3() {
  map.setCameraView({ lat: 34.560392, lng: 110.052393, alt: 1724, heading: 171, pitch: -5 })
}
 
export function changeView4() {
  map.setCameraView({ lat: 30.83463, lng: 115.86774, alt: 710, heading: 303, pitch: -7 })
}
 
// **************************** 相机和视角控制********************** //
export function mapGetCameraView() {
  const camera = map.getCameraView()
  globalAlert(JSON.stringify(camera), "当前视角参数")
}
 
export function mapSetCameraView() {
  map.setCameraView({ lat: 26.8764, lng: 91.148781, alt: 223798, heading: 0, pitch: -45 })
}
 
export function mapSetCameraViewList() {
  // 视角切换(分步执行), stop设置停留在该视角的时间
  map.setCameraViewList([
    { lng: 108.961601, lat: 34.217109, alt: 509.2, heading: 314.5, pitch: -22.5, duration: 8, stop: 0 },
    { lng: 108.96164, lat: 34.222159, alt: 510.3, heading: 211.2, pitch: -22.5, duration: 5, stop: 0 },
    { lng: 108.957259, lat: 34.221967, alt: 494.3, heading: 127.5, pitch: -17.2, duration: 5, stop: 0 },
    { lng: 108.957319, lat: 34.217225, alt: 515.5, heading: 25.4, pitch: -25.3, duration: 5 }
  ])
}
 
export function mapFlyHome() {
  map.flyHome()
}
 
export function mapFlyToGraphic() {
  map.flyToGraphic(graphic, { radius: 10000 })
}
 
export function mapFlyToExtent() {
  map.flyToExtent({ xmin: 114.811691, xmax: 119.703609, ymin: 29.35597, ymax: 34.698585 })
}
 
export function mapFlyToPositions() {
  map.flyToPositions([
    [114.031965, 36.098482, 332.8],
    [114.038309, 36.089496, 267.6],
    [114.048026, 36.093311, 255.7],
    [114.041602, 36.102055, 377.5]
  ])
}
 
export function mapFlyToPoint() {
  map.flyToPoint([113.939351, 36.068144, 350.9])
}
 
export function mapCancelFlyTo() {
  map.cancelFlyTo()
}