@lijuhong1981/cesium.utils 0.0.0-stage → 0.1.0

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.
Files changed (99) hide show
  1. package/README.md +62 -2
  2. package/package.json +33 -4
  3. package/src/additions/Geographic.js +603 -0
  4. package/src/additions/GeographicTransform.js +291 -0
  5. package/src/additions/GeometryInstanceAttributes.js +164 -0
  6. package/src/additions/ModelMatrixTransforms.js +822 -0
  7. package/src/additions/PropertyChangedListener.js +72 -0
  8. package/src/additions/PropertyType.js +30 -0
  9. package/src/additions/StTransforms.js +266 -0
  10. package/src/additions/TranslationRotationScaleTransform.js +809 -0
  11. package/src/additions/index.js +8 -0
  12. package/src/index.js +4 -0
  13. package/src/parses/index.js +46 -0
  14. package/src/parses/parseAltitude.js +32 -0
  15. package/src/parses/parseArcType.js +26 -0
  16. package/src/parses/parseAttitudeToHeadingPitchRoll.js +26 -0
  17. package/src/parses/parseAttitudeToMatrix3.js +17 -0
  18. package/src/parses/parseAttitudeToQuaternion.js +21 -0
  19. package/src/parses/parseCartographicToCartesian.js +21 -0
  20. package/src/parses/parseCartographicsToPositions.js +20 -0
  21. package/src/parses/parseClassificationType.js +24 -0
  22. package/src/parses/parseClockRange.js +26 -0
  23. package/src/parses/parseColorBlendMode.js +26 -0
  24. package/src/parses/parseCornerType.js +24 -0
  25. package/src/parses/parseCullFace.js +28 -0
  26. package/src/parses/parseEulerToHeadingPitchRoll.js +21 -0
  27. package/src/parses/parseEulerToQuaternion.js +18 -0
  28. package/src/parses/parseGeographicToCartesian.js +21 -0
  29. package/src/parses/parseGeographicsToPositions.js +20 -0
  30. package/src/parses/parseHeading.js +28 -0
  31. package/src/parses/parseHeightReference.js +24 -0
  32. package/src/parses/parseHorizontalOrigin.js +26 -0
  33. package/src/parses/parseLabelStyle.js +26 -0
  34. package/src/parses/parseLatitude.js +28 -0
  35. package/src/parses/parseLongitude.js +28 -0
  36. package/src/parses/parsePitch.js +26 -0
  37. package/src/parses/parseRoll.js +26 -0
  38. package/src/parses/parseRotationToHeadingPitchRoll.js +40 -0
  39. package/src/parses/parseRotationToMatrix3.js +25 -0
  40. package/src/parses/parseRotationToQuaternion.js +27 -0
  41. package/src/parses/parseShadowMode.js +26 -0
  42. package/src/parses/parseToBoundingRectangle.js +33 -0
  43. package/src/parses/parseToCartesian2.js +35 -0
  44. package/src/parses/parseToCartesian3.js +37 -0
  45. package/src/parses/parseToCartesian3Array.js +21 -0
  46. package/src/parses/parseToCartesian4.js +39 -0
  47. package/src/parses/parseToCartographic.js +31 -0
  48. package/src/parses/parseToColor.js +33 -0
  49. package/src/parses/parseToDistanceDisplayCondition.js +41 -0
  50. package/src/parses/parseToGeographic.js +31 -0
  51. package/src/parses/parseToHeadingPitchRange.js +45 -0
  52. package/src/parses/parseToJulianDate.js +23 -0
  53. package/src/parses/parseToNearFarScalar.js +33 -0
  54. package/src/parses/parseToPlane.js +37 -0
  55. package/src/parses/parseToPolygonHierarchy.js +48 -0
  56. package/src/parses/parseToRange.js +26 -0
  57. package/src/parses/parseToRectangle.js +32 -0
  58. package/src/parses/parseToTimeInterval.js +45 -0
  59. package/src/parses/parseVerticalOrigin.js +28 -0
  60. package/src/revisions/BoundingSphere.revise.js +107 -0
  61. package/src/revisions/Camera.revise.js +366 -0
  62. package/src/revisions/Cartesian.revise.js +313 -0
  63. package/src/revisions/Cartographic.revise.js +443 -0
  64. package/src/revisions/Check.revise.js +164 -0
  65. package/src/revisions/Color.revise.js +271 -0
  66. package/src/revisions/DistanceDisplayCondition.revise.js +37 -0
  67. package/src/revisions/Ellipsoid.revise.js +64 -0
  68. package/src/revisions/Geometry.revise.js +79 -0
  69. package/src/revisions/Globe.revise.js +92 -0
  70. package/src/revisions/HeadingPitchRoll.revise.js +328 -0
  71. package/src/revisions/JulianDate.revise.js +28 -0
  72. package/src/revisions/Material.revise.js +308 -0
  73. package/src/revisions/Math.revise.js +98 -0
  74. package/src/revisions/Matrix.revise.js +578 -0
  75. package/src/revisions/POI.revise.js +178 -0
  76. package/src/revisions/Plane.revise.js +43 -0
  77. package/src/revisions/PolylinePipeline.revise.js +54 -0
  78. package/src/revisions/PostProcessStageLibrary.revise.js +1143 -0
  79. package/src/revisions/Primitive.revise.js +83 -0
  80. package/src/revisions/Property.revise.js +37 -0
  81. package/src/revisions/Quaternion.revise.js +66 -0
  82. package/src/revisions/Rectangle.revise.js +570 -0
  83. package/src/revisions/SceneTransforms.revise.js +82 -0
  84. package/src/revisions/Spherical.revise.js +35 -0
  85. package/src/revisions/index.js +25 -0
  86. package/src/utils/Scratch.js +165 -0
  87. package/src/utils/computeCirclePositions.js +48 -0
  88. package/src/utils/computeCircleRadius.js +19 -0
  89. package/src/utils/computeModelMatrix.js +109 -0
  90. package/src/utils/computeStTransform.js +57 -0
  91. package/src/utils/createGeometry.js +114 -0
  92. package/src/utils/createPointCloudGeometry.js +79 -0
  93. package/src/utils/getGeometryInstanceAttributes.js +43 -0
  94. package/src/utils/getPositionFromTarget.js +29 -0
  95. package/src/utils/getRenderState.js +35 -0
  96. package/src/utils/index.js +13 -0
  97. package/src/utils/isColorMaterial.js +13 -0
  98. package/src/utils/isTranslucent.js +13 -0
  99. package/src/utils/resolveModelMatrixByFixedFrame.js +30 -0
