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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
let contourLine
 
export const mapOptions = {
  scene: {
    center: { lat: 30.706401, lng: 116.08272, alt: 26859, heading: 5, pitch: -55 },
    showSun: false,
    showMoon: false,
    showSkyBox: false,
    showSkyAtmosphere: false,
    fog: false,
    globe: {
      showGroundAtmosphere: false,
      enableLighting: false
    }
  }
}
 
export const eventTabel = new mars3d.BaseClass()
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  addContourLine()
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
function addContourLine() {
  contourLine = new mars3d.thing.ContourLine({
    spacing: 100,
    width: 1.5,
    color: "rgba(255,0,0,0.8)",
    minHeight: -414.0,
    maxHeight: 8777.0,
    shadingAlpha: 0.6, /// 地表渲染的透明度
    colorScheme: {
      // 地表渲染的配色方案
      elevation: {
        step: [0.0, 0.045, 0.1, 0.15, 0.37, 0.54, 1.0],
        color: ["#000000", "#2747E0", "#D33B7D", "#D33038", "#FF9742", "#FF9742", "#ffd700"]
      },
      slope: {
        step: [0.0, 0.29, 0.5, Math.sqrt(2) / 2, 0.87, 0.91, 1.0],
        color: ["#000000", "#2747E0", "#D33B7D", "#D33038", "#FF9742", "#FF9742", "#ffd700"]
      },
      aspect: {
        step: [0.0, 0.2, 0.4, 0.6, 0.8, 0.9, 1.0],
        color: ["#000000", "#2747E0", "#D33B7D", "#D33038", "#FF9742", "#FF9742", "#ffd700"]
      }
    }
  })
  map.addThing(contourLine)
 
  // 演示的示例区域
  const areaItem = contourLine.addArea([
    [116.003125, 30.948354, 1103.66],
    [116.23964, 30.946376, 563.02],
    [116.223677, 30.802558, 522.04],
    [115.997891, 30.807484, 440.83]
  ])
  addTableItem(areaItem)
}
 
// 添加矩形
export function btnDrawExtent() {
  map.graphicLayer.startDraw({
    type: "rectangle",
    style: {
      color: "#007be6",
      opacity: 0.8,
      outline: false
    },
    success: function (graphic) {
      // 绘制成功后回调
      const positions = graphic.getOutlinePositions(false)
      map.graphicLayer.clear()
 
      console.log("绘制坐标为", JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))) // 方便测试拷贝坐标
 
      const areaItem = contourLine.addArea(positions)
      addTableItem(areaItem)
    }
  })
}
 
// 添加多边形
export function btnDraw() {
  map.graphicLayer.startDraw({
    type: "polygon",
    style: {
      color: "#007be6",
      opacity: 0.5,
      outline: false
    },
    success: function (graphic) {
      // 绘制成功后回调
      const positions = graphic.positionsShow
      map.graphicLayer.clear()
 
      console.log("绘制坐标为", JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))) // 方便测试拷贝坐标
 
      const areaItem = contourLine.addArea(positions)
      addTableItem(areaItem)
    }
  })
}
 
// 清除
export function clearAll() {
  contourLine.clear()
  table = []
}
 
// 滑动条控制
export function changeWidth(val) {
  if (val) {
    contourLine.width = val
  }
}
 
export function changeSpacing(val) {
  if (val) {
    contourLine.spacing = val
  }
}
 
// 改变颜色
export function changeColor(val) {
  contourLine.color = Cesium.Color.fromCssColorString(val)
}
 
// 等高线控制
export function showDengGX(val) {
  contourLine.contourShow = val
}
 
// 状态控制
export function chkClippingPlanes(val) {
  contourLine.showElseArea = val
}
 
// 阴影控制
export function changeShadingType(val) {
  contourLine.shadingType = val
}
 
let table = []
// 区域表格添加一行记录
function addTableItem(item) {
  table.push({ key: item.id, name: "区域" + item.id })
  eventTabel.fire("tableObject", { table })
}
export function changeTable(data) {
  table = data
}
 
// 表格操作
export function flyToGraphic(item) {
  const graphic = contourLine.getAreaById(item)
  map.flyToPositions(graphic.positions)
}
 
export function deletedGraphic(item) {
  const graphic = contourLine.getAreaById(item)
  contourLine.removeArea(graphic)
}
 
export function showHideArea(id, selected) {
  if (selected) {
    contourLine.showArea(id)
  } else {
    contourLine.hideArea(id)
  }
}