@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,1188 @@
|
|
|
1
|
+
import { height } from "dom-helpers";
|
|
2
|
+
import * as Cesium from 'cesium';
|
|
3
|
+
const MeasureTools = (function (Cesium) {
|
|
4
|
+
/**
|
|
5
|
+
* 绘制对象
|
|
6
|
+
* @param viewer
|
|
7
|
+
* @param options
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
function _(viewer, options = {}) {
|
|
11
|
+
if (viewer && viewer instanceof Cesium.Viewer) {
|
|
12
|
+
this._drawLayer = new Cesium.CustomDataSource('measureLayer');
|
|
13
|
+
|
|
14
|
+
viewer && viewer.dataSources.add(this._drawLayer);
|
|
15
|
+
|
|
16
|
+
this._basePath = options.basePath || '';
|
|
17
|
+
|
|
18
|
+
this._viewer = viewer;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
_.prototype = {
|
|
22
|
+
/***
|
|
23
|
+
* 坐标转换 84转笛卡尔
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} {lng,lat,alt} 地理坐标
|
|
26
|
+
*
|
|
27
|
+
* @return {Object} Cartesian3 三维位置坐标
|
|
28
|
+
*/
|
|
29
|
+
transformWGS84ToCartesian: function (position, alt) {
|
|
30
|
+
if (this._viewer) {
|
|
31
|
+
return position
|
|
32
|
+
? Cesium.Cartesian3.fromDegrees(
|
|
33
|
+
position.lng || position.lon,
|
|
34
|
+
position.lat,
|
|
35
|
+
(position.alt = alt || position.alt),
|
|
36
|
+
Cesium.Ellipsoid.WGS84
|
|
37
|
+
)
|
|
38
|
+
: Cesium.Cartesian3.ZERO;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
/***
|
|
42
|
+
* 坐标数组转换 笛卡尔转84
|
|
43
|
+
*
|
|
44
|
+
* @param {Array} WSG84Arr {lng,lat,alt} 地理坐标数组
|
|
45
|
+
* @param {Number} alt 拔高
|
|
46
|
+
* @return {Array} Cartesian3 三维位置坐标数组
|
|
47
|
+
*/
|
|
48
|
+
transformWGS84ArrayToCartesianArray: function (WSG84Arr, alt) {
|
|
49
|
+
if (this._viewer && WSG84Arr) {
|
|
50
|
+
var $this = this;
|
|
51
|
+
return WSG84Arr
|
|
52
|
+
? WSG84Arr.map(function (item) {
|
|
53
|
+
return $this.transformWGS84ToCartesian(item, alt);
|
|
54
|
+
})
|
|
55
|
+
: [];
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
/***
|
|
59
|
+
* 坐标转换 笛卡尔转84
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} Cartesian3 三维位置坐标
|
|
62
|
+
*
|
|
63
|
+
* @return {Object} {lng,lat,alt} 地理坐标
|
|
64
|
+
*/
|
|
65
|
+
transformCartesianToWGS84: function (cartesian) {
|
|
66
|
+
if (this._viewer && cartesian) {
|
|
67
|
+
var ellipsoid = Cesium.Ellipsoid.WGS84;
|
|
68
|
+
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
|
|
69
|
+
return {
|
|
70
|
+
lng: Cesium.Math.toDegrees(cartographic.longitude),
|
|
71
|
+
lat: Cesium.Math.toDegrees(cartographic.latitude),
|
|
72
|
+
alt: cartographic.height
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
/***
|
|
77
|
+
* 坐标数组转换 笛卡尔转86
|
|
78
|
+
*
|
|
79
|
+
* @param {Array} cartesianArr 三维位置坐标数组
|
|
80
|
+
*
|
|
81
|
+
* @return {Array} {lng,lat,alt} 地理坐标数组
|
|
82
|
+
*/
|
|
83
|
+
transformCartesianArrayToWGS84Array: function (cartesianArr) {
|
|
84
|
+
if (this._viewer) {
|
|
85
|
+
var $this = this;
|
|
86
|
+
return cartesianArr
|
|
87
|
+
? cartesianArr.map(function (item) {
|
|
88
|
+
return $this.transformCartesianToWGS84(item);
|
|
89
|
+
})
|
|
90
|
+
: [];
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* 84坐标转弧度坐标
|
|
95
|
+
* @param {Object} position wgs84
|
|
96
|
+
* @return {Object} Cartographic 弧度坐标
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
transformWGS84ToCartographic: function (position) {
|
|
100
|
+
return position
|
|
101
|
+
? Cesium.Cartographic.fromDegrees(position.lng || position.lon, position.lat, position.alt)
|
|
102
|
+
: Cesium.Cartographic.ZERO;
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* 拾取位置点
|
|
106
|
+
*
|
|
107
|
+
* @param {Object} px 屏幕坐标
|
|
108
|
+
*
|
|
109
|
+
* @return {Object} Cartesian3 三维坐标
|
|
110
|
+
*/
|
|
111
|
+
getCatesian3FromPX: function (px) {
|
|
112
|
+
if (this._viewer && px) {
|
|
113
|
+
var picks = this._viewer.scene.drillPick(px);
|
|
114
|
+
var cartesian = null;
|
|
115
|
+
var isOn3dtiles = false,
|
|
116
|
+
isOnTerrain = false;
|
|
117
|
+
// drillPick
|
|
118
|
+
for (let i in picks) {
|
|
119
|
+
let pick = picks[i];
|
|
120
|
+
|
|
121
|
+
if (
|
|
122
|
+
(pick && pick.primitive instanceof Cesium.Cesium3DTileFeature) ||
|
|
123
|
+
(pick && pick.primitive instanceof Cesium.Cesium3DTileset) ||
|
|
124
|
+
(pick && pick.primitive instanceof Cesium.Model)
|
|
125
|
+
) {
|
|
126
|
+
//模型上拾取
|
|
127
|
+
isOn3dtiles = true;
|
|
128
|
+
}
|
|
129
|
+
// 3dtilset
|
|
130
|
+
if (isOn3dtiles) {
|
|
131
|
+
this._viewer.scene.pick(px); // pick
|
|
132
|
+
cartesian = this._viewer.scene.pickPosition(px);
|
|
133
|
+
if (cartesian) {
|
|
134
|
+
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
|
135
|
+
if (cartographic.height < 0) cartographic.height = 0;
|
|
136
|
+
let lon = Cesium.Math.toDegrees(cartographic.longitude),
|
|
137
|
+
lat = Cesium.Math.toDegrees(cartographic.latitude),
|
|
138
|
+
height = cartographic.height;
|
|
139
|
+
cartesian = this.transformWGS84ToCartesian({ lng: lon, lat: lat, alt: height });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// 地形
|
|
144
|
+
let boolTerrain = this._viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider;
|
|
145
|
+
// Terrain
|
|
146
|
+
if (!isOn3dtiles && !boolTerrain) {
|
|
147
|
+
var ray = this._viewer.scene.camera.getPickRay(px);
|
|
148
|
+
if (!ray) return null;
|
|
149
|
+
cartesian = this._viewer.scene.globe.pick(ray, this._viewer.scene);
|
|
150
|
+
isOnTerrain = true;
|
|
151
|
+
}
|
|
152
|
+
// 地球
|
|
153
|
+
if (!isOn3dtiles && !isOnTerrain && boolTerrain) {
|
|
154
|
+
cartesian = this._viewer.scene.camera.pickEllipsoid(px, this._viewer.scene.globe.ellipsoid);
|
|
155
|
+
}
|
|
156
|
+
if (cartesian) {
|
|
157
|
+
let position = this.transformCartesianToWGS84(cartesian);
|
|
158
|
+
if (position.alt < 0) {
|
|
159
|
+
cartesian = this.transformWGS84ToCartesian(position, 0.1);
|
|
160
|
+
}
|
|
161
|
+
return cartesian;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* 获取84坐标的距离
|
|
168
|
+
* @param {*} positions
|
|
169
|
+
*/
|
|
170
|
+
getPositionDistance: function (positions) {
|
|
171
|
+
let distance = 0;
|
|
172
|
+
for (let i = 0; i < positions.length - 1; i++) {
|
|
173
|
+
let point1cartographic = this.transformWGS84ToCartographic(positions[i]);
|
|
174
|
+
let point2cartographic = this.transformWGS84ToCartographic(positions[i + 1]);
|
|
175
|
+
let geodesic = new Cesium.EllipsoidGeodesic();
|
|
176
|
+
geodesic.setEndPoints(point1cartographic, point2cartographic);
|
|
177
|
+
let s = geodesic.surfaceDistance;
|
|
178
|
+
s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
|
|
179
|
+
distance = distance + s;
|
|
180
|
+
}
|
|
181
|
+
return distance.toFixed(3);
|
|
182
|
+
},
|
|
183
|
+
/**
|
|
184
|
+
* 计算一组坐标组成多边形的面积
|
|
185
|
+
* @param {*} positions
|
|
186
|
+
*/
|
|
187
|
+
getPositionsArea: function (positions) {
|
|
188
|
+
let result = 0;
|
|
189
|
+
if (positions) {
|
|
190
|
+
let h = 0;
|
|
191
|
+
let ellipsoid = Cesium.Ellipsoid.WGS84;
|
|
192
|
+
positions.push(positions[0]);
|
|
193
|
+
for (let i = 1; i < positions.length; i++) {
|
|
194
|
+
let oel = ellipsoid.cartographicToCartesian(this.transformWGS84ToCartographic(positions[i - 1]));
|
|
195
|
+
let el = ellipsoid.cartographicToCartesian(this.transformWGS84ToCartographic(positions[i]));
|
|
196
|
+
h += oel.x * el.y - el.x * oel.y;
|
|
197
|
+
}
|
|
198
|
+
result = Math.abs(h).toFixed(2);
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* 计算一组坐标的中心点
|
|
204
|
+
* @param {*} cartesianPositions
|
|
205
|
+
*/
|
|
206
|
+
computePolygonCenter: function (cartesianPositions) {
|
|
207
|
+
if (!Cesium.defined(cartesianPositions) || cartesianPositions.length === 0) {
|
|
208
|
+
return undefined; // 无效输入
|
|
209
|
+
}
|
|
210
|
+
console.log(cartesianPositions, "cartesianPositions");
|
|
211
|
+
let lonArr = [];
|
|
212
|
+
let latArr = [];
|
|
213
|
+
cartesianPositions.map((item) => {
|
|
214
|
+
lonArr.push(item.x);
|
|
215
|
+
latArr.push(item.y);
|
|
216
|
+
});
|
|
217
|
+
let maxLon = Math.max.apply(Math, lonArr);
|
|
218
|
+
let minLon = Math.min.apply(Math, lonArr);
|
|
219
|
+
let maxLat = Math.max.apply(Math, latArr);
|
|
220
|
+
let minLat = Math.min.apply(Math, latArr);
|
|
221
|
+
let lonCenter = ((maxLon - minLon) / 2) + minLon;
|
|
222
|
+
let latCenter = ((maxLat - minLat) / 2) + minLat;
|
|
223
|
+
console.log(lonCenter, latCenter, "latCenter");
|
|
224
|
+
// 计算所有顶点的平均坐标
|
|
225
|
+
let center = new Cesium.Cartesian3();
|
|
226
|
+
for (const position of cartesianPositions) {
|
|
227
|
+
Cesium.Cartesian3.add(center, position, center);
|
|
228
|
+
}
|
|
229
|
+
Cesium.Cartesian3.divideByScalar(center, cartesianPositions.length, center);
|
|
230
|
+
center.x = lonCenter;
|
|
231
|
+
center.y = latCenter;
|
|
232
|
+
return center;
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
// 剖面 线段插值点
|
|
236
|
+
interPoints(positions) {
|
|
237
|
+
let positionsCartographic = [];
|
|
238
|
+
var terrainSamplePositions = [];
|
|
239
|
+
for (let index = 0; index < positions.length; index++) {
|
|
240
|
+
const element = positions[index];
|
|
241
|
+
var ellipsoid = this._viewer.scene.globe.ellipsoid;
|
|
242
|
+
var cartographic = ellipsoid.cartesianToCartographic(element);
|
|
243
|
+
positionsCartographic.push(cartographic);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
for (let i = 0; i < positionsCartographic.length; i++) {
|
|
247
|
+
const m_Cartographic0 = positionsCartographic[i];
|
|
248
|
+
const m_Cartographic1 = positionsCartographic[i + 1];
|
|
249
|
+
if (m_Cartographic1) {
|
|
250
|
+
|
|
251
|
+
// //采样
|
|
252
|
+
// let length = 10;
|
|
253
|
+
// for (var j = 0; j < length; j++) {
|
|
254
|
+
// terrainSamplePositions.push(
|
|
255
|
+
// new Cesium.Cartographic(
|
|
256
|
+
// Cesium.Math.lerp(m_Cartographic0.longitude, m_Cartographic1.longitude, j / (length - 1)),
|
|
257
|
+
// Cesium.Math.lerp(m_Cartographic0.latitude, m_Cartographic1.latitude, j / (length - 1))
|
|
258
|
+
// )
|
|
259
|
+
// );
|
|
260
|
+
// }
|
|
261
|
+
|
|
262
|
+
// 按照距离等距采样;
|
|
263
|
+
let d = 0;
|
|
264
|
+
var point1cartographic = Cesium.Cartographic.fromCartesian(positions[0]);
|
|
265
|
+
var point2cartographic = Cesium.Cartographic.fromCartesian(positions[1]);
|
|
266
|
+
/**根据经纬度计算出距离**/
|
|
267
|
+
var geodesic = new Cesium.EllipsoidGeodesic();
|
|
268
|
+
geodesic.setEndPoints(point1cartographic, point2cartographic);
|
|
269
|
+
var s = geodesic.surfaceDistance;
|
|
270
|
+
//返回两点之间的距离
|
|
271
|
+
s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
|
|
272
|
+
d = d + s;
|
|
273
|
+
let position1 = Cesium.Cartesian3.fromDegrees(m_Cartographic0.longitude / Math.PI * 180, m_Cartographic0.latitude / Math.PI * 180, m_Cartographic0.height);
|
|
274
|
+
let position2 = Cesium.Cartesian3.fromDegrees(m_Cartographic1.longitude / Math.PI * 180, m_Cartographic1.latitude / Math.PI * 180, m_Cartographic1.height);
|
|
275
|
+
let pot = Cesium.Cartesian3.subtract(position2, position1, new Cesium.Cartesian3());//方向
|
|
276
|
+
var dir = Cesium.Cartesian3.normalize(pot, new Cesium.Cartesian3());//向量归一化
|
|
277
|
+
var ray = new Cesium.Ray(position1, dir);
|
|
278
|
+
let length = Math.floor(d / 5);
|
|
279
|
+
for (let index = 1; index < length; index++) {
|
|
280
|
+
let np = Cesium.Ray.getPoint(ray, index * 5);//计算延长点
|
|
281
|
+
let npCartographic = Cesium.Cartographic.fromCartesian(np);
|
|
282
|
+
terrainSamplePositions.push(npCartographic);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
terrainSamplePositions.pop();
|
|
286
|
+
} else {
|
|
287
|
+
terrainSamplePositions.push(m_Cartographic0);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
let positions_point = [];
|
|
291
|
+
let positions_height = [];
|
|
292
|
+
for (var n = 0; n < terrainSamplePositions.length; n++) {
|
|
293
|
+
//地理坐标(弧度)转经纬度坐标
|
|
294
|
+
var m_cartographic = terrainSamplePositions[n];
|
|
295
|
+
var height = this._viewer.scene.globe.getHeight(m_cartographic);
|
|
296
|
+
var point = Cesium.Cartesian3.fromDegrees(m_cartographic.longitude / Math.PI * 180, m_cartographic.latitude / Math.PI * 180, height);
|
|
297
|
+
positions_point.push(point);
|
|
298
|
+
positions_height.push(height.toFixed(2));
|
|
299
|
+
|
|
300
|
+
}
|
|
301
|
+
return positions_height;
|
|
302
|
+
// console.log('this.positions_point', positions_point);
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 测距
|
|
307
|
+
* @param {*} options
|
|
308
|
+
*/
|
|
309
|
+
drawLineMeasureGraphics: function (options = {}) {
|
|
310
|
+
|
|
311
|
+
const { clampToGround, measure, style } = options;
|
|
312
|
+
if (this._viewer && options) {
|
|
313
|
+
var positions = [],
|
|
314
|
+
_lineEntity = new Cesium.Entity(),
|
|
315
|
+
$this = this,
|
|
316
|
+
lineObj,
|
|
317
|
+
distance = 0,
|
|
318
|
+
labelEntityOne,
|
|
319
|
+
_handlers = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
320
|
+
// left
|
|
321
|
+
_handlers.setInputAction(function (movement) {
|
|
322
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
323
|
+
if (cartesian && cartesian.x) {
|
|
324
|
+
if (positions.length == 0) {
|
|
325
|
+
positions.push(cartesian.clone());
|
|
326
|
+
}
|
|
327
|
+
// 添加量测信息点
|
|
328
|
+
if (style?.point) {
|
|
329
|
+
_addInfoPoint(cartesian);
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
positions.push(cartesian);
|
|
333
|
+
}
|
|
334
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
335
|
+
|
|
336
|
+
_handlers.setInputAction(function (movement) {
|
|
337
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
338
|
+
|
|
339
|
+
//鼠标提示信息
|
|
340
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
341
|
+
var _labelEntityOne = new Cesium.Entity();
|
|
342
|
+
_labelEntityOne.position = cartesian;
|
|
343
|
+
_labelEntityOne.label = {
|
|
344
|
+
text: positions.length > 0 ? '右击结束绘制' : '单击打开始绘制',
|
|
345
|
+
show: true,
|
|
346
|
+
showBackground: true,
|
|
347
|
+
font: '14px monospace',
|
|
348
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
349
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
350
|
+
pixelOffset: new Cesium.Cartesian2(-20, -80), //left top
|
|
351
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
352
|
+
};
|
|
353
|
+
labelEntityOne = $this._drawLayer.entities.add(_labelEntityOne);
|
|
354
|
+
|
|
355
|
+
if (positions.length >= 2) {
|
|
356
|
+
if (cartesian && cartesian.x) {
|
|
357
|
+
positions.pop();
|
|
358
|
+
positions.push(cartesian);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
362
|
+
// right
|
|
363
|
+
_handlers.setInputAction(function (movement) {
|
|
364
|
+
_handlers.destroy();
|
|
365
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
366
|
+
_handlers = null;
|
|
367
|
+
|
|
368
|
+
let cartesian = $this.getCatesian3FromPX(movement.position);
|
|
369
|
+
_addInfoPoint(cartesian);
|
|
370
|
+
|
|
371
|
+
if (typeof options.callback === 'function') {
|
|
372
|
+
options.callback({
|
|
373
|
+
points: $this.transformCartesianArrayToWGS84Array(positions),
|
|
374
|
+
entity: lineObj,
|
|
375
|
+
measure: Number(distance),
|
|
376
|
+
poumian: options.showPoumian ? $this.interPoints(positions) : false,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// options.callback($this.transformCartesianArrayToWGS84Array(positions), lineObj)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
383
|
+
|
|
384
|
+
_lineEntity.polyline = {
|
|
385
|
+
width: style?.line?.width || 1,
|
|
386
|
+
material: style?.line?.material || Cesium.Color.BLUE.withAlpha(0.8),
|
|
387
|
+
clampToGround: clampToGround || false
|
|
388
|
+
};
|
|
389
|
+
_lineEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
|
390
|
+
return positions;
|
|
391
|
+
}, false);
|
|
392
|
+
|
|
393
|
+
lineObj = this._drawLayer.entities.add(_lineEntity);
|
|
394
|
+
|
|
395
|
+
//添加坐标点
|
|
396
|
+
function _addInfoPoint(position) {
|
|
397
|
+
var _labelEntity = new Cesium.Entity();
|
|
398
|
+
_labelEntity.position = position;
|
|
399
|
+
_labelEntity.point = {
|
|
400
|
+
pixelSize: style?.point?.pixelSize || 10,
|
|
401
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
402
|
+
outlineWidth: style?.point?.outlineWidth || 0,
|
|
403
|
+
color: style?.point?.color || Cesium.Color.WHITE,
|
|
404
|
+
show: JSON.stringify(style?.point?.show) == 'false' ? false : true,
|
|
405
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
406
|
+
|
|
407
|
+
};
|
|
408
|
+
if (measure) {
|
|
409
|
+
distance = $this.getPositionDistance($this.transformCartesianArrayToWGS84Array(positions));
|
|
410
|
+
|
|
411
|
+
_labelEntity.label = {
|
|
412
|
+
text:
|
|
413
|
+
(distance / 1000).toFixed(4) +
|
|
414
|
+
'公里',
|
|
415
|
+
show: true,
|
|
416
|
+
showBackground: true,
|
|
417
|
+
font: '14px monospace',
|
|
418
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
419
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
420
|
+
pixelOffset: new Cesium.Cartesian2(-20, -80), //left top
|
|
421
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* 测面积
|
|
431
|
+
* @param {*} options
|
|
432
|
+
*/
|
|
433
|
+
drawAreaMeasureGraphics: function (options = {}) {
|
|
434
|
+
const { clampToGround, measure, style } = options;
|
|
435
|
+
|
|
436
|
+
if (this._viewer && options) {
|
|
437
|
+
var positions = [],
|
|
438
|
+
polygon = new Cesium.PolygonHierarchy(),
|
|
439
|
+
_polygonEntity = new Cesium.Entity(),
|
|
440
|
+
$this = this,
|
|
441
|
+
polyObj = null,
|
|
442
|
+
area = 0,
|
|
443
|
+
_label = '',
|
|
444
|
+
labelEntityOne,
|
|
445
|
+
|
|
446
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
447
|
+
// left
|
|
448
|
+
_handler.setInputAction(function (movement) {
|
|
449
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
450
|
+
|
|
451
|
+
if (cartesian && cartesian.x) {
|
|
452
|
+
if (positions.length == 0) {
|
|
453
|
+
polygon.positions.push(cartesian.clone());
|
|
454
|
+
positions.push(cartesian.clone());
|
|
455
|
+
}
|
|
456
|
+
positions.push(cartesian.clone());
|
|
457
|
+
polygon.positions.push(cartesian.clone());
|
|
458
|
+
if (!polyObj) create();
|
|
459
|
+
}
|
|
460
|
+
if (style?.point) {
|
|
461
|
+
addInfoPoint(cartesian, positions.length - 2);
|
|
462
|
+
}
|
|
463
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
464
|
+
// mouse
|
|
465
|
+
_handler.setInputAction(function (movement) {
|
|
466
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
467
|
+
// var cartesian = $this._viewer.scene.camera.pickEllipsoid(movement.endPosition, $this._viewer.scene.globe.ellipsoid);
|
|
468
|
+
|
|
469
|
+
//鼠标提示信息
|
|
470
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
471
|
+
var _labelEntityOne = new Cesium.Entity();
|
|
472
|
+
_labelEntityOne.position = cartesian;
|
|
473
|
+
_labelEntityOne.label = {
|
|
474
|
+
text: positions.length > 0 ? '右击结束绘制' : '单击打开始绘制',
|
|
475
|
+
show: true,
|
|
476
|
+
showBackground: true,
|
|
477
|
+
font: '14px monospace',
|
|
478
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
479
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
480
|
+
pixelOffset: new Cesium.Cartesian2(-20, -80), //left top
|
|
481
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
482
|
+
};
|
|
483
|
+
labelEntityOne = $this._drawLayer.entities.add(_labelEntityOne);
|
|
484
|
+
if (positions.length >= 2) {
|
|
485
|
+
if (cartesian && cartesian.x) {
|
|
486
|
+
positions.pop();
|
|
487
|
+
positions.push(cartesian);
|
|
488
|
+
polygon.positions.pop();
|
|
489
|
+
polygon.positions.push(cartesian);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
493
|
+
|
|
494
|
+
// right
|
|
495
|
+
_handler.setInputAction(function (movement) {
|
|
496
|
+
// var cartesian = $this.getCatesian3FromPX(movement.endPosition)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
500
|
+
|
|
501
|
+
_handler.destroy();
|
|
502
|
+
|
|
503
|
+
positions.push(positions[0]);
|
|
504
|
+
let lastPoint = positions[positions.length - 2];
|
|
505
|
+
if (style?.centerPoint && measure) {
|
|
506
|
+
let center = $this.computePolygonCenter(positions);
|
|
507
|
+
|
|
508
|
+
// 添加信息点
|
|
509
|
+
if (center) _addInfoPoint(center);
|
|
510
|
+
if (style?.point) {
|
|
511
|
+
addInfoPoint(lastPoint);
|
|
512
|
+
|
|
513
|
+
}
|
|
514
|
+
} else {
|
|
515
|
+
addInfoPoint(lastPoint, positions.length - 2);
|
|
516
|
+
}
|
|
517
|
+
// createMidHandles()
|
|
518
|
+
|
|
519
|
+
if (typeof options.callback === 'function') {
|
|
520
|
+
options.callback({
|
|
521
|
+
points: $this.transformCartesianArrayToWGS84Array(positions),
|
|
522
|
+
entity: polyObj,
|
|
523
|
+
measure: Number(area)
|
|
524
|
+
});
|
|
525
|
+
// options.callback($this.transformCartesianArrayToWGS84Array(positions), polyObj)
|
|
526
|
+
}
|
|
527
|
+
// 进入编辑模式
|
|
528
|
+
startEditMode();
|
|
529
|
+
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
530
|
+
|
|
531
|
+
function create() {
|
|
532
|
+
if (style?.line) {
|
|
533
|
+
_polygonEntity.polyline = {
|
|
534
|
+
width: style?.line?.width || 3,
|
|
535
|
+
material: style?.line?.material || Cesium.Color.BLUE.withAlpha(0.8),
|
|
536
|
+
clampToGround: clampToGround || false
|
|
537
|
+
};
|
|
538
|
+
_polygonEntity.polyline.positions = new Cesium.CallbackProperty(() => positions, false);
|
|
539
|
+
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
_polygonEntity.polygon = {
|
|
545
|
+
hierarchy: new Cesium.CallbackProperty(() => polygon, false),
|
|
546
|
+
material: style?.polygon?.material || Cesium.Color.WHITE.withAlpha(0.1),
|
|
547
|
+
clampToGround: options.clampToGround || false
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
polyObj = $this._drawLayer.entities.add(_polygonEntity);
|
|
551
|
+
}
|
|
552
|
+
//添加坐标点
|
|
553
|
+
function _addInfoPoint(position) {
|
|
554
|
+
var _labelEntity = new Cesium.Entity();
|
|
555
|
+
_labelEntity.position = position;
|
|
556
|
+
_labelEntity.point = {
|
|
557
|
+
pixelSize: style?.centerPoint?.pixelSize || style?.point?.pixelSize || 10,
|
|
558
|
+
outlineColor: style?.centerPoint?.outlineColor || style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
559
|
+
outlineWidth: style?.centerPoint?.outlineWidth || style?.point?.outlineWidth || 0,
|
|
560
|
+
color: style?.centerPoint?.color || style?.point?.color || Cesium.Color.WHITE
|
|
561
|
+
};
|
|
562
|
+
if (measure) {
|
|
563
|
+
area = $this.getPositionsArea($this.transformCartesianArrayToWGS84Array(positions));
|
|
564
|
+
// 获取原始位置
|
|
565
|
+
var originalPosition = _labelEntity.position.getValue(Cesium.JulianDate.now());
|
|
566
|
+
// 向上偏移 100 米
|
|
567
|
+
var newHeight = 10; // 向上偏移 100 米
|
|
568
|
+
var newPosition = new Cesium.Cartesian3(originalPosition.x, originalPosition.y, originalPosition.z + newHeight);
|
|
569
|
+
// 更新 entity 的位置属性
|
|
570
|
+
_labelEntity.position.setValue(newPosition);
|
|
571
|
+
_labelEntity.label = {
|
|
572
|
+
text:
|
|
573
|
+
(area / 1000000.0).toFixed(4) +
|
|
574
|
+
'平方公里',
|
|
575
|
+
|
|
576
|
+
show: true,
|
|
577
|
+
showBackground: true,
|
|
578
|
+
font: '14px monospace',
|
|
579
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
580
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
581
|
+
pixelOffset: new Cesium.Cartesian2(-55, -10), //left top
|
|
582
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
587
|
+
}
|
|
588
|
+
function addInfoPoint(position, index) {
|
|
589
|
+
var _labelEntity = new Cesium.Entity({
|
|
590
|
+
position,
|
|
591
|
+
point: {
|
|
592
|
+
pixelSize: style.pixelSize || 4,
|
|
593
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
594
|
+
outlineWidth: style?.point?.outlineWidth || 0,
|
|
595
|
+
color: style?.point?.color || Cesium.Color.WHITE,
|
|
596
|
+
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
597
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
598
|
+
},
|
|
599
|
+
properties: {
|
|
600
|
+
type: 'vertex',
|
|
601
|
+
index
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
605
|
+
}
|
|
606
|
+
// 创建边中心点
|
|
607
|
+
function createMidHandles() {
|
|
608
|
+
const list = $this._drawLayer.entities.values.slice();
|
|
609
|
+
list.forEach(ent => {
|
|
610
|
+
if (ent.properties) {
|
|
611
|
+
let { type } = ent.properties.getValue();
|
|
612
|
+
if (type == 'midpoint') {
|
|
613
|
+
console.log(ent, 'ent中心点');
|
|
614
|
+
$this._drawLayer.entities.remove(ent);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
for (let i = 0; i < positions.length - 1; i++) {
|
|
619
|
+
$this._drawLayer.entities.add({
|
|
620
|
+
position: new Cesium.CallbackProperty(() => {
|
|
621
|
+
const a = positions[i];
|
|
622
|
+
const b = positions[i + 1];
|
|
623
|
+
return Cesium.Cartesian3.lerp(a, b, 0.5, new Cesium.Cartesian3());
|
|
624
|
+
}, false),
|
|
625
|
+
point: {
|
|
626
|
+
pixelSize: 2,
|
|
627
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
628
|
+
outlineWidth: style?.point?.outlineWidth || 0,
|
|
629
|
+
color: style?.point?.color || Cesium.Color.WHITE,
|
|
630
|
+
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
631
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
632
|
+
},
|
|
633
|
+
properties: {
|
|
634
|
+
type: 'midpoint',
|
|
635
|
+
index: i
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function startEditMode() {
|
|
641
|
+
let dragging = false;
|
|
642
|
+
let dragEntity = null;
|
|
643
|
+
let dragIdx = -1;
|
|
644
|
+
let viewer = $this._viewer;
|
|
645
|
+
const editHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
|
646
|
+
editHandler.setInputAction((e) => {
|
|
647
|
+
const picked = viewer.scene.pick(e.position);
|
|
648
|
+
if (!picked || !picked.id || !picked.id.properties) return;
|
|
649
|
+
let { type, index } = picked.id.properties.getValue();
|
|
650
|
+
if (type == 'vertex') {
|
|
651
|
+
dragging = true;
|
|
652
|
+
dragEntity = picked.id;
|
|
653
|
+
dragIdx = index;
|
|
654
|
+
viewer.scene.canvas.style.cursor = 'grabbing';
|
|
655
|
+
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
|
656
|
+
}
|
|
657
|
+
// if (type == 'midpoint') {
|
|
658
|
+
// let midPos = dragEntity.position.getValue(Cesium.JulianDate.now())
|
|
659
|
+
// positions.splice(index + 1, 0, midPos.clone())
|
|
660
|
+
// addInfoPoint(midPos, index + 1)
|
|
661
|
+
// createMidHandles()
|
|
662
|
+
// }
|
|
663
|
+
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
|
664
|
+
// 移动:拖拽更新
|
|
665
|
+
editHandler.setInputAction(e => {
|
|
666
|
+
if (!dragging) return;
|
|
667
|
+
var cartesian = $this.getCatesian3FromPX(e.endPosition);
|
|
668
|
+
let { type } = dragEntity.properties.getValue();
|
|
669
|
+
dragEntity.position.setValue(cartesian);
|
|
670
|
+
positions[dragIdx] = cartesian.clone();
|
|
671
|
+
polygon.positions[dragIdx] = cartesian.clone();
|
|
672
|
+
// 保持闭合
|
|
673
|
+
if (positions.length > 1) {
|
|
674
|
+
positions[positions.length - 1] = positions[0].clone();
|
|
675
|
+
}
|
|
676
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
677
|
+
editHandler.setInputAction(() => {
|
|
678
|
+
if (!dragging) return;
|
|
679
|
+
dragging = false;
|
|
680
|
+
dragIdx = -1;
|
|
681
|
+
dragEntity = null;
|
|
682
|
+
viewer.scene.canvas.style.cursor = 'default';
|
|
683
|
+
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
|
684
|
+
console.log(options,'options')
|
|
685
|
+
if (typeof options.callback === 'function') {
|
|
686
|
+
options.callback({
|
|
687
|
+
points: $this.transformCartesianArrayToWGS84Array(positions),
|
|
688
|
+
measure: Number(area)
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
/**
|
|
696
|
+
* 画三角量测
|
|
697
|
+
* @param {*} options
|
|
698
|
+
*/
|
|
699
|
+
drawTrianglesMeasureGraphics: function (options = {}) {
|
|
700
|
+
const { style } = options;
|
|
701
|
+
let lineStyle = style.line || {
|
|
702
|
+
width: 3,
|
|
703
|
+
material: Cesium.Color.BLUE.withAlpha(0.5)
|
|
704
|
+
};
|
|
705
|
+
if (this._viewer && options) {
|
|
706
|
+
var _trianglesEntity = new Cesium.Entity(),
|
|
707
|
+
_tempLineEntity = new Cesium.Entity(),
|
|
708
|
+
_tempLineEntity2 = new Cesium.Entity(),
|
|
709
|
+
_positions = [],
|
|
710
|
+
_tempPoints = [],
|
|
711
|
+
_tempPoints2 = [],
|
|
712
|
+
$this = this,
|
|
713
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
714
|
+
// 高度
|
|
715
|
+
function _getHeading(startPosition, endPosition) {
|
|
716
|
+
if (!startPosition && !endPosition) return 0;
|
|
717
|
+
if (Cesium.Cartesian3.equals(startPosition, endPosition)) return 0;
|
|
718
|
+
let cartographic = Cesium.Cartographic.fromCartesian(startPosition);
|
|
719
|
+
let cartographic2 = Cesium.Cartographic.fromCartesian(endPosition);
|
|
720
|
+
return (cartographic2.height - cartographic.height).toFixed(2);
|
|
721
|
+
}
|
|
722
|
+
// 偏移点
|
|
723
|
+
function _computesHorizontalLine(positions) {
|
|
724
|
+
let cartographic = Cesium.Cartographic.fromCartesian(positions[0]);
|
|
725
|
+
let cartographic2 = Cesium.Cartographic.fromCartesian(positions[1]);
|
|
726
|
+
return Cesium.Cartesian3.fromDegrees(
|
|
727
|
+
Cesium.Math.toDegrees(cartographic.longitude),
|
|
728
|
+
Cesium.Math.toDegrees(cartographic.latitude),
|
|
729
|
+
cartographic2.height
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
// left
|
|
733
|
+
_handler.setInputAction(function (movement) {
|
|
734
|
+
var position = $this.getCatesian3FromPX(movement.position);
|
|
735
|
+
if (!position && !position.z) return false;
|
|
736
|
+
if (_positions.length == 0) {
|
|
737
|
+
_positions.push(position.clone());
|
|
738
|
+
_positions.push(position.clone());
|
|
739
|
+
_tempPoints.push(position.clone());
|
|
740
|
+
_tempPoints.push(position.clone());
|
|
741
|
+
} else {
|
|
742
|
+
_handler.destroy();
|
|
743
|
+
if (typeof options.callback === 'function') {
|
|
744
|
+
options.callback({ e: _trianglesEntity, e2: _tempLineEntity, e3: _tempLineEntity2 });
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
748
|
+
// mouse
|
|
749
|
+
_handler.setInputAction(function (movement) {
|
|
750
|
+
var position = $this.getCatesian3FromPX(movement.endPosition);
|
|
751
|
+
if (position && _positions.length > 0) {
|
|
752
|
+
//直线
|
|
753
|
+
_positions.pop();
|
|
754
|
+
_positions.push(position.clone());
|
|
755
|
+
let horizontalPosition = _computesHorizontalLine(_positions);
|
|
756
|
+
//高度
|
|
757
|
+
_tempPoints.pop();
|
|
758
|
+
_tempPoints.push(horizontalPosition.clone());
|
|
759
|
+
//水平线
|
|
760
|
+
_tempPoints2.pop(), _tempPoints2.pop();
|
|
761
|
+
_tempPoints2.push(position.clone());
|
|
762
|
+
_tempPoints2.push(horizontalPosition.clone());
|
|
763
|
+
}
|
|
764
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
765
|
+
|
|
766
|
+
// create entity
|
|
767
|
+
|
|
768
|
+
//直线
|
|
769
|
+
_trianglesEntity.polyline = {
|
|
770
|
+
positions: new Cesium.CallbackProperty(function () {
|
|
771
|
+
return _positions;
|
|
772
|
+
}, false),
|
|
773
|
+
...lineStyle
|
|
774
|
+
};
|
|
775
|
+
_trianglesEntity.position = new Cesium.CallbackProperty(function () {
|
|
776
|
+
return _positions[0];
|
|
777
|
+
}, false);
|
|
778
|
+
_trianglesEntity.point = {
|
|
779
|
+
pixelSize: style?.point?.pixelSize || 5,
|
|
780
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
781
|
+
outlineWidth: style?.point?.outlineWidth || 5
|
|
782
|
+
};
|
|
783
|
+
_trianglesEntity.label = {
|
|
784
|
+
text: new Cesium.CallbackProperty(function () {
|
|
785
|
+
return '直线:' + $this.getPositionDistance($this.transformCartesianArrayToWGS84Array(_positions)) + '米';
|
|
786
|
+
}, false),
|
|
787
|
+
show: true,
|
|
788
|
+
showBackground: true,
|
|
789
|
+
font: '14px monospace',
|
|
790
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
791
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
792
|
+
pixelOffset: new Cesium.Cartesian2(50, -100) //left top
|
|
793
|
+
};
|
|
794
|
+
//高度
|
|
795
|
+
_tempLineEntity.polyline = {
|
|
796
|
+
positions: new Cesium.CallbackProperty(function () {
|
|
797
|
+
return _tempPoints;
|
|
798
|
+
}, false),
|
|
799
|
+
...lineStyle
|
|
800
|
+
};
|
|
801
|
+
_tempLineEntity.position = new Cesium.CallbackProperty(function () {
|
|
802
|
+
return _tempPoints2[1];
|
|
803
|
+
}, false);
|
|
804
|
+
_tempLineEntity.point = {
|
|
805
|
+
pixelSize: style?.point?.pixelSize || 5,
|
|
806
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
807
|
+
outlineWidth: style?.point?.outlineWidth || 5
|
|
808
|
+
};
|
|
809
|
+
_tempLineEntity.label = {
|
|
810
|
+
text: new Cesium.CallbackProperty(function () {
|
|
811
|
+
return '高度:' + _getHeading(_tempPoints[0], _tempPoints[1]) + '米';
|
|
812
|
+
}, false),
|
|
813
|
+
show: true,
|
|
814
|
+
showBackground: true,
|
|
815
|
+
font: '14px monospace',
|
|
816
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
817
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
818
|
+
pixelOffset: new Cesium.Cartesian2(-20, 100) //left top
|
|
819
|
+
};
|
|
820
|
+
//水平
|
|
821
|
+
_tempLineEntity2.polyline = {
|
|
822
|
+
positions: new Cesium.CallbackProperty(function () {
|
|
823
|
+
return _tempPoints2;
|
|
824
|
+
}, false),
|
|
825
|
+
...lineStyle
|
|
826
|
+
};
|
|
827
|
+
_tempLineEntity2.position = new Cesium.CallbackProperty(function () {
|
|
828
|
+
return _positions[1];
|
|
829
|
+
}, false);
|
|
830
|
+
|
|
831
|
+
_tempLineEntity2.point = {
|
|
832
|
+
pixelSize: style?.point?.pixelSize || 5,
|
|
833
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
834
|
+
outlineWidth: style?.point?.outlineWidth || 5
|
|
835
|
+
};
|
|
836
|
+
_tempLineEntity2.label = {
|
|
837
|
+
text: new Cesium.CallbackProperty(function () {
|
|
838
|
+
return (
|
|
839
|
+
'水平距离:' + $this.getPositionDistance($this.transformCartesianArrayToWGS84Array(_tempPoints2)) + '米'
|
|
840
|
+
);
|
|
841
|
+
}, false),
|
|
842
|
+
show: true,
|
|
843
|
+
showBackground: true,
|
|
844
|
+
font: '14px monospace',
|
|
845
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
846
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
847
|
+
pixelOffset: new Cesium.Cartesian2(-150, -20) //left top
|
|
848
|
+
};
|
|
849
|
+
this._drawLayer.entities.add(_tempLineEntity2);
|
|
850
|
+
this._drawLayer.entities.add(_tempLineEntity);
|
|
851
|
+
this._drawLayer.entities.add(_trianglesEntity);
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
/**
|
|
855
|
+
* 传入两个点位返回矩形4个点的坐标
|
|
856
|
+
*/
|
|
857
|
+
computeRectanglePos: function (lTop, rBottom) {
|
|
858
|
+
let positions = [];
|
|
859
|
+
var leftTop = this.transformCartesianToWGS84(lTop);
|
|
860
|
+
var rightBottom = this.transformCartesianToWGS84(rBottom);
|
|
861
|
+
var rightTop = {
|
|
862
|
+
"lng": rightBottom.lng,
|
|
863
|
+
"lat": leftTop.lat
|
|
864
|
+
};
|
|
865
|
+
let rightTop2 = Cesium.Cartesian3.fromDegrees(rightTop.lng, rightTop.lat);
|
|
866
|
+
// 计算左下角的坐标
|
|
867
|
+
var leftBottom = {
|
|
868
|
+
"lng": leftTop.lng,
|
|
869
|
+
"lat": rightBottom.lat
|
|
870
|
+
};
|
|
871
|
+
let leftBottom2 = Cesium.Cartesian3.fromDegrees(leftBottom.lng, leftBottom.lat);
|
|
872
|
+
positions.push(rightTop2.clone(), rBottom.clone(), leftBottom2.clone(), lTop.clone());
|
|
873
|
+
return positions;
|
|
874
|
+
},
|
|
875
|
+
/**
|
|
876
|
+
* 绘制矩形
|
|
877
|
+
*/
|
|
878
|
+
drawRectangleMeasureGraphics: function (options = {}) {
|
|
879
|
+
const { clampToGround, measure, style } = options;
|
|
880
|
+
|
|
881
|
+
if (this._viewer && options) {
|
|
882
|
+
var positions = [],
|
|
883
|
+
polyObj = null,
|
|
884
|
+
rectangle = new Cesium.PolygonHierarchy(),
|
|
885
|
+
_polygonEntity = new Cesium.Entity(),
|
|
886
|
+
$this = this,
|
|
887
|
+
labelEntityOne,
|
|
888
|
+
area = 0,
|
|
889
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
890
|
+
// left
|
|
891
|
+
_handler.setInputAction(function (movement) {
|
|
892
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
893
|
+
addInfoPoint(cartesian);
|
|
894
|
+
|
|
895
|
+
if (cartesian && cartesian.x) {
|
|
896
|
+
if (positions.length == 0) {
|
|
897
|
+
rectangle.positions.push(cartesian.clone());
|
|
898
|
+
positions.push(cartesian.clone());
|
|
899
|
+
|
|
900
|
+
} else {
|
|
901
|
+
let otherPos = $this.computeRectanglePos(positions[0], cartesian);
|
|
902
|
+
console.log(otherPos, "");
|
|
903
|
+
positions.push(...otherPos);
|
|
904
|
+
if (positions.length > 1) {
|
|
905
|
+
positions.splice(-4);
|
|
906
|
+
rectangle.positions.splice(-4);
|
|
907
|
+
}
|
|
908
|
+
positions.map((pos) => {
|
|
909
|
+
rectangle.positions.push(pos);
|
|
910
|
+
});
|
|
911
|
+
//清除鼠标事件
|
|
912
|
+
if (_handler) _handler.destroy();
|
|
913
|
+
//清除提示
|
|
914
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
915
|
+
if (typeof options.callback === 'function') {
|
|
916
|
+
options.callback({
|
|
917
|
+
points: $this.transformCartesianArrayToWGS84Array(positions),
|
|
918
|
+
entity: polyObj,
|
|
919
|
+
measure: Number(area)
|
|
920
|
+
});
|
|
921
|
+
// options.callback($this.transformCartesianArrayToWGS84Array(positions), polyObj)
|
|
922
|
+
}
|
|
923
|
+
//如果measure==true就计算面积
|
|
924
|
+
if (measure == true) {
|
|
925
|
+
if (style.centerPoint) {
|
|
926
|
+
const center = $this.computePolygonCenter(positions);
|
|
927
|
+
if (center) _addInfoPoint(center);
|
|
928
|
+
} else {
|
|
929
|
+
_addInfoPoint(cartesian);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
if (!polyObj) create();
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
943
|
+
_handler.setInputAction(function (movement) {
|
|
944
|
+
|
|
945
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
946
|
+
//鼠标提示信息
|
|
947
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
948
|
+
var _labelEntityOne = new Cesium.Entity();
|
|
949
|
+
_labelEntityOne.position = cartesian;
|
|
950
|
+
_labelEntityOne.label = {
|
|
951
|
+
text: '点击两个点后自动完成绘制',
|
|
952
|
+
show: true,
|
|
953
|
+
showBackground: true,
|
|
954
|
+
font: '14px monospace',
|
|
955
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
956
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
957
|
+
pixelOffset: new Cesium.Cartesian2(-20, -80) //left top
|
|
958
|
+
};
|
|
959
|
+
labelEntityOne = $this._drawLayer.entities.add(_labelEntityOne);
|
|
960
|
+
if (positions.length > 1) {
|
|
961
|
+
positions.splice(-4);
|
|
962
|
+
rectangle.positions.splice(-4);
|
|
963
|
+
}
|
|
964
|
+
let otherPos = $this.computeRectanglePos(positions[0], cartesian);
|
|
965
|
+
positions.push(...otherPos);
|
|
966
|
+
positions.map((pos) => {
|
|
967
|
+
rectangle.positions.push(pos);
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
972
|
+
|
|
973
|
+
function create() {
|
|
974
|
+
|
|
975
|
+
_polygonEntity.polyline = {
|
|
976
|
+
width: style?.line?.width || 3,
|
|
977
|
+
material: style?.line?.material || Cesium.Color.BLUE.withAlpha(0.8),
|
|
978
|
+
clampToGround: clampToGround || false,
|
|
979
|
+
show: JSON.stringify(style?.line?.show) == 'false' ? false : true
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
_polygonEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
|
983
|
+
return positions;
|
|
984
|
+
}, false);
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
_polygonEntity.polygon = {
|
|
989
|
+
hierarchy: new Cesium.CallbackProperty(function () {
|
|
990
|
+
return rectangle;
|
|
991
|
+
}, false),
|
|
992
|
+
|
|
993
|
+
material: style?.polygon?.material || Cesium.Color.WHITE.withAlpha(0.1),
|
|
994
|
+
clampToGround: clampToGround || false
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
polyObj = $this._drawLayer.entities.add(_polygonEntity);
|
|
998
|
+
}
|
|
999
|
+
//鼠标打点
|
|
1000
|
+
function addInfoPoint(position) {
|
|
1001
|
+
var _labelEntity = new Cesium.Entity();
|
|
1002
|
+
_labelEntity.position = position;
|
|
1003
|
+
_labelEntity.point = {
|
|
1004
|
+
pixelSize: style?.point?.pixelSize || 10,
|
|
1005
|
+
outlineColor: style?.point?.outlineColor || Cesium.Color.BLUE,
|
|
1006
|
+
outlineWidth: style?.point?.outlineWidth || 0,
|
|
1007
|
+
color: style?.point?.cololr || Cesium.Color.WHEAT,
|
|
1008
|
+
show: JSON.stringify(style?.point?.show) == 'false' ? false : true
|
|
1009
|
+
|
|
1010
|
+
};
|
|
1011
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
1012
|
+
}
|
|
1013
|
+
//添加坐标点
|
|
1014
|
+
function _addInfoPoint(position) {
|
|
1015
|
+
var _labelEntity = new Cesium.Entity();
|
|
1016
|
+
_labelEntity.position = position;
|
|
1017
|
+
_labelEntity.point = {
|
|
1018
|
+
pixelSize: style?.centerPoint?.pixelSize || 10,
|
|
1019
|
+
outlineColor: style?.centerPoint?.outlineColor || Cesium.Color.BLUE,
|
|
1020
|
+
outlineWidth: style?.centerPoint?.outlineWidth || 0,
|
|
1021
|
+
color: style?.centerPoint?.cololr || Cesium.Color.WHEAT,
|
|
1022
|
+
show: JSON.stringify(style?.centerPoint?.show) == 'false' ? false : true
|
|
1023
|
+
};
|
|
1024
|
+
if (measure) {
|
|
1025
|
+
area = $this.getPositionsArea($this.transformCartesianArrayToWGS84Array(positions));
|
|
1026
|
+
_labelEntity.label = {
|
|
1027
|
+
text:
|
|
1028
|
+
(area / 1000000.0).toFixed(4) +
|
|
1029
|
+
'平方公里',
|
|
1030
|
+
show: true,
|
|
1031
|
+
showBackground: true,
|
|
1032
|
+
font: '14px monospace',
|
|
1033
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
1034
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
1035
|
+
pixelOffset: new Cesium.Cartesian2(-55, -10) //left top
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
/**
|
|
1044
|
+
* 绘制圆形
|
|
1045
|
+
*/
|
|
1046
|
+
drawCircleMeasureGraphics: function (options = {}) {
|
|
1047
|
+
const { clampToGround, measure, style } = options;
|
|
1048
|
+
|
|
1049
|
+
if (this._viewer && options) {
|
|
1050
|
+
var positions = [],
|
|
1051
|
+
polyObj = null,
|
|
1052
|
+
_labelEntity,
|
|
1053
|
+
_polygonEntity = new Cesium.Entity(),
|
|
1054
|
+
center,
|
|
1055
|
+
radius = 500,
|
|
1056
|
+
$this = this,
|
|
1057
|
+
labelEntityOne,
|
|
1058
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
1059
|
+
if (!polyObj) create();
|
|
1060
|
+
_handler.setInputAction(function (movement) {
|
|
1061
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
1062
|
+
|
|
1063
|
+
if (cartesian && cartesian.x) {
|
|
1064
|
+
if (positions.length == 0) {
|
|
1065
|
+
_labelEntity = addInfoPoint(cartesian);
|
|
1066
|
+
_polygonEntity.position = new Cesium.CallbackProperty(function () {
|
|
1067
|
+
// 在这个回调函数中动态计算圆形的位置(中心点)
|
|
1068
|
+
return cartesian;
|
|
1069
|
+
}, false);
|
|
1070
|
+
if (!center) center = cartesian;
|
|
1071
|
+
|
|
1072
|
+
positions.push(cartesian);
|
|
1073
|
+
} else {
|
|
1074
|
+
radius = Number($this.getPositionDistance($this.transformCartesianArrayToWGS84Array([center, cartesian])));
|
|
1075
|
+
//清除鼠标事件
|
|
1076
|
+
if (_handler) _handler.destroy();
|
|
1077
|
+
//清除提示
|
|
1078
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
1079
|
+
if (typeof options.callback === 'function') {
|
|
1080
|
+
options.callback(
|
|
1081
|
+
{
|
|
1082
|
+
center: $this.transformCartesianArrayToWGS84Array([center]),
|
|
1083
|
+
radius: radius
|
|
1084
|
+
}
|
|
1085
|
+
, polyObj);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
1094
|
+
|
|
1095
|
+
_handler.setInputAction(function (movement) {
|
|
1096
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
1097
|
+
|
|
1098
|
+
//鼠标提示信息
|
|
1099
|
+
if (labelEntityOne) $this._drawLayer.entities.remove(labelEntityOne);
|
|
1100
|
+
|
|
1101
|
+
radius = Number($this.getPositionDistance($this.transformCartesianArrayToWGS84Array([center, cartesian])));
|
|
1102
|
+
// 计算圆形的面积
|
|
1103
|
+
|
|
1104
|
+
if (measure) {
|
|
1105
|
+
if (!_labelEntity) {
|
|
1106
|
+
_labelEntity = addInfoPoint(center);
|
|
1107
|
+
}
|
|
1108
|
+
var circleArea = Math.PI * Math.pow(radius, 2);
|
|
1109
|
+
_labelEntity.label = {
|
|
1110
|
+
text:
|
|
1111
|
+
(circleArea / 1000000.0).toFixed(4) +
|
|
1112
|
+
'平方公里',
|
|
1113
|
+
show: true,
|
|
1114
|
+
showBackground: true,
|
|
1115
|
+
font: '14px monospace',
|
|
1116
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
1117
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
1118
|
+
pixelOffset: new Cesium.Cartesian2(-55, -10), //left top
|
|
1119
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
var _labelEntityOne = new Cesium.Entity();
|
|
1123
|
+
_labelEntityOne.position = cartesian;
|
|
1124
|
+
_labelEntityOne.label = {
|
|
1125
|
+
text: positions.length > 0 ? '再次单机后结束绘制' : '单击打开始绘制',
|
|
1126
|
+
show: true,
|
|
1127
|
+
showBackground: true,
|
|
1128
|
+
font: '14px monospace',
|
|
1129
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
1130
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
1131
|
+
pixelOffset: new Cesium.Cartesian2(-20, -80), //left top
|
|
1132
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 新增,禁用深度
|
|
1133
|
+
};
|
|
1134
|
+
labelEntityOne = $this._drawLayer.entities.add(_labelEntityOne);
|
|
1135
|
+
|
|
1136
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
1137
|
+
}
|
|
1138
|
+
function create() {
|
|
1139
|
+
|
|
1140
|
+
_polygonEntity.ellipse = {
|
|
1141
|
+
semiMinorAxis: new Cesium.CallbackProperty(function () {
|
|
1142
|
+
|
|
1143
|
+
// 在这个回调函数中动态计算圆形的半径
|
|
1144
|
+
return radius;
|
|
1145
|
+
}, true),
|
|
1146
|
+
semiMajorAxis: new Cesium.CallbackProperty(function () {
|
|
1147
|
+
// 在这个回调函数中动态计算圆形的半径
|
|
1148
|
+
return radius;
|
|
1149
|
+
}, true),
|
|
1150
|
+
height: 0,//
|
|
1151
|
+
material: style?.circle?.material || Cesium.Color.RED.withAlpha(0.5),
|
|
1152
|
+
outline: true, // 显示边框
|
|
1153
|
+
outlineColor: style?.circle?.outlineColor || Cesium.Color.GREEN, // 边框颜色
|
|
1154
|
+
zIndex: 5,
|
|
1155
|
+
clampToGround: options.clampToGround || false
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
polyObj = $this._drawLayer.entities.add(_polygonEntity);
|
|
1159
|
+
}
|
|
1160
|
+
function addInfoPoint(position) {
|
|
1161
|
+
var _labelEntity = new Cesium.Entity();
|
|
1162
|
+
_labelEntity.position = position;
|
|
1163
|
+
|
|
1164
|
+
_labelEntity.point = {
|
|
1165
|
+
pixelSize: style?.centerPoint?.pixelSize || 10,
|
|
1166
|
+
outlineColor: style?.centerPoint?.outlineColor || Cesium.Color.BLUE,
|
|
1167
|
+
outlineWidth: style?.centerPoint?.outlineWidth || 0,
|
|
1168
|
+
color: style?.centerPoint?.cololr || Cesium.Color.WHEAT,
|
|
1169
|
+
zIndex: 10,
|
|
1170
|
+
show: JSON.stringify(style?.centerPoint?.show) == 'false' ? false : true
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
};
|
|
1174
|
+
// 获取原始位置
|
|
1175
|
+
var originalPosition = _labelEntity.position.getValue(Cesium.JulianDate.now());
|
|
1176
|
+
// 向上偏移 100 米
|
|
1177
|
+
var newHeight = 10; // 向上偏移 100 米
|
|
1178
|
+
var newPosition = new Cesium.Cartesian3(originalPosition.x, originalPosition.y, originalPosition.z + newHeight);
|
|
1179
|
+
// 更新 entity 的位置属性
|
|
1180
|
+
_labelEntity.position.setValue(newPosition);
|
|
1181
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
1182
|
+
return _labelEntity;
|
|
1183
|
+
}
|
|
1184
|
+
},
|
|
1185
|
+
};
|
|
1186
|
+
return _;
|
|
1187
|
+
})(Cesium);
|
|
1188
|
+
export default MeasureTools;
|