@@ -0,0 +1,603 @@
1
+ import { Cartesian3, Cartographic, Math as CesiumMath, Check, defined, EllipsoidGeodesic } from "cesium";
2
+ import Scratch from "../utils/Scratch.js";
3
+
4
+ /**
5
+ * 因Cesium的Cartographic对象保存的经纬度值是Radius,而不是常用的Degrees,使用起来并不方便,
6
+ * 所以自定义了一个Geographic对象用来保存Degrees值的经纬度。
7
+ * 同时添加了Geographic、Cartographic、Cartesian3三种对象之间的相互转换方法。
8
+ *
9
+ * @param {number} [longitude = 0] [经度] The longitude, in degrees.
10
+ * @param {number} [latitude = 0] [纬度] The latitude, in degrees.
11
+ * @param {number} [altitude = 0] [高度] The altitude, in meters, above the ellipsoid.
12
+ */
13
+ function Geographic(longitude = 0, latitude = 0, altitude = 0) {
14
+
15
+ /**
16
+ * The longitude, in degrees.
17
+ * @type {number}
18
+ * @default 0.0
19
+ */
20
+ this.longitude = longitude;
21
+
22
+ /**
23
+ * The latitude, in degrees.
24
+ * @type {number}
25
+ * @default 0.0
26
+ */
27
+ this.latitude = latitude;
28
+
29
+ /**
30
+ * The altitude, in meters, above the ellipsoid.
31
+ * @type {number}
32
+ * @default 0.0
33
+ */
34
+ this.altitude = altitude;
35
+
36
+ };
37
+
38
+ Object.defineProperties(Geographic.prototype, {
39
+ /**
40
+ * height属性,等同于altitude属性
41
+ * @type {number}
42
+ * @default 0.0
43
+ */
44
+ height: {
45
+ set: function (value) {
46
+ this.altitude = value;
47
+ },
48
+ get: function () {
49
+ return this.altitude;
50
+ }
51
+ }
52
+ });
53
+
54
+ /**
55
+ * 从Degrees经纬度生成Geographic实例
56
+ * @param {number} longitude [经度] The longitude, in degrees.
57
+ * @param {number} latitude [纬度] The latitude, in degrees.
58
+ * @param {number} [altitude = 0] [高度] The altitude, in meters, above the ellipsoid.
59
+ * @param {Geographic} [result] 输出结果的Geographic实例
60
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
61
+ */
62
+ Geographic.fromDegrees = function (longitude, latitude, altitude = 0, result = new Geographic()) {
63
+ //>>includeStart('debug', pragmas.debug);
64
+ Check.typeOf.number('longitude', longitude);
65
+ Check.typeOf.number('latitude', latitude);
66
+ //>>includeEnd('debug');
67
+
68
+ result.longitude = longitude;
69
+ result.latitude = latitude;
70
+ result.altitude = altitude;
71
+ return result;
72
+ };
73
+
74
+ /**
75
+ * 从Radius经纬度生成Geographic实例
76
+ * @param {number} longitude [经度] The longitude, in radius.
77
+ * @param {number} latitude [纬度] The latitude, in radius.
78
+ * @param {number} height [高度] The height, in meters, above the ellipsoid.
79
+ * @param {Geographic} [result] 输出结果的Geographic实例
80
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
81
+ */
82
+ Geographic.fromRadians = function (longitude, latitude, height, result) {
83
+ //>>includeStart('debug', pragmas.debug);
84
+ Check.typeOf.number('longitude', longitude);
85
+ Check.typeOf.number('latitude', latitude);
86
+ //>>includeEnd('debug');
87
+ longitude = CesiumMath.toDegrees(longitude);
88
+ latitude = CesiumMath.toDegrees(latitude);
89
+
90
+ return Geographic.fromDegrees(longitude, latitude, height, result);
91
+ };
92
+
93
+ /**
94
+ * 从Cartographic实例生成Geographic实例
95
+ * @param {Cartographic} cartographic Cartographic实例
96
+ * @param {Geographic} [result] 输出结果的Geographic实例
97
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
98
+ */
99
+ Geographic.fromCartographic = function (cartographic, result = new Geographic()) {
100
+ //>>includeStart('debug', pragmas.debug);
101
+ Check.defined('cartographic', cartographic);
102
+ //>>includeEnd('debug');
103
+
104
+ result.longitude = CesiumMath.toDegrees(cartographic.longitude);
105
+ result.latitude = CesiumMath.toDegrees(cartographic.latitude);
106
+ result.height = cartographic.height;
107
+ return result;
108
+ };
109
+
110
+ /**
111
+ * 从Cartographic实例数组生成Geographic实例数组
112
+ * @param {Array<Cartographic>} cartographics Cartographic实例数组
113
+ * @param {Array} [result] 输出结果的Geographic实例数组
114
+ * @return {Array<Geographic>} 返回修改后的result实例数组或创建一个新的Geographic实例数组
115
+ */
116
+ Geographic.fromCartographicArray = function (cartographics, result = []) {
117
+ //>>includeStart('debug', pragmas.debug);
118
+ Check.typeOf.array('cartographics', cartographics);
119
+ //>>includeEnd('debug');
120
+
121
+ for (let i = 0; i < cartographics.length; i++) {
122
+ result[i] = Geographic.fromCartographic(cartographics[i], result[i]);
123
+ }
124
+ return result;
125
+ };
126
+
127
+ /**
128
+ * 将Geographic实例转换为Cartographic实例
129
+ * @param {Geographic} geographic Geographic实例
130
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
131
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
132
+ */
133
+ Geographic.toCartographic = function (geographic, result) {
134
+ return Cartographic.fromGeographic(geographic, result);
135
+ };
136
+
137
+ /**
138
+ * 将当前Geographic实例转换为Cartographic实例
139
+ * @see Geographic.toCartographic
140
+ */
141
+ Geographic.prototype.toCartographic = function (result) {
142
+ return Geographic.toCartographic(this, result);
143
+ };
144
+
145
+ /**
146
+ * 将Geographic实例数组转换为Cartographic实例数组
147
+ * @param {Array<Geographic>} geographics Geographic实例数组
148
+ * @param {Array} [result] 输出结果的数组
149
+ * @return {Array<Geographic>} 返回修改后的result实例数组或创建一个新的Cartographic实例数组
150
+ */
151
+ Geographic.toCartographicArray = function (geographics, result) {
152
+ return Cartographic.fromGeographicArray(geographics, result);
153
+ };
154
+
155
+ /**
156
+ * 从Cartesian3实例生成Geographic实例
157
+ * @param {Cartesian3} cartesian Cartesian3实例
158
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
159
+ * @param {Geographic} [result] 输出结果的Geographic实例
160
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
161
+ */
162
+ Geographic.fromCartesian = function (cartesian, ellipsoid, result) {
163
+ //>>includeStart('debug', pragmas.debug);
164
+ Check.defined('cartesian', cartesian);
165
+ //>>includeEnd('debug');
166
+ const cartographic = Cartographic.fromCartesian(cartesian, ellipsoid, Scratch.scratchCartographic);
167
+ if (defined(cartographic))
168
+ return Geographic.fromCartographic(cartographic, result);
169
+ };
170
+
171
+ /**
172
+ * 从Cartesian3实例数组生成Geographic实例数组
173
+ * @param {Array<Cartesian3>} cartesians Cartesian3实例数组
174
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
175
+ * @param {Array} [result] 输出结果的数组
176
+ * @return {Array<Geographic>} 返回修改后的result实例数组或创建一个新的Geographic实例数组
177
+ */
178
+ Geographic.fromCartesianArray = function (cartesians, ellipsoid, result = []) {
179
+ //>>includeStart('debug', pragmas.debug);
180
+ Check.typeOf.array('cartesians', cartesians);
181
+ //>>includeEnd('debug');
182
+
183
+ for (let i = 0; i < cartesians.length; i++) {
184
+ result[i] = Geographic.fromCartesian(cartesians[i], ellipsoid, result[i]);
185
+ }
186
+
187
+ return result;
188
+ };
189
+
190
+ /**
191
+ * 将Geographic转换为Cartesian3实例
192
+ * @param {Geographic} geographic Geographic实例
193
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
194
+ * @param {Cartesian3} [result] 输出结果的Cartesian3实例
195
+ * @return {Cartesian3} 返回修改后的result实例或创建一个新的Cartesian3实例
196
+ */
197
+ Geographic.toCartesian = function (geographic, ellipsoid, result) {
198
+ //>>includeStart('debug', pragmas.debug);
199
+ Check.defined('geographic', geographic);
200
+ //>>includeEnd('debug');
201
+
202
+ return Cartesian3.fromDegrees(geographic.longitude, geographic.latitude, geographic.altitude, ellipsoid, result);
203
+ };
204
+
205
+ /**
206
+ * 将当前Geographic实例转换为Cartesian3实例
207
+ * @see Geographic.toCartesian
208
+ */
209
+ Geographic.prototype.toCartesian = function (ellipsoid, result) {
210
+ return Geographic.toCartesian(this, ellipsoid, result);
211
+ };
212
+
213
+ /**
214
+ * 将Geographic实例数组转换为Cartesian3实例数组
215
+ * @param {Array<Geographic>} geographics Geographic实例数组
216
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
217
+ * @param {Array} [result] 输出结果的数组
218
+ * @return {Array<Cartesian3>} 返回修改后的result实例数组或创建一个新的Cartesian3实例数组
219
+ */
220
+ Geographic.toCartesianArray = function (geographics, ellipsoid, result) {
221
+ return Cartesian3.fromGeographicArray(geographics, ellipsoid, result);
222
+ };
223
+
224
+ /**
225
+ * 计算两个Geographic实例之间的直线距离
226
+ * @param {Geographic} left 第一个Geographic实例
227
+ * @param {Geographic} right 第二个Geographic实例
228
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
229
+ * @return {number} 两点之间的直线距离(单位:米)
230
+ */
231
+ Geographic.distance = function (left, right, ellipsoid) {
232
+ Check.defined("left", left);
233
+ Check.defined("right", right);
234
+
235
+ const leftCartesian = Geographic.toCartesian(left, ellipsoid, Scratch.scratchLeftCartesian3);
236
+ const rightCartesian = Geographic.toCartesian(right, ellipsoid, Scratch.scratchRightCartesian3);
237
+
238
+ return Cartesian3.distance(leftCartesian, rightCartesian);
239
+ };
240
+
241
+ /**
242
+ * 计算当前Geographic实例与另一个Geographic实例之间的直线距离
243
+ * @see Geographic.distance
244
+ */
245
+ Geographic.prototype.distance = function (other, ellipsoid) {
246
+ return Geographic.distance(this, other, ellipsoid);
247
+ };
248
+
249
+ /**
250
+ * 计算两个Geographic实例间的地表距离(不考虑高度)
251
+ * @param {Geographic} left 第一个Geographic实例
252
+ * @param {Geographic} right 第二个Geographic实例
253
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
254
+ * @return {number} 两点之间的地表距离(单位:米)
255
+ */
256
+ Geographic.surfaceDistance = function (left, right, ellipsoid) {
257
+ Check.defined("left", left);
258
+ Check.defined("right", right);
259
+
260
+ const start = Geographic.toCartographic(left, Scratch.scratchLeftCartographic);
261
+ const end = Geographic.toCartographic(right, Scratch.scratchRightCartographic);
262
+
263
+ return new EllipsoidGeodesic(start, end, ellipsoid).surfaceDistance;
264
+ };
265
+
266
+ /**
267
+ * 计算当前Geographic实例与另一个Geographic实例之间的地表距离(不考虑高度)
268
+ * @see Geographic.surfaceDistance
269
+ */
270
+ Geographic.prototype.surfaceDistance = function (other, ellipsoid) {
271
+ return Geographic.surfaceDistance(this, other, ellipsoid);
272
+ };
273
+
274
+ /**
275
+ * Geographic实例沿地表向正北方向移动一定距离(不考虑高度)
276
+ * @param {Geographic} geographic Geographic实例
277
+ * @param {number} distance 移动的距离(单位:米)
278
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
279
+ * @param {Geographic} [result] 输出结果的Geographic实例
280
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
281
+ */
282
+ Geographic.moveToNorth = function (geographic, distance, ellipsoid, result) {
283
+ Check.defined('geographic', geographic);
284
+ Check.typeOf.number('distance', distance);
285
+
286
+ const cartographic = Cartographic.fromGeographic(geographic, Scratch.scratchCartographic);
287
+ cartographic.moveToNorth(distance, ellipsoid);
288
+ return cartographic.toGeographic(result);
289
+ };
290
+
291
+ /**
292
+ * 当前Geographic实例沿地表向正北方向移动一定距离(不考虑高度)
293
+ * @see Geographic.moveToNorth
294
+ */
295
+ Geographic.prototype.moveToNorth = function (distance, ellipsoid, result) {
296
+ return Geographic.moveToNorth(this, distance, ellipsoid, result ? result : this);
297
+ };
298
+
299
+ /**
300
+ * Geographic实例沿地表向正南方向移动一定距离(不考虑高度)
301
+ * @param {Geographic} geographic Geographic实例
302
+ * @param {number} distance 移动的距离(单位:米)
303
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
304
+ * @param {Geographic} [result] 输出结果的Geographic实例
305
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
306
+ */
307
+ Geographic.moveToSouth = function (geographic, distance, ellipsoid, result) {
308
+ Check.defined('geographic', geographic);
309
+ Check.typeOf.number('distance', distance);
310
+
311
+ const cartographic = Cartographic.fromGeographic(geographic, Scratch.scratchCartographic);
312
+ cartographic.moveToSouth(distance, ellipsoid);
313
+ return cartographic.toGeographic(result);
314
+ };
315
+
316
+ /**
317
+ * 当前Geographic实例沿地表向正南方向移动一定距离(不考虑高度)
318
+ * @see Geographic.moveToSouth
319
+ */
320
+ Geographic.prototype.moveToSouth = function (distance, ellipsoid, result) {
321
+ return Geographic.moveToSouth(this, distance, ellipsoid, result ? result : this);
322
+ };
323
+
324
+ /**
325
+ * Geographic实例沿地表向正东方向移动一定距离(不考虑高度)
326
+ * @param {Geographic} geographic Geographic实例
327
+ * @param {number} distance 移动的距离(单位:米)
328
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
329
+ * @param {Geographic} [result] 输出结果的Geographic实例
330
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
331
+ */
332
+ Geographic.moveToEast = function (geographic, distance, ellipsoid, result) {
333
+ Check.defined('geographic', geographic);
334
+ Check.typeOf.number('distance', distance);
335
+
336
+ const cartographic = Cartographic.fromGeographic(geographic, Scratch.scratchCartographic);
337
+ cartographic.moveToEast(distance, ellipsoid);
338
+ return cartographic.toGeographic(result);
339
+ };
340
+
341
+ /**
342
+ * 当前Geographic实例沿地表向正东方向移动一定距离(不考虑高度)
343
+ * @see Geographic.moveToEast
344
+ */
345
+ Geographic.prototype.moveToEast = function (distance, ellipsoid, result) {
346
+ return Geographic.moveToEast(this, distance, ellipsoid, result ? result : this);
347
+ };
348
+
349
+ /**
350
+ * Geographic实例沿地表向正西方向移动一定距离(不考虑高度)
351
+ * @param {Geographic} geographic Geographic实例
352
+ * @param {number} distance 移动的距离(单位:米)
353
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
354
+ * @param {Geographic} [result] 输出结果的Geographic实例
355
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
356
+ */
357
+ Geographic.moveToWest = function (geographic, distance, ellipsoid, result) {
358
+ Check.defined('geographic', geographic);
359
+ Check.typeOf.number('distance', distance);
360
+
361
+ const cartographic = Cartographic.fromGeographic(geographic, Scratch.scratchCartographic);
362
+ cartographic.moveToWest(distance, ellipsoid);
363
+ return cartographic.toGeographic(result);
364
+ };
365
+
366
+ /**
367
+ * 当前Geographic实例沿地表向正西方向移动一定距离(不考虑高度)
368
+ * @see Geographic.moveToWest
369
+ */
370
+ Geographic.prototype.moveToWest = function (distance, ellipsoid, result) {
371
+ return Geographic.moveToWest(this, distance, ellipsoid, result ? result : this);
372
+ };
373
+
374
+ /**
375
+ * 克隆Geographic实例
376
+ * @param {Geographic} geographic Geographic实例
377
+ * @param {Geographic} [result] 输出结果的Geographic实例
378
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
379
+ */
380
+ Geographic.clone = function (geographic, result = new Geographic()) {
381
+ Check.defined('geographic', geographic);
382
+
383
+ result.longitude = geographic.longitude;
384
+ result.latitude = geographic.latitude;
385
+ result.altitude = geographic.altitude;
386
+ return result;
387
+ };
388
+
389
+ /**
390
+ * 克隆当前Geographic实例
391
+ * @see Geographic.clone
392
+ */
393
+ Geographic.prototype.clone = function (result) {
394
+ return Geographic.clone(this, result);
395
+ };
396
+
397
+ /**
398
+ * 判断两个Geographic实例是否相等
399
+ * @param {Geographic} left 第一个Geographic实例
400
+ * @param {Geographic} right 第二个Geographic实例
401
+ * @return {boolean} 返回判断结果
402
+ */
403
+ Geographic.equals = function (left, right) {
404
+ return (left === right) ||
405
+ ((defined(left)) &&
406
+ (defined(right)) &&
407
+ (left.longitude === right.longitude) &&
408
+ (left.latitude === right.latitude) &&
409
+ (left.altitude === right.altitude));
410
+ };
411
+
412
+ /**
413
+ * 当前Geographic实例是否与另一个Geographic实例相等
414
+ * @see Geographic.equals
415
+ */
416
+ Geographic.prototype.equals = function (other) {
417
+ return Geographic.equals(this, other);
418
+ };
419
+
420
+ /**
421
+ * 判断两个Geographic实例是否在指定误差范围内相等
422
+ * @param {Geographic} left 第一个Geographic实例
423
+ * @param {Geographic} right 第二个Geographic实例
424
+ * @param {number} [epsilon = 0] 误差范围,默认为0
425
+ * @return {boolean} 返回判断结果
426
+ */
427
+ Geographic.equalsEpsilon = function (left, right, epsilon = 0) {
428
+ return (
429
+ left === right ||
430
+ (defined(left) &&
431
+ defined(right) &&
432
+ Math.abs(left.longitude - right.longitude) <= epsilon &&
433
+ Math.abs(left.latitude - right.latitude) <= epsilon &&
434
+ Math.abs(left.altitude - right.altitude) <= epsilon)
435
+ );
436
+ };
437
+
438
+ /**
439
+ * 当前Geographic实例是否与另一个Geographic实例在指定误差范围内相等
440
+ * @see Geographic.equalsEpsilon
441
+ */
442
+ Geographic.prototype.equalsEpsilon = function (other, epsilon) {
443
+ return Geographic.equalsEpsilon(other, epsilon);
444
+ };
445
+
446
+ /**
447
+ * The number of elements used to pack the object into an array.
448
+ * @type {number}
449
+ */
450
+ Geographic.packedLength = 3;
451
+
452
+ /**
453
+ * 将Geographic实例打包到数组中
454
+ * @param {Geographic} value Geographic实例
455
+ * @param {Array} [array] 输出结果的数组
456
+ * @param {number} [startingIndex = 0] 数组开始索引
457
+ * @return {Array} 返回修改后的array数组或创建一个新的数组
458
+ */
459
+ Geographic.pack = function (value, array = [], startingIndex = 0) {
460
+ //>>includeStart('debug', pragmas.debug);
461
+ Check.defined("value", value);
462
+ //>>includeEnd('debug');
463
+
464
+ array[startingIndex++] = value.longitude;
465
+ array[startingIndex++] = value.latitude;
466
+ array[startingIndex] = value.altitude;
467
+ return array;
468
+ };
469
+
470
+ /**
471
+ * 将数组解包为Geographic实例
472
+ * @param {Array} array 输入的数组
473
+ * @param {number} [startingIndex = 0] 数组开始索引
474
+ * @param {Geographic} [result] 输出结果的Geographic实例
475
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
476
+ */
477
+ Geographic.unpack = function (array, startingIndex = 0, result = new Geographic()) {
478
+ //>>includeStart('debug', pragmas.debug);
479
+ Check.defined("array", array);
480
+ //>>includeEnd('debug');
481
+
482
+ result.longitude = array[startingIndex++];
483
+ result.latitude = array[startingIndex++];
484
+ result.altitude = array[startingIndex];
485
+ return result;
486
+ };
487
+
488
+ /**
489
+ * 从数组生成Geographic实例
490
+ * @see Geographic.unpack
491
+ */
492
+ Geographic.fromArray = Geographic.unpack;
493
+
494
+ /**
495
+ * 将当前Geographic实例转换为数组
496
+ * @param {Array} [array] 输出结果的数组
497
+ * @param {number} [startingIndex = 0] 数组开始索引
498
+ * @return {Array<number>} 返回修改后的array数组或创建一个新的数组
499
+ */
500
+ Geographic.prototype.toArray = function (array, startingIndex) {
501
+ return Geographic.unpack(this, array, startingIndex);
502
+ };
503
+
504
+ /**
505
+ * 将Geographic实例数组打包到数组中
506
+ * @param {Array<Geographic>} geographics Geographic实例数组
507
+ * @param {Array} [result] 输出结果的数组
508
+ * @return {Array<number>} 返回修改后的result数组或创建一个新的数组
509
+ */
510
+ Geographic.packArray = function (geographics, result = []) {
511
+ //>>includeStart('debug', pragmas.debug);
512
+ Check.typeOf.array("geographics", geographics);
513
+ //>>includeEnd('debug');
514
+
515
+ let startingIndex = 0;
516
+ for (let i = 0; i < geographics.length; i++) {
517
+ Geographic.pack(geographics[i], result, startingIndex);
518
+ startingIndex += Geographic.packedLength;
519
+ }
520
+ return result;
521
+ };
522
+
523
+ /**
524
+ * 将数组解包为Geographic实例数组
525
+ * @param {Array<number>} array 输入的数组
526
+ * @param {Array} [result] 输出结果的数组
527
+ * @return {Array<Geographic>} 返回修改后的result数组或创建一个新的数组
528
+ */
529
+ Geographic.unpackArray = function (array, result = []) {
530
+ //>>includeStart('debug', pragmas.debug);
531
+ Check.typeOf.array("array", array);
532
+ //>>includeEnd('debug');
533
+
534
+ result.length = array.length / Geographic.packedLength;
535
+
536
+ let startingIndex = 0;
537
+ for (let i = 0; i < result.length; i++) {
538
+ result[i] = Geographic.unpack(array, startingIndex);
539
+ startingIndex += Geographic.packedLength;
540
+ }
541
+ return result;
542
+ };
543
+
544
+ /**
545
+ * 从数组生成Geographic实例数组
546
+ * @see Geographic.unpackArray
547
+ */
548
+ Geographic.fromArray = Geographic.unpackArray;
549
+
550
+ /**
551
+ * 将Geographic实例数组打包到二维数组中
552
+ * @param {Array<Geographic>} geographics Geographic实例数组
553
+ * @param {Array<Array<number>>} [result] 输出结果的二维数组
554
+ * @return {Array<Array<number>>} 返回修改后的result数组或创建一个新的数组
555
+ */
556
+ Geographic.pack2DArray = function (geographics, result = []) {
557
+ Check.typeOf.array('geographics', geographics);
558
+
559
+ for (let i = 0; i < geographics.length; i++) {
560
+ result[i] = Geographic.pack(geographics[i], result[i]);
561
+ }
562
+ return result;
563
+ };
564
+
565
+ /**
566
+ * 将二维数组解包为Geographic实例数组
567
+ * @param {Array<Array<number>>} array 输入的二维数组
568
+ * @param {Array} [result] 输出结果的数组
569
+ * @return {Array<Geographic>} 返回修改后的result数组或创建一个新的数组
570
+ */
571
+ Geographic.unpack2DArray = function (array, result = []) {
572
+ //>>includeStart('debug', pragmas.debug);
573
+ Check.typeOf.array("array", array);
574
+ //>>includeEnd('debug');
575
+
576
+ for (let i = 0; i < array.length; i++) {
577
+ result[i] = Geographic.unpack(array[i]);
578
+ }
579
+ return result;
580
+ };
581
+
582
+ /**
583
+ * 从二维数组生成Geographic实例数组
584
+ * @see Geographic.unpack2DArray
585
+ */
586
+ Geographic.from2DArray = Geographic.unpack2DArray;
587
+
588
+ /**
589
+ * 一个不可修改的,初始化值为(0.0, 0.0, 0.0)的Geographic实例
590
+ * @type {Geographic}
591
+ */
592
+ Geographic.ZERO = Object.freeze(new Geographic(0.0, 0.0, 0.0));
593
+
594
+ /**
595
+ * 将当前Geographic实例转换为字符串
596
+ * @returns {string} A string representing this Cartesian in the format 'Geographic(longitude, latitude, altitude)'.
597
+ */
598
+ Geographic.prototype.toString = function () {
599
+ return `Geographic(${this.longitude}, ${this.latitude}, ${this.altitude})`;
600
+ };
601
+
602
+ export default Geographic;
603
+ export { Geographic };