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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 30.841762, lng: 116.26537, alt: 3281, heading: 39, pitch: -63 }
  }
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
export function removeAll() {
  map.graphicLayer.clear()
 
  clearInterResult()
}
 
/**
 * 面插值
 *
 * @export
 * @param {number} val 步长
 * @returns {void}
 */
export function interPolygon(val) {
  map.graphicLayer.startDraw({
    type: "polygon",
    style: {
      color: "#29cf34",
      opacity: 0.3,
      outline: true,
      outlineColor: "#ffffff",
      clampToGround: true
    },
    success: function (graphic) {
      const positions = graphic.positionsShow
      map.graphicLayer.clear()
 
      const resultInter = mars3d.PolyUtil.interPolygon({
        scene: map.scene,
        positions: positions,
        splitNum: val // splitNum插值分割的个数
      })
 
      showInterResult(resultInter.list)
    }
  })
}
 
/**
 * 线插值
 *
 * @export
 * @param {number} val 步长
 * @returns {void}
 */
export function interLine(val) {
  map.graphicLayer.startDraw({
    type: "polyline",
    style: {
      color: "#55ff33",
      width: 3
    },
    success: function (graphic) {
      const positions = graphic.positionsShow
      map.graphicLayer.clear()
 
      const arrLine = mars3d.PolyUtil.interLine(positions, {
        splitNum: val // 插值分割的个数
      })
 
      showInterLineResult(arrLine)
    }
  })
}
 
/**
 * 线插值(高度等分)
 *
 * @export
 * @param {number} val 步长
 * @returns {void}
 */
export function interPolyline(val) {
  map.graphicLayer.startDraw({
    type: "polyline",
    style: {
      color: "#55ff33",
      width: 3,
      clampToGround: true
    },
    success: function (graphic) {
      const positions = graphic.positionsShow
      map.graphicLayer.clear()
 
      const arrLine = mars3d.PolyUtil.interPolyline({
        scene: map.scene,
        positions: positions,
        splitNum: val // 插值分割的个数
      })
 
      showInterLineResult(arrLine)
    }
  })
}
 
// 显示mars3d.polygon.interPolygon处理后的面内插值分析结果,主要用于测试对比
 
// 显示面的插值计算结果,方便比较分析
let interGraphicLayer
 
function clearInterResult() {
  if (!interGraphicLayer) {
    interGraphicLayer = new mars3d.layer.GraphicLayer()
 
    map.addLayer(interGraphicLayer)
  }
 
  interGraphicLayer.clear()
}
 
function showInterResult(list) {
  // 分析结果用于测试分析的,不做太多处理,直接清除之前的,只保留一个
  clearInterResult()
 
  let pt1, pt2, pt3
  for (let i = 0, len = list.length; i < len; i++) {
    const item = list[i]
 
    pt1 = item.point1.pointDM
    pt2 = item.point2.pointDM
    pt3 = item.point3.pointDM
 
    // 点
    for (const pt of [item.point1, item.point2, item.point3]) {
      const primitive = new mars3d.graphic.PointPrimitive({
        position: pt.pointDM,
        style: {
          pixelSize: 9,
          color: Cesium.Color.fromCssColorString("#ff0000").withAlpha(0.5)
        }
      })
      interGraphicLayer.addGraphic(primitive)
 
      primitive.bindTooltip("点高度:" + mars3d.MeasureUtil.formatDistance(pt.height))
    }
 
    // 横截面面积
    item.area = item.area || mars3d.MeasureUtil.getTriangleArea(pt1, pt2, pt3)
 
    // 三角网及边线
    const positions = [pt1, pt2, pt3, pt1]
 
    // 三角网面(单击用)
    const primitivePoly = new mars3d.graphic.PolygonPrimitive({
      positions: positions,
      style: {
        material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Color, {
          color: Cesium.Color.fromCssColorString("#ffffff").withAlpha(0.01)
        })
      }
    })
    interGraphicLayer.addGraphic(primitivePoly)
    primitivePoly.bindTooltip("三角面积:" + mars3d.MeasureUtil.formatArea(item.area) + "(第" + i + "个)")
 
    // 三角网边线
    const primitiveLine = new mars3d.graphic.PolylinePrimitive({
      positions: positions,
      style: {
        width: 1,
        material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Color, {
          color: Cesium.Color.fromCssColorString("#ffff00").withAlpha(0.3)
        })
      }
    })
    interGraphicLayer.addGraphic(primitiveLine)
  }
}
 
// 在f80_interPoly等示例中使用
function showInterLineResult(list) {
  // 分析结果用于测试分析的,不做太多处理,直接清除之前的,只保留最后一个
  clearInterResult()
 
  const colorList = [Cesium.Color.fromCssColorString("#ffff00"), Cesium.Color.fromCssColorString("#00ffff")]
 
  for (let i = 1, len = list.length; i < len; i++) {
    const pt1 = list[i - 1]
    const pt2 = list[i]
 
    const color = colorList[i % 2]
 
    const graphic = new mars3d.graphic.PolylineEntity({
      positions: [pt1, pt2],
      style: {
        width: 3,
        material: color,
        depthFailMaterial: color.withAlpha(0.3)
      }
    })
    interGraphicLayer.addGraphic(graphic)
    graphic.bindTooltip("长度:" + mars3d.MeasureUtil.formatDistance(Cesium.Cartesian3.distance(pt1, pt2)) + "(第" + i + "段)")
  }
}