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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
let satelliteSensor
let modelGraphic
let graphicLayer
const reverse = true // z轴方向,true朝向空中,false朝向地心
const converter = Cesium.Transforms.eastNorthUpToFixedFrame
// const converter = Cesium.Transforms.localFrameToFixedFrameGenerator('east', 'south')
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 0.072832, lng: 151.409367, alt: 29330818, heading: 10, pitch: -90 }
  },
  cameraController: {
    maximumZoomDistance: 9000000000,
    constrainedAxis: false // 解除在南北极区域鼠标操作限制
  }
}
 
export const eventTarget = new mars3d.BaseClass() // 事件对象,用于抛出事件到面板中
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @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 addModelGraphic(sensorParams) {
  const position = Cesium.Cartesian3.fromDegrees(sensorParams.model_x, sensorParams.model_y, sensorParams.model_z)
  // 加个模型
  modelGraphic = new mars3d.graphic.ModelEntity({
    name: "卫星模型",
    position: position,
    style: {
      url: "//data.mars3d.cn/gltf/mars/weixin.gltf",
      scale: 1,
      minimumPixelSize: 150,
      heading: sensorParams.headingValue,
      pitch: sensorParams.pitchValue,
      roll: sensorParams.rollValue
    }
  })
  graphicLayer.addGraphic(modelGraphic)
 
  // 打开3个轴进行显示对比
  modelGraphic.debugAxis = true
 
  // 视锥体
  satelliteSensor = new mars3d.graphic.SatelliteSensor({
    position: position,
    style: {
      sensorType: mars3d.graphic.SatelliteSensor.Type.Rect,
      angle1: sensorParams.angleValue1,
      angle2: sensorParams.angleValue2,
      heading: sensorParams.headingValue,
      pitch: sensorParams.pitchValue,
      roll: sensorParams.rollValue,
      color: "rgba(0,255,255,0.7)"
    },
    fixedFrameTransform: converter,
    reverse: reverse
  })
  graphicLayer.addGraphic(satelliteSensor)
}
 
/**
 *
 * @export
 * @param {*} x 经度
 * @param {*} y 纬度
 * @param {*} z 高度
 * @returns {void}
 */
export function updatePosition(x, y, z) {
  const position = Cesium.Cartesian3.fromDegrees(x, y, z)
  modelGraphic.position = position
  satelliteSensor.position = position
}
 
export function locate() {
  map.flyToGraphic(modelGraphic, { radius: modelGraphic.height * 2 })
}
 
// 方向角改变
export function headingChange(value) {
  modelGraphic.heading = value
  satelliteSensor.heading = value
}
 
// 俯仰角
export function pitchChange(value) {
  modelGraphic.pitch = value
  satelliteSensor.pitch = value
}
 
// 左右角
export function rollChange(value) {
  modelGraphic.roll = value
  satelliteSensor.roll = value
}
 
// 夹角1
export function angle1(value) {
  satelliteSensor.angle1 = value
}
 
// 夹角2
export function angle2(value) {
  satelliteSensor.angle2 = value
}
 
// 参考轴系显示与隐藏
export function chkShowModelMatrix(val) {
  modelGraphic.debugAxis = val
}
 
// 视椎体状态
export function sensorShowHide(val) {
  satelliteSensor.show = val
}
// 是否与地球相交
export function chkUnderground(val) {
  satelliteSensor.rayEllipsoid = val
}
 
// 类型选择
export function chkSensorType(value) {
  if (value === "1") {
    satelliteSensor.sensorType = mars3d.graphic.SatelliteSensor.Type.Conic
  } else {
    satelliteSensor.sensorType = mars3d.graphic.SatelliteSensor.Type.Rect
  }
}
 
export function lengthChange(value) {
  modelGraphic.debugAxisLength = value * 1000
}
 
export function clearAll() {
  map.graphicLayer.clear()
}
 
// 获取边界值
export function getRegion() {
  map.graphicLayer.clear()
 
  const coords = satelliteSensor.getAreaCoords() // 导出成像区边界坐标
  if (!coords || coords.length === 0) {
    globalMsg("当前与地球无成像区边")
    return
  }
  // 显示边界点,测试
  map.graphicLayer.clear()
 
  coords.forEach((position) => {
    const primitive = new mars3d.graphic.PointPrimitive({
      position: position,
      style: {
        color: "#ff0000",
        pixelSize: 8,
        outline: true,
        outlineColor: "#ffffff",
        outlineWidth: 2,
        clampToGround: true
      }
    })
    map.graphicLayer.addGraphic(primitive)
  })
}
 
export function getCenter() {
  map.graphicLayer.clear()
 
  const groundPosition = satelliteSensor.groundPosition
  if (!groundPosition) {
    globalMsg("当前与地球无交点")
    return
  }
 
  const primitive = new mars3d.graphic.PointPrimitive({
    position: groundPosition,
    style: {
      color: "#ff0000",
      pixelSize: 8,
      outline: true,
      outlineColor: "#ffffff",
      outlineWidth: 2,
      clampToGround: true
    }
  })
  map.graphicLayer.addGraphic(primitive)
 
  const point = mars3d.LngLatPoint.fromCartesian(groundPosition)
  globalMsg(point.toString())
}