cesium_dev_kit 1.0.45 → 1.0.47

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.
@@ -1,646 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Math3d = Math3d;
7
- let Cesium = {};
8
-
9
- /**
10
- * 三维数学工具
11
- * 默认三维
12
- * @param {*} viewer
13
- */
14
- function Math3d(viewer, cesiumGlobal) {
15
- if (viewer) {
16
- this._viewer = viewer;
17
- Cesium = cesiumGlobal;
18
- }
19
- }
20
- Math3d.prototype = {
21
- /**
22
- * 拆分组合坐标数组
23
- * @param {*} cartesianArr
24
- */
25
- splitCartesians3: function (cartesianArr) {
26
- var positions = [];
27
- for (var i = 0; i < cartesianArr.length; i += 3) {
28
- var cartesian = new Cesium.Cartesian3(cartesianArr[i], cartesianArr[i + 1], cartesianArr[i + 2]);
29
- positions.push(cartesian);
30
- }
31
- positions.push(positions[0]);
32
- return positions;
33
- },
34
- /**
35
- * 计算链路的点集
36
- * @param startPoint 开始节点
37
- * @param endPoint 结束节点
38
- * @param angularityFactor 曲率
39
- * @param numOfSingleLine 点集数量
40
- * @returns {Array}
41
- */
42
- getLinkedPointList: function (startPoint, endPoint, angularityFactor, numOfSingleLine) {
43
- if (this._viewer) {
44
- var result = [];
45
- var startPosition = Cesium.Cartographic.fromCartesian(startPoint);
46
- var endPosition = Cesium.Cartographic.fromCartesian(endPoint);
47
- var startLon = startPosition.longitude * 180 / Math.PI;
48
- var startLat = startPosition.latitude * 180 / Math.PI;
49
- var endLon = endPosition.longitude * 180 / Math.PI;
50
- var endLat = endPosition.latitude * 180 / Math.PI;
51
- var dist = Math.sqrt((startLon - endLon) * (startLon - endLon) + (startLat - endLat) * (startLat - endLat));
52
- //var dist = Cesium.Cartesian3.distance(startPoint, endPoint);
53
- var angularity = dist * angularityFactor;
54
- var startVec = Cesium.Cartesian3.clone(startPoint);
55
- var endVec = Cesium.Cartesian3.clone(endPoint);
56
- var startLength = Cesium.Cartesian3.distance(startVec, Cesium.Cartesian3.ZERO);
57
- var endLength = Cesium.Cartesian3.distance(endVec, Cesium.Cartesian3.ZERO);
58
- Cesium.Cartesian3.normalize(startVec, startVec);
59
- Cesium.Cartesian3.normalize(endVec, endVec);
60
- if (Cesium.Cartesian3.distance(startVec, endVec) == 0) {
61
- return result;
62
- }
63
- var omega = Cesium.Cartesian3.angleBetween(startVec, endVec);
64
- result.push(startPoint);
65
- for (var i = 1; i < numOfSingleLine - 1; i++) {
66
- var t = i * 1.0 / (numOfSingleLine - 1);
67
- var invT = 1 - t;
68
- var startScalar = Math.sin(invT * omega) / Math.sin(omega);
69
- var endScalar = Math.sin(t * omega) / Math.sin(omega);
70
- var startScalarVec = Cesium.Cartesian3.multiplyByScalar(startVec, startScalar, new Cesium.Cartesian3());
71
- var endScalarVec = Cesium.Cartesian3.multiplyByScalar(endVec, endScalar, new Cesium.Cartesian3());
72
- var centerVec = Cesium.Cartesian3.add(startScalarVec, endScalarVec, new Cesium.Cartesian3());
73
- var ht = t * Math.PI;
74
- var centerLength = startLength * invT + endLength * t + Math.sin(ht) * angularity;
75
- centerVec = Cesium.Cartesian3.multiplyByScalar(centerVec, centerLength, centerVec);
76
- result.push(centerVec);
77
- }
78
- result.push(endPoint);
79
- return result;
80
- }
81
- },
82
- /**
83
- * 计算两点的角度
84
- * @param {*} option
85
- */
86
- getPositionsAngle: function (option) {
87
- if (option) {
88
- var position1 = option.position1,
89
- position2 = option.position2,
90
- localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(position1),
91
- //以a点为原点建立局部坐标系(东方向为x轴,北方向为y轴,垂直于地面为z轴),得到一个局部坐标到世界坐标转换的变换矩阵
92
- worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4()),
93
- //求世界坐标到局部坐标的变换矩阵
94
- localPosition_A = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, position1, new Cesium.Cartesian3()),
95
- //a点在局部坐标的位置,其实就是局部坐标原点
96
- localPosition_B = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, position2, new Cesium.Cartesian3()),
97
- //B点在以A点为原点的局部的坐标位置
98
- angle; //弧度
99
- if ('pitch' === option.type) {
100
- //俯仰角
101
-
102
- angle = Math.atan2(localPosition_B.z - localPosition_A.z, localPosition_B.x - localPosition_A.x);
103
- } else if ('heading ' === option.type) {
104
- //偏航角
105
-
106
- angle = Math.atan2(localPosition_B.y - localPosition_A.y, localPosition_B.x - localPosition_A.x);
107
- }
108
- var theta = angle * (180 / Math.PI); //角度
109
- if (theta < 0) {
110
- theta = theta + 360;
111
- }
112
- return theta;
113
- }
114
- },
115
- /**
116
- * 计算一组坐标组成的面的面积
117
- * @param {*} positions
118
- */
119
- getPositionsArea: function (positions) {
120
- let result = 0;
121
- if (positions) {
122
- let h = 0;
123
- let ellipsoid = Cesium.Ellipsoid.WGS84;
124
- positions.push(positions[0]);
125
- for (let i = 1; i < positions.length; i++) {
126
- let oel = ellipsoid.cartographicToCartesian(this.transformWGS84ToCartographic(positions[i - 1]));
127
- let el = ellipsoid.cartographicToCartesian(this.transformWGS84ToCartographic(positions[i]));
128
- h += oel.x * el.y - el.x * oel.y;
129
- }
130
- result = Math.abs(h).toFixed(2);
131
- }
132
- return result;
133
- },
134
- /**
135
- * 计算多边形的面积
136
- * @param {*} points
137
- */
138
- getPolygonArea: function (points) {
139
- if (this._viewer) {
140
- var Bearing = function (from, to) {
141
- var lat1 = from.lat * radiansPerDegree,
142
- lon1 = from.lon * radiansPerDegree,
143
- lat2 = to.lat * radiansPerDegree,
144
- lon2 = to.lon * radiansPerDegree,
145
- angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2));
146
- if (angle < 0) {
147
- angle += Math.PI * 2.0;
148
- }
149
- angle = angle * degreesPerRadian; //角度
150
- return angle;
151
- };
152
- var Angle = function (p1, p2, p3) {
153
- var bearing21 = Bearing(p2, p1),
154
- bearing23 = Bearing(p2, p3),
155
- angle = bearing21 - bearing23;
156
- if (angle < 0) {
157
- angle += 360;
158
- }
159
- return angle;
160
- };
161
- var res = 0;
162
- //拆分三角曲面
163
-
164
- for (var i = 0; i < points.length - 2; i++) {
165
- var j = (i + 1) % points.length,
166
- k = (i + 2) % points.length,
167
- totalAngle = Angle(points[i], points[j], points[k]),
168
- dis_temp1 = this.getPositionsDistance(positions[i], positions[j]),
169
- dis_temp2 = this.getPositionsDistance(positions[j], positions[k]);
170
- res += dis_temp1 * dis_temp2 * Math.abs(Math.sin(totalAngle));
171
- }
172
- return (res / 1000000.0).toFixed(4);
173
- }
174
- },
175
- /**
176
- * 获取两点距离
177
- * @param {*} point1
178
- * @param {*} point2
179
- */
180
- getPointDistance: function (point1, point2) {
181
- if (this._viewer) {
182
- var point1cartographic = Cesium.Cartographic.fromCartesian(point1),
183
- point2cartographic = Cesium.Cartographic.fromCartesian(point2);
184
- /**根据经纬度计算出距离**/
185
- var geodesic = new Cesium.EllipsoidGeodesic();
186
- geodesic.setEndPoints(point1cartographic, point2cartographic);
187
- var s = geodesic.surfaceDistance;
188
-
189
- //返回两点之间的距离
190
- s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
191
- return s;
192
- }
193
- },
194
- /**
195
- * 获取84坐标的距离
196
- * @param {*} positions
197
- */
198
- getPositionDistance: function (positions) {
199
- let distance = 0;
200
- for (let i = 0; i < positions.length - 1; i++) {
201
- let point1cartographic = this.transformWGS84ToCartographic(positions[i]);
202
- let point2cartographic = this.transformWGS84ToCartographic(positions[i + 1]);
203
- let geodesic = new Cesium.EllipsoidGeodesic();
204
- geodesic.setEndPoints(point1cartographic, point2cartographic);
205
- let s = geodesic.surfaceDistance;
206
- s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
207
- distance = distance + s;
208
- }
209
- return distance.toFixed(3);
210
- },
211
- /**
212
- * 获取相交对象
213
- * @param {*} startPos
214
- * @param {*} endPos
215
- * @param {*} excludeArr
216
- * @param {*} bDrillPick
217
- */
218
- getIntersectObj: function (startPos, endPos, excludeArr = [], bDrillPick = false) {
219
- if (this._viewer) {
220
- var direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(endPos, startPos, new Cesium.Cartesian3()), new Cesium.Cartesian3());
221
- var ray = new Cesium.Ray(startPos, direction); //无限延长的射线
222
-
223
- var results = [];
224
- if (bDrillPick) {
225
- results = this._viewer.scene.drillPickFromRay(ray, 10, excludeArr);
226
- } else
227
- //只pick首个物体
228
- {
229
- var result = this._viewer.scene.pickFromRay(ray, excludeArr);
230
- if (Cesium.defined(result)) {
231
- results = [result];
232
- }
233
- }
234
- return results;
235
- }
236
- },
237
- /**
238
- * 椭圆计算
239
- * @param {*} theta
240
- * @param {*} rotation
241
- * @param {*} northVec
242
- * @param {*} eastVec
243
- * @param {*} aSqr
244
- * @param {*} ab
245
- * @param {*} bSqr
246
- * @param {*} mag
247
- * @param {*} unitPos
248
- * @param {*} result
249
- */
250
- getPointOnEllipsoid: function (theta, rotation, northVec, eastVec, aSqr, ab, bSqr, mag, unitPos, result) {
251
- if (this._viewer) {
252
- var rotAxis = new Cesium.Cartesian3();
253
- var tempVec = new Cesium.Cartesian3();
254
- var unitQuat = new Cesium.Quaternion();
255
- var rotMtx = new Cesium.Matrix3();
256
- var azimuth = theta + rotation;
257
- Cesium.Cartesian3.multiplyByScalar(eastVec, Math.cos(azimuth), rotAxis);
258
- Cesium.Cartesian3.multiplyByScalar(northVec, Math.sin(azimuth), tempVec);
259
- Cesium.Cartesian3.add(rotAxis, tempVec, rotAxis);
260
- var cosThetaSquared = Math.cos(theta);
261
- cosThetaSquared = cosThetaSquared * cosThetaSquared;
262
- var sinThetaSquared = Math.sin(theta);
263
- sinThetaSquared = sinThetaSquared * sinThetaSquared;
264
- var radius = ab / Math.sqrt(bSqr * cosThetaSquared + aSqr * sinThetaSquared);
265
- var angle = radius / mag;
266
-
267
- // Create the quaternion to rotate the position vector to the boundary of the ellipse.
268
- Cesium.Quaternion.fromAxisAngle(rotAxis, angle, unitQuat);
269
- Cesium.Matrix3.fromQuaternion(unitQuat, rotMtx);
270
- Cesium.Matrix3.multiplyByVector(rotMtx, unitPos, result);
271
- Cesium.Cartesian3.normalize(result, result);
272
- Cesium.Cartesian3.multiplyByScalar(result, mag, result);
273
- return result;
274
- }
275
- },
276
- /**
277
- * 计算点的插值高度
278
- * Returns the positions raised to the given heights
279
- * @private
280
- */
281
- raisePositionsToHeight: function (positions, options, extrude) {
282
- if (this._viewer) {
283
- var scratchCartesian1 = new Cesium.Cartesian3();
284
- var scratchCartesian2 = new Cesium.Cartesian3();
285
- var scratchCartesian3 = new Cesium.Cartesian3();
286
- var scratchNormal = new Cesium.Cartesian3();
287
- var ellipsoid = options.ellipsoid;
288
- var height = options.height;
289
- var extrudedHeight = options.extrudedHeight;
290
- var size = extrude ? positions.length / 3 * 2 : positions.length / 3;
291
- var finalPositions = new Float64Array(size * 3);
292
- var length = positions.length;
293
- var bottomOffset = extrude ? length : 0;
294
- for (var i = 0; i < length; i += 3) {
295
- var i1 = i + 1;
296
- var i2 = i + 2;
297
- var position = Cesium.Cartesian3.fromArray(positions, i, scratchCartesian1);
298
- ellipsoid.scaleToGeodeticSurface(position, position);
299
- var extrudedPosition = Cesium.Cartesian3.clone(position, scratchCartesian2);
300
- var normal = ellipsoid.geodeticSurfaceNormal(position, scratchNormal);
301
- var scaledNormal = Cesium.Cartesian3.multiplyByScalar(normal, height, scratchCartesian3);
302
- Cesium.Cartesian3.add(position, scaledNormal, position);
303
- if (extrude) {
304
- Cesium.Cartesian3.multiplyByScalar(normal, extrudedHeight, scaledNormal);
305
- Cesium.Cartesian3.add(extrudedPosition, scaledNormal, extrudedPosition);
306
- finalPositions[i + bottomOffset] = extrudedPosition.x;
307
- finalPositions[i1 + bottomOffset] = extrudedPosition.y;
308
- finalPositions[i2 + bottomOffset] = extrudedPosition.z;
309
- }
310
- finalPositions[i] = position.x;
311
- finalPositions[i1] = position.y;
312
- finalPositions[i2] = position.z;
313
- }
314
- return finalPositions;
315
- }
316
- },
317
- /**
318
- * options.semiMinorAxis:短半轴
319
- * options.semiMajorAxis:长半轴
320
- * options.rotation:旋转角度 弧度
321
- * options.center:中心点 笛卡尔坐标
322
- * options.granularity:粒度 弧度
323
- * Returns an array of positions that make up the ellipse.
324
- * @private
325
- */
326
- computeEllipseEdgePositions: function (options) {
327
- if (this._viewer) {
328
- var unitPosScratch = new Cesium.Cartesian3();
329
- var eastVecScratch = new Cesium.Cartesian3();
330
- var northVecScratch = new Cesium.Cartesian3();
331
- var scratchCartesian1 = new Cesium.Cartesian3();
332
- var semiMinorAxis = options.semiMinorAxis;
333
- var semiMajorAxis = options.semiMajorAxis;
334
- var rotation = options.rotation; //法线
335
- var center = options.center;
336
- var granularity = options.granularity && typeof options.granularity === 'number' ? options.granularity : Math.PI / 180.0; // 角度间隔
337
- if (granularity > Math.PI / 12.0) {
338
- granularity = Math.PI / 12.0;
339
- } //最小分24
340
- if (granularity < Math.PI / 180.0) {
341
- granularity = Math.PI / 180.0;
342
- } //最大分360
343
- var aSqr = semiMinorAxis * semiMinorAxis;
344
- var bSqr = semiMajorAxis * semiMajorAxis;
345
- var ab = semiMajorAxis * semiMinorAxis;
346
- var mag = Cesium.Cartesian3.magnitude(center); //
347
- var unitPos = Cesium.Cartesian3.normalize(center, unitPosScratch);
348
- var eastVec = Cesium.Cartesian3.cross(Cesium.Cartesian3.UNIT_Z, center, eastVecScratch);
349
- eastVec = Cesium.Cartesian3.normalize(eastVec, eastVec);
350
- var northVec = Cesium.Cartesian3.cross(unitPos, eastVec, northVecScratch);
351
- var numPts = Math.ceil(Cesium.Math.PI * 2 / granularity);
352
- var deltaTheta = granularity;
353
- var theta = 0;
354
- var position = scratchCartesian1;
355
- var i;
356
- var outerIndex = 0;
357
- var outerPositions = [];
358
- for (i = 0; i < numPts; i++) {
359
- theta = i * deltaTheta;
360
- position = this.getPointOnEllipsoid(theta, rotation, northVec, eastVec, aSqr, ab, bSqr, mag, unitPos, position);
361
- outerPositions[outerIndex++] = position.x;
362
- outerPositions[outerIndex++] = position.y;
363
- outerPositions[outerIndex++] = position.z;
364
- }
365
- var r = {};
366
- r.numPts = numPts;
367
- r.outerPositions = outerPositions;
368
- return r;
369
- }
370
- },
371
- /**
372
- * options.semiMinorAxis:短半轴
373
- * options.semiMajorAxis:长半轴
374
- * options.rotation:旋转角度 弧度
375
- * options.center:中心点 笛卡尔坐标
376
- * options.granularity:粒度 弧度
377
- * options.angle:角度 弧度
378
- * Returns an array of positions that make up the ellipse.
379
- * @private
380
- */
381
- computeSectorEdgePositions: function (options) {
382
- if (this._viewer) {
383
- var unitPosScratch = new Cesium.Cartesian3();
384
- var eastVecScratch = new Cesium.Cartesian3();
385
- var northVecScratch = new Cesium.Cartesian3();
386
- var scratchCartesian1 = new Cesium.Cartesian3();
387
- var semiMinorAxis = options.semiMinorAxis;
388
- var semiMajorAxis = options.semiMajorAxis;
389
- var rotation = options.rotation;
390
- var angle = options.angle ? options.angle : Math.PI * 2.0;
391
- var center = options.center;
392
- var granularity = options.granularity && typeof options.granularity === 'number' ? options.granularity : Math.PI / 180.0; // 角度间隔
393
- if (granularity > Math.PI / 12.0) {
394
- granularity = Math.PI / 12.0;
395
- } //最小分24
396
- if (granularity < Math.PI / 180.0) {
397
- granularity = Math.PI / 180.0;
398
- } //最大分360
399
- var aSqr = semiMinorAxis * semiMinorAxis;
400
- var bSqr = semiMajorAxis * semiMajorAxis;
401
- var ab = semiMajorAxis * semiMinorAxis;
402
- var mag = Cesium.Cartesian3.magnitude(center); //
403
- var unitPos = Cesium.Cartesian3.normalize(center, unitPosScratch);
404
- var eastVec = Cesium.Cartesian3.cross(Cesium.Cartesian3.UNIT_Z, center, eastVecScratch);
405
- eastVec = Cesium.Cartesian3.normalize(eastVec, eastVec);
406
- var northVec = Cesium.Cartesian3.cross(unitPos, eastVec, northVecScratch);
407
- var numPts = Math.ceil(angle / granularity); //Math.ceil(Cesium.Math.PI * 2 / granularity);
408
- var deltaTheta = granularity;
409
- var theta = 0;
410
- var position = scratchCartesian1;
411
- var i;
412
- var outerIndex = 0;
413
- var outerPositions = [];
414
- for (i = 0; i < numPts; i++) {
415
- theta = i * deltaTheta;
416
- position = this.getPointOnEllipsoid(theta, rotation, northVec, eastVec, aSqr, ab, bSqr, mag, unitPos, position);
417
- outerPositions[outerIndex++] = position.x;
418
- outerPositions[outerIndex++] = position.y;
419
- outerPositions[outerIndex++] = position.z;
420
- }
421
- var r = {};
422
- r.numPts = numPts;
423
- r.outerPositions = outerPositions;
424
- return r;
425
- }
426
- },
427
- /**
428
- * 获取3DTiles高度
429
- * 传入lonlat数组 角度制的lon lat
430
- * @param {*} lonlats
431
- * @param {*} callback
432
- */
433
- computeLonlatPointsTerrainData: function (lonlats, callback) {
434
- if (this._viewer) {
435
- var pointArrInput = [];
436
- for (var i = 0; i < lonlats.length; i++) {
437
- pointArrInput.push(Cesium.Cartographic.fromDegrees(lonlats[i].lon, lonlats[i].lat));
438
- }
439
- var promise = this._viewer.scene.clampToHeightMostDetailed(pointArrInput); //pointArrInput
440
- promise.then(function (updatedPositions) {
441
- callback(updatedPositions);
442
- });
443
- }
444
- },
445
- /**
446
- * 获取3DTiles高度
447
- * 传入Cartographic类型数组 弧度制经纬度
448
- * @param {*} Cartographics
449
- * @param {*} callback
450
- */
451
- computeCartographicPointsTerrainData: function (Cartographics, callback) {
452
- if (this._viewer) {
453
- if (Cartographics.length <= 0) {
454
- return;
455
- }
456
- var pointArrInput = [];
457
- for (var i = 0; i < Cartographics.length; i++) {
458
- pointArrInput.push(Cesium.Cartesian3.fromRadians(Cartographics[i].longitude, Cartographics[i].latitude, Cartographics[i].height));
459
- }
460
- var promise = this._viewer.scene.clampToHeightMostDetailed(pointArrInput),
461
- $this = this; //pointArrInput
462
- promise.then(function (updatedPositions) {
463
- var result = [];
464
- var ellipsoid = $this._viewer.scene.globe.ellipsoid;
465
- for (var j = 0; j < updatedPositions.length; j++) {
466
- result.push(ellipsoid.cartesianToCartographic(updatedPositions[j]));
467
- }
468
- callback(result);
469
- }).otherwise(function (error) {
470
- console.log(error);
471
- });
472
- }
473
- },
474
- _checkLonDegree: function (value) {
475
- if (value > 180 || value < -180) {
476
- return false;
477
- }
478
- return true;
479
- },
480
- _checkLatDegree: function (value) {
481
- if (value > 90 || value < -90) {
482
- return false;
483
- }
484
- return true;
485
- },
486
- /*
487
- 线段插值
488
- 经纬度坐标插值
489
- start.lon start.lat 单位:度
490
- return [[lon,lat],...]
491
- */
492
- computeInterpolateLineLonlat: function (start, end) {
493
- if (!start || !end) {
494
- return null;
495
- }
496
- if (start.lon || !start.lat || !end.lon || !end.lat) {
497
- return null;
498
- }
499
- if (!this._checkLonDegree(start.lon) || !this._checkLonDegree(end.lon) || !this._checkLatDegree(start.lat) || !this._checkLatDegree(end.lat)) {
500
- return null;
501
- }
502
- var result = [];
503
- result.push([start.lon, start.lat]);
504
- var interval = Math.sqrt(Math.pow(end.lon - start.lon, 2) + Math.pow(end.lat - start.lat, 2));
505
- if (interval <= 0.00001) {
506
- //小于最小间隔
507
- result.push([end.lon, end.lat]);
508
- return result;
509
- } else {
510
- var num = interval / 0.00001;
511
- var stepLon = (end.lon - start.lon) / num;
512
- var stepLat = (end.lat - start.lat) / num;
513
- for (var i = 0; i < num; i++) {
514
- var lon = start.lon + (i + 1) * stepLon;
515
- var lat = start.lat + (i + 1) * stepLat;
516
- result.push([lon, lat]);
517
- }
518
- }
519
- return result;
520
- },
521
- /*
522
- 线段插值
523
- 经纬度坐标插值
524
- Cartographic start.longitude start.latitude 单位:弧度
525
- return [Cartographic,...]
526
- */
527
- computeInterpolateLineCartographic: function (start, end, _Delta) {
528
- if (!start || !end) {
529
- return null;
530
- }
531
- if (!start.longitude || !start.latitude || !end.longitude || !end.latitude) {
532
- return null;
533
- }
534
- var result = [];
535
- //开始点
536
- result.push(new Cesium.Cartographic(start.longitude, start.latitude));
537
- var interval = Math.sqrt(Math.pow(end.longitude - start.longitude, 2) + Math.pow(end.latitude - start.latitude, 2));
538
- var delta = _Delta && typeof _Delta === 'number' ? _Delta : 0.00001 * Math.PI / 180.0;
539
- if (interval <= delta) {
540
- //小于最小间隔
541
- result.push(new Cesium.Cartographic(end.longitude, end.latitude));
542
- return result;
543
- } else {
544
- var num = interval / delta;
545
- var stepLon = (end.longitude - start.longitude) / num;
546
- var stepLat = (end.latitude - start.latitude) / num;
547
- for (var i = 0; i < num; i++) {
548
- var lon = start.longitude + (i + 1) * stepLon;
549
- var lat = start.latitude + (i + 1) * stepLat;
550
- result.push(new Cesium.Cartographic(lon, lat)); //与最后一个点有偏差
551
- }
552
-
553
- result.push(new Cesium.Cartographic(end.longitude, end.latitude, end.height));
554
- }
555
- return result;
556
- },
557
- /*
558
- 线段插值
559
- 经纬度高程插值
560
- Cartographic start.longitude start.latitude 单位:弧度 start.height 高程单位m
561
- return [Cartographic,...]
562
- */
563
- computeInterpolateLineHeightCartographic: function (start, end) {
564
- if (!start || !end) {
565
- return null;
566
- }
567
- if (!start.longitude || !start.latitude || !end.longitude || !end.latitude) {
568
- return null;
569
- }
570
- var result = [];
571
- result.push(new Cesium.Cartographic(start.longitude, start.latitude, start.height));
572
- var interval = Math.sqrt(Math.pow(end.longitude - start.longitude, 2) + Math.pow(end.latitude - start.latitude, 2));
573
- if (interval <= 0.00001 * Math.PI / 180.0) {
574
- //小于最小间隔
575
- result.push(new Cesium.Cartographic(end.longitude, end.latitude, end.height));
576
- return result;
577
- } else {
578
- var num = interval / 0.00001 * Math.PI / 180.0;
579
- var stepLon = (end.longitude - start.longitude) / num;
580
- var stepLat = (end.latitude - start.latitude) / num;
581
- var stepHeight = (end.height - start.height) / num;
582
- for (var i = 0; i < num; i++) {
583
- var lon = start.longitude + (i + 1) * stepLon;
584
- var lat = start.latitude + (i + 1) * stepLat;
585
- var hieght = start.height + (i + 1) * stepHeight;
586
- result.push(new Cesium.Cartographic(lon, lat, hieght));
587
- }
588
- result.push(new Cesium.Cartographic(end.longitude, end.latitude, end.height));
589
- }
590
- return result;
591
- },
592
- /*
593
- 线段插值
594
- 经纬度高程插值
595
- Cartographic start.longitude start.latitude 单位:弧度 start.height 高程单位m
596
- num:分总段数 传入数组长度-1
597
- index:获取到第index点的所有插值 0点是开始点
598
- return [Cartographic,...]
599
- */
600
- computeInterpolate2IndexLineHeightCartographic: function (start, end, num, curIndex) {
601
- if (!start || !end) {
602
- return null;
603
- }
604
- if (!start.longitude || !start.latitude || !end.longitude || !end.latitude) {
605
- return null;
606
- }
607
- var result = [];
608
- result.push(new Cesium.Cartographic(start.longitude, start.latitude, start.height));
609
- var stepLon = (end.longitude - start.longitude) / num;
610
- var stepLat = (end.latitude - start.latitude) / num;
611
- var stepHeight = (end.height - start.height) / num;
612
- for (var i = 0; i < curIndex; i++) {
613
- var lon = start.longitude + (i + 1) * stepLon;
614
- var lat = start.latitude + (i + 1) * stepLat;
615
- var hieght = start.height + (i + 1) * stepHeight;
616
- result.push(new Cesium.Cartographic(lon, lat, hieght));
617
- }
618
- //result.push(new Cesium.Cartographic(end.longitude, end.latitude, end.height));
619
- return result;
620
- },
621
- /*
622
- 线段插值 指定第index值
623
- 经纬度高程插值
624
- Cartographic start.longitude start.latitude 单位:弧度 start.height 高程单位m
625
- num:分总段数 传入数组长度-1
626
- index:获取第index个插值点 0点是开始点
627
- return Cartographic
628
- */
629
- computeInterpolateIndexLineHeightCartographic: function (start, end, num, index) {
630
- if (!start || !end) {
631
- return null;
632
- }
633
- if (!start.longitude || !start.latitude || !end.longitude || !end.latitude) {
634
- return null;
635
- }
636
- //var delta = _Delta && (typeof _Delta === 'number') ? _Delta : 0.00001 * Math.PI / 180.0;
637
- var stepLon = (end.longitude - start.longitude) / num;
638
- var stepLat = (end.latitude - start.latitude) / num;
639
- var stepHeight = (end.height - start.height) / num;
640
- var lon = start.longitude + index * stepLon;
641
- var lat = start.latitude + index * stepLat;
642
- var hieght = start.height + index * stepHeight;
643
- var result = new Cesium.Cartographic(lon, lat, hieght);
644
- return result;
645
- }
646
- };