@go-home-early/go-home-early98 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @go-home-early/go-home-early98 might be problematic. Click here for more details.
- package/README.md +28 -16
- package/dist/go-home-early.umd.js +5 -5
- package/package.json +2 -16
- package/src/packages/Cesium/DrawMap/DrawJs/CesiumEntityEdit.js +427 -0
- package/src/packages/Cesium/DrawMap/DrawJs/CreatePolygonOnGround.js +202 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawAttackArrow.js +477 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawBillboard.js +114 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawCircle.js +311 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawCircleTY.js +237 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawCurve.js +256 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPincerArrow.js +584 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPoint.js +158 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPolygon.js +215 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPolyline.js +213 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPolylineJT.js +218 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawProFile.js +314 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawRectangle.js +215 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawstraightArrow.js +364 -0
- package/src/packages/Cesium/DrawMap/DrawJs/MeasurePolygon.js +337 -0
- package/src/packages/Cesium/DrawMap/DrawJs/MeasurePolyline.js +285 -0
- package/src/packages/Cesium/DrawMap/DrawJs/ReminderTip.js +78 -0
- package/src/packages/Cesium/DrawMap/DrawJs/SlopeAspect.js +436 -0
- package/src/packages/Cesium/DrawMap/DrawJs/measureLength.js +177 -0
- package/src/packages/Cesium/DrawMap/index.vue +272 -0
- package/src/packages/Cesium/components/LocationDialog.vue +283 -0
- package/src/packages/Cesium/components/Popup.vue +591 -0
- package/src/packages/Cesium/components/PoumianDialog.vue +200 -0
- package/src/packages/Cesium/imgs/add-off.png +0 -0
- package/src/packages/Cesium/imgs/add.png +0 -0
- package/src/packages/Cesium/imgs/circle.png +0 -0
- package/src/packages/Cesium/imgs/icon-position-blue.png +0 -0
- package/src/packages/Cesium/imgs/line.png +0 -0
- package/src/packages/Cesium/imgs/map-delete.png +0 -0
- package/src/packages/Cesium/imgs/map.png +0 -0
- package/src/packages/Cesium/imgs/orientation-bg.svg +14 -0
- package/src/packages/Cesium/imgs/orientation.svg +21 -0
- package/src/packages/Cesium/imgs/poi.png +0 -0
- package/src/packages/Cesium/imgs/point.png +0 -0
- package/src/packages/Cesium/imgs/polygon.png +0 -0
- package/src/packages/Cesium/imgs/popup/back-popup-img.png +0 -0
- package/src/packages/Cesium/imgs/popup/backimg-btn.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-bd.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-btn.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-ft.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-hd.png +0 -0
- package/src/packages/Cesium/imgs/reduce-off.png +0 -0
- package/src/packages/Cesium/index.md +292 -0
- package/src/packages/Cesium/index.vue +3830 -0
- package/src/packages/Cesium/materials/CircularDiffusionMaterialProperty.js +98 -0
- package/src/packages/Cesium/materials/CircularRippleMaterialProperty.js +126 -0
- package/src/packages/Cesium/materials/PolylineArrowMaterialProperty.js +109 -0
- package/src/packages/Cesium/utils/MeasureHeight.js +261 -0
- package/src/packages/Cesium/utils/MeasureTools.js +1188 -0
- package/src/packages/index.js +33 -0
- package/src/packages/utils/charts.js +54 -0
- package/src/packages/utils/index.js +50 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// MeasurePolygon
|
|
2
|
+
/*
|
|
3
|
+
绘制面测量面积
|
|
4
|
+
*/
|
|
5
|
+
class MeasurePolygon {
|
|
6
|
+
constructor(arg) {
|
|
7
|
+
this.viewer = arg.viewer;
|
|
8
|
+
this.Cesium = arg.Cesium;
|
|
9
|
+
this.Text = arg.data.text || '';
|
|
10
|
+
this.Color = arg.data.color || '#000';
|
|
11
|
+
this.imgUrl = arg.data.imgUrl || '';
|
|
12
|
+
this.FontSize = arg.data.fontSize || 16;
|
|
13
|
+
this.callback = arg.data.callback || null;
|
|
14
|
+
this.pxNum = arg.data.pxNum || 5;
|
|
15
|
+
this.handler = null;
|
|
16
|
+
|
|
17
|
+
this.tempPoints = [];
|
|
18
|
+
this.floatingPoint = null;
|
|
19
|
+
this.radiansPerDegree = Math.PI / 180.0; // 角度转化为弧度(rad)
|
|
20
|
+
this.degreesPerRadian = 180.0 / Math.PI; // 弧度转化为角度
|
|
21
|
+
this.textArea = '';
|
|
22
|
+
this._polygon = null; // 活动面
|
|
23
|
+
this._polygonLast = null; // 最后一个面
|
|
24
|
+
this._positions = []; // 活动点
|
|
25
|
+
this._entities_point = []; // 脏数据
|
|
26
|
+
this._entities_polygon = []; // 脏数据
|
|
27
|
+
this._polygonData = null; // 用户构造面
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 返回最后活动面
|
|
31
|
+
get polygon() {
|
|
32
|
+
return this._polygonLast;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 返回面数据用于加载面
|
|
36
|
+
getData() {
|
|
37
|
+
return this._polygonData;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 加载面
|
|
41
|
+
loadPolygon(data) {
|
|
42
|
+
var $this = this;
|
|
43
|
+
return this.viewer.entities.add({
|
|
44
|
+
polygon: {
|
|
45
|
+
hierarchy: new $this.Cesium.PolygonHierarchy(data),
|
|
46
|
+
clampToGround: true,
|
|
47
|
+
show: true,
|
|
48
|
+
fill: true,
|
|
49
|
+
material: $this.Cesium.Color.fromCssColorString($this.Color),
|
|
50
|
+
width: 3,
|
|
51
|
+
outlineColor: $this.Cesium.Color.BLACK,
|
|
52
|
+
outlineWidth: 1,
|
|
53
|
+
outline: false
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 开始绘制
|
|
59
|
+
startCreate() {
|
|
60
|
+
var $this = this;
|
|
61
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
62
|
+
this.viewer.scene.canvas
|
|
63
|
+
);
|
|
64
|
+
this.handler.setInputAction(function(evt) {
|
|
65
|
+
// 单机开始绘制
|
|
66
|
+
var cartesian = $this.getCatesian3FromPX(evt.position);
|
|
67
|
+
if ($this._positions.length == 0) {
|
|
68
|
+
$this._positions.push(cartesian.clone());
|
|
69
|
+
}
|
|
70
|
+
$this.createPoint(cartesian);
|
|
71
|
+
$this._positions.push(cartesian);
|
|
72
|
+
|
|
73
|
+
// 在三维场景中添加点
|
|
74
|
+
var cartographic = $this.Cesium.Cartographic.fromCartesian(
|
|
75
|
+
$this._positions[$this._positions.length - 1]
|
|
76
|
+
);
|
|
77
|
+
var longitudeString = $this.Cesium.Math.toDegrees(cartographic.longitude);
|
|
78
|
+
var latitudeString = $this.Cesium.Math.toDegrees(cartographic.latitude);
|
|
79
|
+
var heightString = cartographic.height;
|
|
80
|
+
var labelText =
|
|
81
|
+
'(' +
|
|
82
|
+
longitudeString.toFixed(2) +
|
|
83
|
+
',' +
|
|
84
|
+
latitudeString.toFixed(2) +
|
|
85
|
+
')';
|
|
86
|
+
$this.tempPoints.push({
|
|
87
|
+
lon: longitudeString,
|
|
88
|
+
lat: latitudeString,
|
|
89
|
+
hei: heightString
|
|
90
|
+
});
|
|
91
|
+
$this.floatingPoint = $this.viewer.entities.add({
|
|
92
|
+
name: '多边形面积',
|
|
93
|
+
position: $this._positions[$this._positions.length - 1],
|
|
94
|
+
openwindow: false,
|
|
95
|
+
point: {
|
|
96
|
+
pixelSize: 5,
|
|
97
|
+
color: $this.Cesium.Color.RED,
|
|
98
|
+
outlineColor: $this.Cesium.Color.WHITE,
|
|
99
|
+
outlineWidth: 2,
|
|
100
|
+
heightReference: $this.Cesium.HeightReference.CLAMP_TO_GROUND
|
|
101
|
+
},
|
|
102
|
+
label: {
|
|
103
|
+
// text: labelText,
|
|
104
|
+
text: labelText,
|
|
105
|
+
font: '14px sans-serif',
|
|
106
|
+
fillColor: $this.Cesium.Color.YELLOW,
|
|
107
|
+
style: $this.Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
108
|
+
// outlineWidth: 2,
|
|
109
|
+
verticalOrigin: $this.Cesium.VerticalOrigin.BOTTOM,
|
|
110
|
+
pixelOffset: new $this.Cesium.Cartesian2(20, -20),
|
|
111
|
+
distanceDisplayCondition: new $this.Cesium.DistanceDisplayCondition(
|
|
112
|
+
10,
|
|
113
|
+
10000000
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
118
|
+
this.handler.setInputAction(function(evt) {
|
|
119
|
+
// 移动时绘制面
|
|
120
|
+
if ($this._positions.length < 1) return;
|
|
121
|
+
var cartesian = $this.getCatesian3FromPX(evt.endPosition);
|
|
122
|
+
if ($this._positions.length == 3) {
|
|
123
|
+
if (!$this.Cesium.defined($this._polygon)) {
|
|
124
|
+
$this._polygon = $this.createPolygon();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
$this._positions.pop();
|
|
128
|
+
$this._positions.push(cartesian);
|
|
129
|
+
}, $this.Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
130
|
+
this.handler.setInputAction(function(evt) {
|
|
131
|
+
if (!$this._polygon) return;
|
|
132
|
+
var cartesian = $this.getCatesian3FromPX(evt.position);
|
|
133
|
+
console.log(`output->$this.tempPoints`, $this.tempPoints);
|
|
134
|
+
// if ($this.tempPoints.length < 4) {
|
|
135
|
+
// $this.handler.destroy();
|
|
136
|
+
// return;
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
$this._positions.pop();
|
|
140
|
+
$this._positions.push(cartesian);
|
|
141
|
+
$this.createPoint(cartesian); // 创建点
|
|
142
|
+
|
|
143
|
+
// 在三维场景中添加点
|
|
144
|
+
var cartographic = $this.Cesium.Cartographic.fromCartesian(
|
|
145
|
+
$this._positions[$this._positions.length - 1]
|
|
146
|
+
);
|
|
147
|
+
var longitudeString = $this.Cesium.Math.toDegrees(cartographic.longitude);
|
|
148
|
+
var latitudeString = $this.Cesium.Math.toDegrees(cartographic.latitude);
|
|
149
|
+
var heightString = cartographic.height;
|
|
150
|
+
|
|
151
|
+
$this.tempPoints.push({
|
|
152
|
+
lon: longitudeString,
|
|
153
|
+
lat: latitudeString,
|
|
154
|
+
hei: heightString
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
$this.textArea = $this.getArea($this.tempPoints) + '平方公里';
|
|
158
|
+
$this.viewer.entities.add({
|
|
159
|
+
name: '多边形面积',
|
|
160
|
+
openwindow: false,
|
|
161
|
+
position: $this._positions[$this._positions.length - 1],
|
|
162
|
+
label: {
|
|
163
|
+
text: $this.textArea,
|
|
164
|
+
font: '18px sans-serif',
|
|
165
|
+
fillColor: $this.Cesium.Color.GOLD,
|
|
166
|
+
style: $this.Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
167
|
+
outlineWidth: 2,
|
|
168
|
+
verticalOrigin: $this.Cesium.VerticalOrigin.BOTTOM,
|
|
169
|
+
pixelOffset: new $this.Cesium.Cartesian2(20, -40),
|
|
170
|
+
heightReference: $this.Cesium.HeightReference.CLAMP_TO_GROUND
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
$this._polygonData = $this._positions.concat();
|
|
175
|
+
$this.viewer.entities.remove($this._positions); // 移除
|
|
176
|
+
$this._positions = null;
|
|
177
|
+
$this._positions = [];
|
|
178
|
+
var Polygon = $this.loadPolygon($this._polygonData);
|
|
179
|
+
$this._entities_polygon.push(Polygon);
|
|
180
|
+
$this._polygonLast = Polygon;
|
|
181
|
+
if (typeof $this.callback == 'function') {
|
|
182
|
+
$this.callback(Polygon);
|
|
183
|
+
}
|
|
184
|
+
$this.handler.destroy();
|
|
185
|
+
}, $this.Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 创建点击删除事件
|
|
189
|
+
creatDeleteClick(isSelect) {
|
|
190
|
+
const $this = this;
|
|
191
|
+
if (isSelect) {
|
|
192
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
193
|
+
$this.viewer.scene.canvas
|
|
194
|
+
);
|
|
195
|
+
this.handler.setInputAction(function(movement) {
|
|
196
|
+
var pick = $this.viewer.scene.pick(movement.position, 3, 3);
|
|
197
|
+
|
|
198
|
+
if (!pick) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
$this.viewer.entities.removeById(pick.id._id);
|
|
202
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
203
|
+
} else {
|
|
204
|
+
this.handler.destroy();
|
|
205
|
+
this.handler = null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 创建面
|
|
210
|
+
createPolygon() {
|
|
211
|
+
var $this = this;
|
|
212
|
+
var polygon = this.viewer.entities.add({
|
|
213
|
+
polygon: {
|
|
214
|
+
hierarchy: new $this.Cesium.CallbackProperty(function() {
|
|
215
|
+
return new $this.Cesium.PolygonHierarchy($this._positions);
|
|
216
|
+
}, false),
|
|
217
|
+
clampToGround: true,
|
|
218
|
+
show: true,
|
|
219
|
+
fill: true,
|
|
220
|
+
material:
|
|
221
|
+
$this.Cesium.Color.fromCssColorString('#ffffff').withAlpha(0.5),
|
|
222
|
+
width: 3,
|
|
223
|
+
outlineColor: $this.Cesium.Color.BLACK,
|
|
224
|
+
outlineWidth: 1,
|
|
225
|
+
outline: false
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
$this._entities_polygon.push(polygon);
|
|
229
|
+
return polygon;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 创建点
|
|
233
|
+
createPoint(cartesian) {
|
|
234
|
+
var $this = this;
|
|
235
|
+
var point = this.viewer.entities.add({
|
|
236
|
+
position: cartesian,
|
|
237
|
+
point: {
|
|
238
|
+
pixelSize: 10,
|
|
239
|
+
color: $this.Cesium.Color.YELLOW
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
$this._entities_point.push(point);
|
|
243
|
+
return point;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 销毁事件
|
|
247
|
+
destroy() {
|
|
248
|
+
if (this.handler) {
|
|
249
|
+
this.handler.destroy();
|
|
250
|
+
this.handler = null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 清空实体对象
|
|
255
|
+
clear() {
|
|
256
|
+
for (let i = 0; i < this._entities_point.length; i++) {
|
|
257
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
258
|
+
}
|
|
259
|
+
for (let i = 0; i < this._entities_polygon.length; i++) {
|
|
260
|
+
this.viewer.entities.remove(this._entities_polygon[i]);
|
|
261
|
+
}
|
|
262
|
+
this._polygon = null; // 活动面
|
|
263
|
+
this._polygonLast = null; // 最后一个面
|
|
264
|
+
this._positions = []; // 活动点
|
|
265
|
+
this._entities_point = []; // 脏数据
|
|
266
|
+
this._entities_polygon = []; // 脏数据
|
|
267
|
+
this._polygonData = null; // 用户构造面
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
getCatesian3FromPX(px) {
|
|
271
|
+
var cartesian;
|
|
272
|
+
var ray = this.viewer.camera.getPickRay(px);
|
|
273
|
+
if (!ray) return null;
|
|
274
|
+
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
|
|
275
|
+
return cartesian;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// 计算多边形面积
|
|
279
|
+
getArea(points) {
|
|
280
|
+
var res = 0;
|
|
281
|
+
// 拆分三角曲面
|
|
282
|
+
for (var i = 0; i < points.length - 2; i++) {
|
|
283
|
+
var j = (i + 1) % points.length;
|
|
284
|
+
var k = (i + 2) % points.length;
|
|
285
|
+
var totalAngle = this.Angle(points[i], points[j], points[k]);
|
|
286
|
+
var dis_temp1 = this.distance(this._positions[i], this._positions[j]);
|
|
287
|
+
var dis_temp2 = this.distance(this._positions[j], this._positions[k]);
|
|
288
|
+
res += dis_temp1 * dis_temp2 * Math.abs(Math.sin(totalAngle));
|
|
289
|
+
}
|
|
290
|
+
return (res / 1000000.0).toFixed(4);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* 角度*/
|
|
294
|
+
Angle(p1, p2, p3) {
|
|
295
|
+
var bearing21 = this.Bearing(p2, p1);
|
|
296
|
+
var bearing23 = this.Bearing(p2, p3);
|
|
297
|
+
var angle = bearing21 - bearing23;
|
|
298
|
+
if (angle < 0) {
|
|
299
|
+
angle += 360;
|
|
300
|
+
}
|
|
301
|
+
return angle;
|
|
302
|
+
}
|
|
303
|
+
/* 方向*/
|
|
304
|
+
Bearing(from, to) {
|
|
305
|
+
var lat1 = from.lat * this.radiansPerDegree;
|
|
306
|
+
var lon1 = from.lon * this.radiansPerDegree;
|
|
307
|
+
var lat2 = to.lat * this.radiansPerDegree;
|
|
308
|
+
var lon2 = to.lon * this.radiansPerDegree;
|
|
309
|
+
var angle = -Math.atan2(
|
|
310
|
+
Math.sin(lon1 - lon2) * Math.cos(lat2),
|
|
311
|
+
Math.cos(lat1) * Math.sin(lat2) -
|
|
312
|
+
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2)
|
|
313
|
+
);
|
|
314
|
+
if (angle < 0) {
|
|
315
|
+
angle += Math.PI * 2.0;
|
|
316
|
+
}
|
|
317
|
+
angle = angle * this.degreesPerRadian; // 角度
|
|
318
|
+
return angle;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
distance(point1, point2) {
|
|
322
|
+
var point1cartographic = this.Cesium.Cartographic.fromCartesian(point1);
|
|
323
|
+
var point2cartographic = this.Cesium.Cartographic.fromCartesian(point2);
|
|
324
|
+
/** 根据经纬度计算出距离**/
|
|
325
|
+
var geodesic = new this.Cesium.EllipsoidGeodesic();
|
|
326
|
+
geodesic.setEndPoints(point1cartographic, point2cartographic);
|
|
327
|
+
var s = geodesic.surfaceDistance;
|
|
328
|
+
// 返回两点之间的距离
|
|
329
|
+
s = Math.sqrt(
|
|
330
|
+
Math.pow(s, 2) +
|
|
331
|
+
Math.pow(point2cartographic.height - point1cartographic.height, 2)
|
|
332
|
+
);
|
|
333
|
+
return s;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export default MeasurePolygon;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// DrawPolyline
|
|
2
|
+
/*
|
|
3
|
+
绘制线
|
|
4
|
+
*/
|
|
5
|
+
class DrawPolyline {
|
|
6
|
+
constructor(arg) {
|
|
7
|
+
this.viewer = arg.viewer;
|
|
8
|
+
this.Cesium = arg.Cesium;
|
|
9
|
+
this.Text = arg.data.text || '';
|
|
10
|
+
this.Color = arg.data.color || '#000';
|
|
11
|
+
this.imgUrl = arg.data.imgUrl || '';
|
|
12
|
+
this.FontSize = arg.data.fontSize || 16;
|
|
13
|
+
this.callback = arg.data.callback || null;
|
|
14
|
+
this.pxNum = arg.data.pxNum || 5;
|
|
15
|
+
this.distance = 0;
|
|
16
|
+
this.handler = null;
|
|
17
|
+
this.labelPt = null;
|
|
18
|
+
this.textDisance = '';
|
|
19
|
+
this._polyline = null; // 活动线
|
|
20
|
+
this._polylineLast = null; // 最后一条线
|
|
21
|
+
this._positions = []; // 活动点
|
|
22
|
+
this._entities_point = []; // 脏数据
|
|
23
|
+
this._entities_line = []; // 脏数据
|
|
24
|
+
this._polylineData = null; // 用于构造线数据
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 返回最后活动线
|
|
28
|
+
get line() {
|
|
29
|
+
return this._polylineLast;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 返回线数据用于加载线
|
|
33
|
+
getData() {
|
|
34
|
+
return this._polylineData;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 加载线
|
|
38
|
+
loadPolyline(data) {
|
|
39
|
+
const $this = this;
|
|
40
|
+
const polyline = this.viewer.entities.add({
|
|
41
|
+
polyline: {
|
|
42
|
+
positions: data,
|
|
43
|
+
show: true,
|
|
44
|
+
material: $this.Cesium.Color.fromCssColorString($this.Color),
|
|
45
|
+
width: $this.pxNum,
|
|
46
|
+
clampToGround: true
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return polyline;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 开始创建
|
|
53
|
+
startCreate() {
|
|
54
|
+
const $this = this;
|
|
55
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
56
|
+
this.viewer.scene.canvas
|
|
57
|
+
);
|
|
58
|
+
this.handler.setInputAction(function(evt) {
|
|
59
|
+
// 单机开始绘制
|
|
60
|
+
// 屏幕坐标转地形上坐标
|
|
61
|
+
const cartesian = $this.getCatesian3FromPX(evt.position);
|
|
62
|
+
if ($this._positions.length == 0) {
|
|
63
|
+
$this._positions.push(cartesian.clone());
|
|
64
|
+
}
|
|
65
|
+
$this._positions.push(cartesian);
|
|
66
|
+
if ($this._positions.length > 2) {
|
|
67
|
+
$this.getSpaceDistance($this._positions);
|
|
68
|
+
}
|
|
69
|
+
// 记录鼠标单击时的节点位置,异步计算贴地距离
|
|
70
|
+
$this.labelPt = $this._positions[$this._positions.length - 1];
|
|
71
|
+
$this.createPoint(cartesian); // 绘制点
|
|
72
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
73
|
+
this.handler.setInputAction(function(evt) {
|
|
74
|
+
// 移动时绘制线
|
|
75
|
+
if ($this._positions.length < 1) return;
|
|
76
|
+
const cartesian = $this.getCatesian3FromPX(evt.endPosition);
|
|
77
|
+
if (!$this.Cesium.defined($this._polyline)) {
|
|
78
|
+
$this._polyline = $this.createPolyline();
|
|
79
|
+
}
|
|
80
|
+
if ($this._polyline) {
|
|
81
|
+
$this._positions.pop();
|
|
82
|
+
$this._positions.push(cartesian);
|
|
83
|
+
}
|
|
84
|
+
}, $this.Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
85
|
+
this.handler.setInputAction(function(evt) {
|
|
86
|
+
if (!$this._polyline) return;
|
|
87
|
+
const cartesian = $this.getCatesian3FromPX(evt.position);
|
|
88
|
+
if ($this._positions.length >= 2) {
|
|
89
|
+
$this.viewer.entities.add({
|
|
90
|
+
name: '贴地距离',
|
|
91
|
+
position: $this.labelPt,
|
|
92
|
+
openwindow: false,
|
|
93
|
+
point: {
|
|
94
|
+
pixelSize: 5,
|
|
95
|
+
color: $this.Cesium.Color.RED,
|
|
96
|
+
outlineColor: $this.Cesium.Color.WHITE,
|
|
97
|
+
outlineWidth: 2
|
|
98
|
+
},
|
|
99
|
+
label: {
|
|
100
|
+
text: $this.textDisance,
|
|
101
|
+
// text: lonLat + textDisance,
|
|
102
|
+
font: '18px sans-serif',
|
|
103
|
+
fillColor: $this.Cesium.Color.GOLD,
|
|
104
|
+
style: $this.Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
105
|
+
outlineWidth: 2,
|
|
106
|
+
verticalOrigin: $this.Cesium.VerticalOrigin.BOTTOM,
|
|
107
|
+
pixelOffset: new $this.Cesium.Cartesian2(20, -20)
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
$this._positions.pop();
|
|
112
|
+
// $this._positions.push(cartesian);
|
|
113
|
+
// $this.createPoint(cartesian); // 绘制点
|
|
114
|
+
$this._polylineData = $this._positions.concat();
|
|
115
|
+
$this.viewer.entities.remove($this._polyline); // 移除
|
|
116
|
+
$this._polyline = null;
|
|
117
|
+
$this._positions = [];
|
|
118
|
+
const line = $this.loadPolyline($this._polylineData); // 加载线
|
|
119
|
+
$this._entities_line.push(line);
|
|
120
|
+
$this._polylineLast = line;
|
|
121
|
+
if (typeof $this.callback == 'function') {
|
|
122
|
+
$this.callback(line);
|
|
123
|
+
}
|
|
124
|
+
$this.handler.destroy();
|
|
125
|
+
}, $this.Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 创建点击删除事件
|
|
129
|
+
creatDeleteClick(isSelect) {
|
|
130
|
+
const $this = this;
|
|
131
|
+
if (isSelect) {
|
|
132
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
133
|
+
$this.viewer.scene.canvas
|
|
134
|
+
);
|
|
135
|
+
this.handler.setInputAction(function(movement) {
|
|
136
|
+
var pick = $this.viewer.scene.pick(movement.position, 3, 3);
|
|
137
|
+
|
|
138
|
+
if (!pick) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
$this.viewer.entities.removeById(pick.id._id);
|
|
142
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
143
|
+
} else {
|
|
144
|
+
this.handler.destroy();
|
|
145
|
+
this.handler = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 创建点
|
|
150
|
+
createPoint(cartesian) {
|
|
151
|
+
const $this = this;
|
|
152
|
+
const point = this.viewer.entities.add({
|
|
153
|
+
position: cartesian,
|
|
154
|
+
point: {
|
|
155
|
+
pixelSize: 10,
|
|
156
|
+
color: $this.Cesium.Color.YELLOW
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
$this._entities_point.push(point);
|
|
160
|
+
return point;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 创建线
|
|
164
|
+
createPolyline() {
|
|
165
|
+
const $this = this;
|
|
166
|
+
const polyline = this.viewer.entities.add({
|
|
167
|
+
polyline: {
|
|
168
|
+
// 使用cesium的peoperty
|
|
169
|
+
positions: new $this.Cesium.CallbackProperty(function() {
|
|
170
|
+
return $this._positions;
|
|
171
|
+
}, false),
|
|
172
|
+
show: true,
|
|
173
|
+
material:
|
|
174
|
+
$this.Cesium.Color.fromCssColorString('#ffffff').withAlpha(0.5),
|
|
175
|
+
width: $this.pxNum,
|
|
176
|
+
clampToGround: true
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
$this._entities_line.push(polyline);
|
|
180
|
+
return polyline;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 销毁
|
|
184
|
+
destroy() {
|
|
185
|
+
if (this.handler) {
|
|
186
|
+
this.handler.destroy();
|
|
187
|
+
this.handler = null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 清空实体对象
|
|
192
|
+
clear() {
|
|
193
|
+
for (let i = 0; i < this._entities_point.length; i++) {
|
|
194
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
195
|
+
}
|
|
196
|
+
for (let i = 0; i < this._entities_line.length; i++) {
|
|
197
|
+
this.viewer.entities.remove(this._entities_line[i]);
|
|
198
|
+
}
|
|
199
|
+
this._polyline = null;
|
|
200
|
+
this._positions = [];
|
|
201
|
+
this._entities_point = []; // 脏数据
|
|
202
|
+
this._entities_line = []; // 脏数据
|
|
203
|
+
this._polylineData = null; // 用于构造线数据
|
|
204
|
+
this._polylineLast = null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getCatesian3FromPX(px) {
|
|
208
|
+
let cartesian = null;
|
|
209
|
+
const ray = this.viewer.camera.getPickRay(px);
|
|
210
|
+
if (!ray) return null;
|
|
211
|
+
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
|
|
212
|
+
return cartesian;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 空间两点距离计算函数
|
|
216
|
+
getSpaceDistance(positions) {
|
|
217
|
+
// 只计算最后一截,与前面累加
|
|
218
|
+
// 因move和鼠标左击事件,最后两个点坐标重复
|
|
219
|
+
const i = positions.length - 3;
|
|
220
|
+
const point1cartographic = this.Cesium.Cartographic.fromCartesian(
|
|
221
|
+
positions[i]
|
|
222
|
+
);
|
|
223
|
+
const point2cartographic = this.Cesium.Cartographic.fromCartesian(
|
|
224
|
+
positions[i + 1]
|
|
225
|
+
);
|
|
226
|
+
this.getTerrainDistance(point1cartographic, point2cartographic);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
getTerrainDistance(point1cartographic, point2cartographic) {
|
|
230
|
+
const $this = this;
|
|
231
|
+
const geodesic = new $this.Cesium.EllipsoidGeodesic();
|
|
232
|
+
geodesic.setEndPoints(point1cartographic, point2cartographic);
|
|
233
|
+
const s = geodesic.surfaceDistance;
|
|
234
|
+
const cartoPts = [point1cartographic];
|
|
235
|
+
for (let jj = 1000; jj < s; jj += 1000) {
|
|
236
|
+
// 分段采样计算距离
|
|
237
|
+
const cartoPt = geodesic.interpolateUsingSurfaceDistance(jj);
|
|
238
|
+
cartoPts.push(cartoPt);
|
|
239
|
+
}
|
|
240
|
+
cartoPts.push(point2cartographic);
|
|
241
|
+
// 返回两点之间的距离
|
|
242
|
+
// let promise = this.Cesium.sampleTerrain(
|
|
243
|
+
// this.viewer.terrainProvider,
|
|
244
|
+
// 8,
|
|
245
|
+
// cartoPts
|
|
246
|
+
// );
|
|
247
|
+
$this.Cesium.sampleTerrain($this.viewer.terrainProvider, 8, cartoPts).then(
|
|
248
|
+
function(updatedPositions) {
|
|
249
|
+
console.log(`output->updatedPositions`, updatedPositions);
|
|
250
|
+
for (let jj = 0; jj < updatedPositions.length - 1; jj++) {
|
|
251
|
+
const geoD = new $this.Cesium.EllipsoidGeodesic();
|
|
252
|
+
geoD.setEndPoints(updatedPositions[jj], updatedPositions[jj + 1]);
|
|
253
|
+
let innerS = geoD.surfaceDistance;
|
|
254
|
+
innerS = Math.sqrt(
|
|
255
|
+
Math.pow(innerS, 2) +
|
|
256
|
+
Math.pow(
|
|
257
|
+
updatedPositions[jj + 1].height - updatedPositions[jj].height,
|
|
258
|
+
2
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
$this.distance += innerS;
|
|
262
|
+
}
|
|
263
|
+
// 在三维场景中添加Label
|
|
264
|
+
const lon1 = $this.viewer.scene.globe.ellipsoid.cartesianToCartographic(
|
|
265
|
+
$this.labelPt
|
|
266
|
+
).longitude;
|
|
267
|
+
const lat1 = $this.viewer.scene.globe.ellipsoid.cartesianToCartographic(
|
|
268
|
+
$this.labelPt
|
|
269
|
+
).latitude;
|
|
270
|
+
const lonLat =
|
|
271
|
+
'(' +
|
|
272
|
+
$this.Cesium.Math.toDegrees(lon1).toFixed(2) +
|
|
273
|
+
',' +
|
|
274
|
+
$this.Cesium.Math.toDegrees(lat1).toFixed(2) +
|
|
275
|
+
')';
|
|
276
|
+
$this.textDisance = $this.distance.toFixed(2) + '米';
|
|
277
|
+
if ($this.distance > 10000) {
|
|
278
|
+
$this.textDisance = ($this.distance / 1000.0).toFixed(2) + '千米';
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export default DrawPolyline;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 标绘提示弹窗tip
|
|
3
|
+
* @Author: Wang jianLei
|
|
4
|
+
* @Date: 2022-04-14 20:52:03
|
|
5
|
+
* @Last Modified by: 宋木桐
|
|
6
|
+
* @Last Modified time: 2024-08-20 15:52:54
|
|
7
|
+
*/
|
|
8
|
+
const CreateRemindertip = function (arr, position, show) {
|
|
9
|
+
let tooltip = document.getElementById("toolTip");
|
|
10
|
+
let style, _x, _y, _color;
|
|
11
|
+
if (arr && typeof arr === "object") {
|
|
12
|
+
style = arr;
|
|
13
|
+
}
|
|
14
|
+
if (style && style.origin) {
|
|
15
|
+
style.origin === "center" && ((_x = 15), (_y = -12));
|
|
16
|
+
style.origin === "top" && ((_x = 15), (_y = -44));
|
|
17
|
+
style.origin === "bottom" && ((_x = 15), (_y = 20));
|
|
18
|
+
} else {
|
|
19
|
+
(_x = 15), (_y = 20);
|
|
20
|
+
}
|
|
21
|
+
if (style && style.color) {
|
|
22
|
+
style.color === "white" &&
|
|
23
|
+
(_color = "background: rgba(255, 255, 255, 0.8);color: black;");
|
|
24
|
+
style.color === "black" &&
|
|
25
|
+
(_color = "background: rgba(0, 0, 0, 0.5);color: white;");
|
|
26
|
+
style.color === "yellow" &&
|
|
27
|
+
(_color =
|
|
28
|
+
"color: black;background-color: #ffcc33;border: 1px solid white;");
|
|
29
|
+
} else {
|
|
30
|
+
_color = "background: rgba(0, 0, 0, 0.5);color: white;";
|
|
31
|
+
}
|
|
32
|
+
if (!tooltip) {
|
|
33
|
+
const viewerDom = document.getElementsByClassName("cesium-viewer")[0];
|
|
34
|
+
let elementbottom = document.createElement("div");
|
|
35
|
+
viewerDom.append(elementbottom);
|
|
36
|
+
let html =
|
|
37
|
+
'<div id="toolTip" style="display: none;pointer-events: none;position: absolute;z-index: 1000;opacity: 0.8;border-radius: 4px;padding: 4px 8px;white-space: nowrap;font-family:黑体;color:white;font-weight: bolder;font-size: 18px;' +
|
|
38
|
+
_color +
|
|
39
|
+
'"></div>';
|
|
40
|
+
viewerDom.insertAdjacentHTML("beforeend", html);
|
|
41
|
+
tooltip = document.getElementById("toolTip");
|
|
42
|
+
}
|
|
43
|
+
if (show) {
|
|
44
|
+
tooltip.innerHTML = arr;
|
|
45
|
+
tooltip.style.left = position.x + _x + "px";
|
|
46
|
+
tooltip.style.top = position.y + _y + "px";
|
|
47
|
+
tooltip.style.display = "block";
|
|
48
|
+
} else {
|
|
49
|
+
tooltip.style.display = "none";
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
tooltip: tooltip,
|
|
53
|
+
style: style,
|
|
54
|
+
showAt: function (position, text) {
|
|
55
|
+
this.tooltip.innerHTML = text;
|
|
56
|
+
if (this.style && this.style.origin) {
|
|
57
|
+
this.style.origin === "center" &&
|
|
58
|
+
((_x = 15), (_y = -this.tooltip.offsetHeight / 2));
|
|
59
|
+
this.style.origin === "top" &&
|
|
60
|
+
((_x = 15), (_y = -this.tooltip.offsetHeight - 20));
|
|
61
|
+
this.style.origin === "bottom" && ((_x = 15), (_y = 20));
|
|
62
|
+
} else {
|
|
63
|
+
(_x = 15), (_y = -this.tooltip.offsetHeight / 2);
|
|
64
|
+
}
|
|
65
|
+
this.tooltip.style.left = position.x + _x + "px";
|
|
66
|
+
this.tooltip.style.top = position.y + _y + "px";
|
|
67
|
+
this.tooltip.style.display = "block";
|
|
68
|
+
},
|
|
69
|
+
show: function (show) {
|
|
70
|
+
if (show) {
|
|
71
|
+
this.tooltip.style.display = "block";
|
|
72
|
+
} else {
|
|
73
|
+
this.tooltip.style.display = "none";
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export default CreateRemindertip;
|