@lijuhong1981/cesium.utils 0.0.0-stage → 0.1.1

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 +45 -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,443 @@
1
+ import convertToLatitudeRange from "@lijuhong1981/jsmath/src/convertToLatitudeRange.js";
2
+ import convertToLongitudeRange from "@lijuhong1981/jsmath/src/convertToLongitudeRange.js";
3
+ import { Cartesian3, Cartographic, Check, EllipsoidGeodesic } from "cesium";
4
+ import Geographic from "../additions/Geographic.js";
5
+ import Scratch from "../utils/Scratch.js";
6
+
7
+ /**
8
+ * 扩展 Cesium 的 Cartographic 类,补充与 Geographic、Cartesian3 的互转、距离计算、
9
+ * 沿地表方向移动、打包解包等方法。
10
+ * @class Cartographic
11
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Cartographic.html}
12
+ */
13
+
14
+ Object.defineProperties(Cartographic.prototype, {
15
+ /**
16
+ * 添加altitude属性,等同于height属性
17
+ * @type {number}
18
+ * @default 0.0
19
+ * @memberof Cartographic
20
+ */
21
+ altitude: {
22
+ set: function (value) {
23
+ this.height = value;
24
+ },
25
+ get: function () {
26
+ return this.height;
27
+ }
28
+ },
29
+ });
30
+
31
+ /**
32
+ * 从Geographic实例生成Cartographic实例
33
+ * @param {Geographic} geographic [Geographic实例]
34
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
35
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
36
+ * @memberof Cartographic
37
+ * @static
38
+ */
39
+ Cartographic.fromGeographic = function (geographic, result) {
40
+ //>>includeStart('debug', pragmas.debug);
41
+ Check.defined('geographic', geographic);
42
+ //>>includeEnd('debug');
43
+
44
+ return Cartographic.fromDegrees(geographic.longitude, geographic.latitude, geographic.altitude, result);
45
+ };
46
+
47
+ /**
48
+ * 从Geographic实例数组生成Cartographic实例数组
49
+ * @param {Array<Geographic>} geographics Geographic实例数组
50
+ * @param {Array} [result] 输出结果的Cartographic实例数组
51
+ * @return {Array<Cartographic>} 返回修改后的result实例数组或创建一个新的Cartographic实例数组
52
+ * @memberof Cartographic
53
+ * @static
54
+ */
55
+ Cartographic.fromGeographicArray = function (geographics, result = []) {
56
+ //>>includeStart('debug', pragmas.debug);
57
+ Check.typeOf.array('geographics', geographics);
58
+ //>>includeEnd('debug');
59
+
60
+ for (let i = 0; i < geographics.length; i++) {
61
+ result[i] = Cartographic.fromGeographic(geographics[i], result[i]);
62
+ }
63
+ return result;
64
+ };
65
+
66
+ /**
67
+ * 将Cartographic实例转换为Geographic实例
68
+ * @param {Cartographic} cartographic Cartographic实例
69
+ * @param {Geographic} [result] 输出结果的Geographic实例
70
+ * @return {Geographic} 返回修改后的result实例或创建一个新的Geographic实例
71
+ * @memberof Cartographic
72
+ * @static
73
+ */
74
+ Cartographic.toGeographic = function (cartographic, result) {
75
+ return Geographic.fromCartographic(cartographic, result);
76
+ };
77
+
78
+ /**
79
+ * 将当前Cartographic实例转换为Geographic实例
80
+ * @memberof Cartographic
81
+ * @see Cartographic.toGeographic
82
+ */
83
+ Cartographic.prototype.toGeographic = function (result) {
84
+ return Cartographic.toGeographic(this, result);
85
+ };
86
+
87
+ /**
88
+ * 将Cartographic实例数组转换为Geographic实例数组
89
+ * @param {Array<Cartographic>} cartographics Cartographic实例数组
90
+ * @param {Array} [result] 输出结果的数组
91
+ * @return {Array<Geographic>} 返回修改后的result实例数组或创建一个新的Geographic实例数组
92
+ * @memberof Cartographic
93
+ * @static
94
+ */
95
+ Cartographic.toGeographicArray = function (cartographics, result) {
96
+ return Geographic.fromCartographicArray(cartographics, result);
97
+ };
98
+
99
+ /**
100
+ * 从Cartesian3实例数组生成Cartographic实例数组
101
+ * @param {Array<Cartesian3>} cartesians Cartesian3实例数组
102
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体对象,默认为WGS84椭球体
103
+ * @param {Array} [result] 输出结果的数组
104
+ * @return {Array<Cartographic>} 返回修改后的result实例数组或创建一个新的Cartographic实例数组
105
+ * @memberof Cartographic
106
+ * @static
107
+ */
108
+ Cartographic.fromCartesianArray = function (cartesians, ellipsoid, result = []) {
109
+ //>>includeStart('debug', pragmas.debug);
110
+ Check.typeOf.array('cartesians', cartesians);
111
+ //>>includeEnd('debug');
112
+
113
+ for (let i = 0; i < cartesians.length; i++) {
114
+ result[i] = Cartographic.fromCartesian(cartesians[i], ellipsoid, result[i]);
115
+ }
116
+ return result;
117
+ };
118
+
119
+ /**
120
+ * 将当前Cartographic实例转换为Cartesian3实例
121
+ * @memberof Cartographic
122
+ * @see Cartographic.toCartesian
123
+ */
124
+ Cartographic.prototype.toCartesian = function (ellipsoid, result) {
125
+ return Cartographic.toCartesian(this, ellipsoid, result);
126
+ };
127
+
128
+ /**
129
+ * 将Cartographic实例数组转换为Cartesian3实例数组
130
+ * @param {Array<Cartographic>} cartographics Cartesian3实例数组
131
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体对象,默认为WGS84椭球体
132
+ * @param {Array} [result] 输出结果的数组
133
+ * @return {Array<Cartesian3>} 返回修改后的result实例数组或创建一个新的Cartesian3实例数组
134
+ * @memberof Cartographic
135
+ * @static
136
+ */
137
+ Cartographic.toCartesianArray = function (cartographics, ellipsoid, result) {
138
+ return Cartesian3.fromCartographicArray(cartographics, ellipsoid, result);
139
+ };
140
+
141
+ /**
142
+ * 计算两个Cartographic实例之间的直线距离
143
+ * @param {Cartographic} left 第一个Cartographic实例
144
+ * @param {Cartographic} right 第二个Cartographic实例
145
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
146
+ * @return {number} 两点之间的直线距离(单位:米)
147
+ * @memberof Cartographic
148
+ * @static
149
+ */
150
+ Cartographic.distance = function (left, right, ellipsoid) {
151
+ Check.defined("left", left);
152
+ Check.defined("right", right);
153
+
154
+ const leftCartesian = Cartographic.toCartesian(left, ellipsoid, Scratch.scratchLeftCartesian3);
155
+ const rightCartesian = Cartographic.toCartesian(right, ellipsoid, Scratch.scratchRightCartesian3);
156
+
157
+ return Cartesian3.distance(leftCartesian, rightCartesian);
158
+ };
159
+
160
+ /**
161
+ * 计算当前Cartographic实例与另一个Cartographic实例之间的直线距离
162
+ * @memberof Cartographic
163
+ * @see Cartographic.distance
164
+ */
165
+ Cartographic.prototype.distance = function (other, ellipsoid) {
166
+ return Cartographic.distance(this, other, ellipsoid);
167
+ };
168
+
169
+ /**
170
+ * 计算两个Cartographic实例之间的地表距离(不考虑高度)
171
+ * @param {Cartographic} left 第一个Cartographic实例
172
+ * @param {Cartographic} right 第二个Cartographic实例
173
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
174
+ * @return {number} 两点之间的地表距离(单位:米)
175
+ * @memberof Cartographic
176
+ * @static
177
+ */
178
+ Cartographic.surfaceDistance = function (left, right, ellipsoid) {
179
+ Check.defined("left", left);
180
+ Check.defined("right", right);
181
+
182
+ return new EllipsoidGeodesic(left, right, ellipsoid).surfaceDistance;
183
+ };
184
+
185
+ /**
186
+ * 计算当前Cartographic实例与另一个Cartographic实例之间的地表距离(不考虑高度)
187
+ * @memberof Cartographic
188
+ * @see Cartographic.surfaceDistance
189
+ */
190
+ Cartographic.prototype.surfaceDistance = function (other, ellipsoid) {
191
+ return Cartographic.surfaceDistance(this, other, ellipsoid);
192
+ };
193
+
194
+ /**
195
+ * Cartographic实例沿地表向正北方向移动一定距离(不考虑高度)
196
+ * @param {Cartographic} cartographic Cartographic实例
197
+ * @param {number} distance 移动的距离(单位:米)
198
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
199
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
200
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
201
+ * @memberof Cartographic
202
+ * @static
203
+ */
204
+ Cartographic.moveToNorth = function (cartographic, distance, ellipsoid, result) {
205
+ Check.defined('cartographic', cartographic);
206
+ Check.typeOf.number('distance', distance);
207
+
208
+ const endCar = Cartographic.fromRadians(cartographic.longitude, convertToLatitudeRange(cartographic.latitude + 0.0001, false), cartographic.height, Scratch.scratchEndCartographic);
209
+ const geodesic = new EllipsoidGeodesic(cartographic, endCar, ellipsoid);
210
+ result = geodesic.interpolateUsingSurfaceDistance(distance, result);
211
+ result.height = cartographic.height;
212
+ return result;
213
+ };
214
+
215
+ /**
216
+ * 当前Cartographic实例沿地表向正北方向移动一定距离(不考虑高度)
217
+ * @memberof Cartographic
218
+ * @see Cartographic.moveToNorth
219
+ */
220
+ Cartographic.prototype.moveToNorth = function (distance, ellipsoid, result) {
221
+ return Cartographic.moveToNorth(this, distance, ellipsoid, result ? result : this);
222
+ };
223
+
224
+ /**
225
+ * Cartographic实例沿地表向正南方向移动一定距离(不考虑高度)
226
+ * @param {Cartographic} cartographic Cartographic实例
227
+ * @param {number} distance 移动的距离(单位:米)
228
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
229
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
230
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
231
+ * @memberof Cartographic
232
+ * @static
233
+ */
234
+ Cartographic.moveToSouth = function (cartographic, distance, ellipsoid, result) {
235
+ Check.defined('cartographic', cartographic);
236
+ Check.typeOf.number('distance', distance);
237
+
238
+ const endCar = Cartographic.fromRadians(cartographic.longitude, convertToLatitudeRange(cartographic.latitude - 0.0001, false), cartographic.height, Scratch.scratchEndCartographic);
239
+ const geodesic = new EllipsoidGeodesic(cartographic, endCar, ellipsoid);
240
+ result = geodesic.interpolateUsingSurfaceDistance(distance, result);
241
+ result.height = cartographic.height;
242
+ return result;
243
+ };
244
+
245
+ /**
246
+ * 当前Cartographic实例沿地表向正南方向移动一定距离(不考虑高度)
247
+ * @memberof Cartographic
248
+ * @see Cartographic.moveToSouth
249
+ */
250
+ Cartographic.prototype.moveToSouth = function (distance, ellipsoid, result) {
251
+ return Cartographic.moveToSouth(this, distance, ellipsoid, result ? result : this);
252
+ };
253
+
254
+ /**
255
+ * Cartographic实例沿地表向正东方向移动一定距离(不考虑高度)
256
+ * @param {Cartographic} cartographic Cartographic实例
257
+ * @param {number} distance 移动的距离(单位:米)
258
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
259
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
260
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
261
+ * @memberof Cartographic
262
+ * @static
263
+ */
264
+ Cartographic.moveToEast = function (cartographic, distance, ellipsoid, result) {
265
+ Check.defined('cartographic', cartographic);
266
+ Check.typeOf.number('distance', distance);
267
+
268
+ const endCar = Cartographic.fromRadians(convertToLongitudeRange(cartographic.longitude + 0.0001, false), cartographic.latitude, cartographic.height, Scratch.scratchEndCartographic);
269
+ const geodesic = new EllipsoidGeodesic(cartographic, endCar, ellipsoid);
270
+ result = geodesic.interpolateUsingSurfaceDistance(distance, result);
271
+ result.height = cartographic.height;
272
+ return result;
273
+ };
274
+
275
+ /**
276
+ * 当前Cartographic实例沿地表向正东方向移动一定距离(不考虑高度)
277
+ * @memberof Cartographic
278
+ * @see Cartographic.moveToEast
279
+ */
280
+ Cartographic.prototype.moveToEast = function (distance, ellipsoid, result) {
281
+ return Cartographic.moveToEast(this, distance, ellipsoid, result ? result : this);
282
+ };
283
+
284
+ /**
285
+ * Cartographic实例沿地表向正西方向移动一定距离(不考虑高度)
286
+ * @param {Cartographic} cartographic Cartographic实例
287
+ * @param {number} distance 移动的距离(单位:米)
288
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] 椭球体,默认为WGS84椭球体
289
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
290
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
291
+ * @memberof Cartographic
292
+ * @static
293
+ */
294
+ Cartographic.moveToWest = function (cartographic, distance, ellipsoid, result) {
295
+ Check.defined('cartographic', cartographic);
296
+ Check.typeOf.number('distance', distance);
297
+
298
+ const endCar = Cartographic.fromRadians(convertToLongitudeRange(cartographic.longitude - 0.0001, false), cartographic.latitude, cartographic.height, Scratch.scratchEndCartographic);
299
+ const geodesic = new EllipsoidGeodesic(cartographic, endCar, ellipsoid);
300
+ result = geodesic.interpolateUsingSurfaceDistance(distance, result);
301
+ result.height = cartographic.height;
302
+ return result;
303
+ };
304
+
305
+ /**
306
+ * 当前Cartographic实例沿地表向正西方向移动一定距离(不考虑高度)
307
+ * @memberof Cartographic
308
+ * @see Cartographic.moveToWest
309
+ */
310
+ Cartographic.prototype.moveToWest = function (distance, ellipsoid, result) {
311
+ return Cartographic.moveToWest(this, distance, ellipsoid, result ? result : this);
312
+ };
313
+
314
+ /**
315
+ * The number of elements used to pack the object into an array.
316
+ * @type {number}
317
+ * @constant
318
+ * @memberof Cartographic
319
+ */
320
+ Cartographic.packedLength = 3;
321
+
322
+ /**
323
+ * 将Cartographic实例打包到数组中
324
+ * @param {Cartographic} value Cartographic实例
325
+ * @param {Array} [array] 输出结果的数组
326
+ * @param {number} [startingIndex = 0] 数组开始索引
327
+ * @return {Array} 返回修改后的array数组或创建一个新的数组
328
+ * @memberof Cartographic
329
+ * @static
330
+ */
331
+ Cartographic.pack = function (value, array = [], startingIndex = 0) {
332
+ //>>includeStart('debug', pragmas.debug);
333
+ Check.defined("value", value);
334
+ //>>includeEnd('debug');
335
+
336
+ array[startingIndex++] = value.longitude;
337
+ array[startingIndex++] = value.latitude;
338
+ array[startingIndex] = value.height;
339
+
340
+ return array;
341
+ };
342
+
343
+ /**
344
+ * 将数组解包为Cartographic实例
345
+ * @param {Array} array 输入的数组
346
+ * @param {number} [startingIndex = 0] 数组开始索引
347
+ * @param {Cartographic} [result] 输出结果的Cartographic实例
348
+ * @return {Cartographic} 返回修改后的result实例或创建一个新的Cartographic实例
349
+ * @memberof Cartographic
350
+ * @static
351
+ */
352
+ Cartographic.unpack = function (array, startingIndex = 0, result = new Cartographic()) {
353
+ //>>includeStart('debug', pragmas.debug);
354
+ Check.defined("array", array);
355
+ //>>includeEnd('debug');
356
+
357
+ result.longitude = array[startingIndex++];
358
+ result.latitude = array[startingIndex++];
359
+ result.height = array[startingIndex];
360
+ return result;
361
+ };
362
+
363
+ /**
364
+ * 将Cartographic实例数组打包到数组中
365
+ * @param {Array<Cartographic>} cartographics Cartographic实例数组
366
+ * @param {Array} [result] 输出结果的数组
367
+ * @return {Array<number>} 返回修改后的result数组或创建一个新的数组
368
+ * @memberof Cartographic
369
+ * @static
370
+ */
371
+ Cartographic.packArray = function (cartographics, result = []) {
372
+ //>>includeStart('debug', pragmas.debug);
373
+ Check.typeOf.array("cartographics", cartographics);
374
+ //>>includeEnd('debug');
375
+
376
+ let startingIndex = 0;
377
+ for (let i = 0; i < cartographics.length; i++) {
378
+ Cartographic.pack(cartographics[i], result, startingIndex);
379
+ startingIndex += Cartographic.packedLength;
380
+ }
381
+ return result;
382
+ };
383
+
384
+ /**
385
+ * 将数组解包为Cartographic实例数组
386
+ * @param {Array} array 输入的数组
387
+ * @param {Array} [result] 输出结果的数组
388
+ * @return {Array<Cartographic>} 返回修改后的result数组或创建一个新的数组
389
+ * @memberof Cartographic
390
+ * @static
391
+ */
392
+ Cartographic.unpackArray = function (array, result = []) {
393
+ //>>includeStart('debug', pragmas.debug);
394
+ Check.typeOf.array("array", array);
395
+ //>>includeEnd('debug');
396
+
397
+ result.length = array.length / Cartographic.packedLength;
398
+
399
+ let startingIndex = 0;
400
+ for (let i = 0; i < result.length; i++) {
401
+ result[i] = Cartographic.unpack(array, startingIndex);
402
+ startingIndex += Cartographic.packedLength;
403
+ }
404
+ return result;
405
+ };
406
+
407
+ /**
408
+ * 从数组生成Cartographic实例
409
+ * @memberof Cartographic
410
+ * @see Cartographic.unpack
411
+ */
412
+ Cartographic.fromArray = Cartographic.unpack;
413
+
414
+ /**
415
+ * 将当前Cartographic实例转换为数组
416
+ * @param {Array} [array] 输出结果的数组
417
+ * @param {number} [startingIndex = 0] 数组开始索引
418
+ * @return {Array<number>} 返回修改后的array数组或创建一个新的数组
419
+ * @memberof Cartographic
420
+ */
421
+ Cartographic.prototype.toArray = function (result, startingIndex) {
422
+ return Cartographic.unpack(this, result, startingIndex);
423
+ };
424
+
425
+ /**
426
+ * 将Cartographic实例数组打包到二维数组中
427
+ * @param {Array<Cartographic>} cartographics Cartographic实例数组
428
+ * @param {Array<number>} [result] 输出结果的二维数组
429
+ * @return {Array<number>} 返回修改后的result数组或创建一个新的数组
430
+ * @memberof Cartographic
431
+ * @static
432
+ */
433
+ Cartographic.pack2DArray = function (cartographics, result = []) {
434
+ Check.typeOf.array('cartographics', cartographics);
435
+
436
+ for (let i = 0; i < cartographics.length; i++) {
437
+ result[i] = Cartographic.pack(cartographics[i], result[i]);
438
+ }
439
+ return result;
440
+ };
441
+
442
+ export default Cartographic;
443
+ export { Cartographic };
@@ -0,0 +1,164 @@
1
+ import { Check, DeveloperError } from "cesium";
2
+
3
+ /**
4
+ * 扩展 Cesium 的 Check 类,补充数组、整数、实例类型等校验方法。
5
+ * @class Check
6
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Check.html}
7
+ */
8
+
9
+ /**
10
+ * 如果 test 不是 Array 类型则抛出异常。
11
+ *
12
+ * @param {string} name 被检测变量的名称
13
+ * @param {*} test 待检测的值
14
+ * @exception {DeveloperError} test 必须为 'Array' 类型
15
+ * @memberof Check
16
+ * @static
17
+ */
18
+ Check.typeOf.array = function (name, test) {
19
+ if (Array.isArray(test) === false) {
20
+ throw new DeveloperError(Check.getFailedTypeErrorMessage(typeof test, 'array', name));
21
+ }
22
+ };
23
+
24
+ /**
25
+ * 如果 test 不是整数类型则抛出异常。
26
+ *
27
+ * @param {string} name 被检测变量的名称
28
+ * @param {*} test 待检测的值
29
+ * @exception {DeveloperError} test 必须为 'integer' 类型
30
+ * @memberof Check
31
+ * @static
32
+ */
33
+ Check.typeOf.integer = function (name, test) {
34
+ if (Number.isSafeInteger(test) === false) {
35
+ throw new DeveloperError(Check.getFailedTypeErrorMessage(typeof test, 'integer', name));
36
+ }
37
+ };
38
+
39
+ /**
40
+ * 如果 test 不是整数类型或不小于 limit 则抛出异常。
41
+ *
42
+ * @param {string} name 被检测变量的名称
43
+ * @param {*} test 待检测的值
44
+ * @param {number} limit 用于比较的上限值
45
+ * @exception {DeveloperError} test 必须为 'integer' 类型且小于 limit
46
+ * @memberof Check
47
+ * @static
48
+ */
49
+ Check.typeOf.integer.lessThan = function (name, test, limit) {
50
+ Check.typeOf.integer(name, test);
51
+ if (test >= limit) {
52
+ throw new DeveloperError('Expected ' + name + ' to be less than ' + limit + ', actual value was ' + test);
53
+ }
54
+ };
55
+
56
+ /**
57
+ * 如果 test 不是整数类型或不小于等于 limit 则抛出异常。
58
+ *
59
+ * @param {string} name 被检测变量的名称
60
+ * @param {*} test 待检测的值
61
+ * @param {number} limit 用于比较的上限值
62
+ * @exception {DeveloperError} test 必须为 'integer' 类型且小于等于 limit
63
+ * @memberof Check
64
+ * @static
65
+ */
66
+ Check.typeOf.integer.lessThanOrEquals = function (name, test, limit) {
67
+ Check.typeOf.integer(name, test);
68
+ if (test > limit) {
69
+ throw new DeveloperError('Expected ' + name + ' to be less than or equal to ' + limit + ', actual value was ' + test);
70
+ }
71
+ };
72
+
73
+ /**
74
+ * 如果 test 不是整数类型或不大于 limit 则抛出异常。
75
+ *
76
+ * @param {string} name 被检测变量的名称
77
+ * @param {*} test 待检测的值
78
+ * @param {number} limit 用于比较的下限值
79
+ * @exception {DeveloperError} test 必须为 'integer' 类型且大于 limit
80
+ * @memberof Check
81
+ * @static
82
+ */
83
+ Check.typeOf.integer.greaterThan = function (name, test, limit) {
84
+ Check.typeOf.integer(name, test);
85
+ if (test <= limit) {
86
+ throw new DeveloperError('Expected ' + name + ' to be greater than ' + limit + ', actual value was ' + test);
87
+ }
88
+ };
89
+
90
+ /**
91
+ * 如果 test 不是整数类型或不大于等于 limit 则抛出异常。
92
+ *
93
+ * @param {string} name 被检测变量的名称
94
+ * @param {*} test 待检测的值
95
+ * @param {number} limit 用于比较的下限值
96
+ * @exception {DeveloperError} test 必须为 'integer' 类型且大于等于 limit
97
+ * @memberof Check
98
+ * @static
99
+ */
100
+ Check.typeOf.integer.greaterThanOrEquals = function (name, test, limit) {
101
+ Check.typeOf.integer(name, test);
102
+ if (test < limit) {
103
+ throw new DeveloperError('Expected ' + name + ' to be greater than or equal to' + limit + ', actual value was ' + test);
104
+ }
105
+ };
106
+
107
+ /**
108
+ * 如果 test1 与 test2 不是整数类型或两者值不相等则抛出异常。
109
+ *
110
+ * @param {string} name1 第一个被检测变量的名称
111
+ * @param {string} name2 第二个被检测变量的名称
112
+ * @param {*} test1 待检测的值
113
+ * @param {*} test2 用于比较的值
114
+ * @exception {DeveloperError} test1 与 test2 必须为 'integer' 类型且值相等
115
+ * @memberof Check
116
+ * @static
117
+ */
118
+ Check.typeOf.integer.equals = function (name1, name2, test1, test2) {
119
+ Check.typeOf.integer(name1, test1);
120
+ Check.typeOf.integer(name2, test2);
121
+ if (test1 !== test2) {
122
+ throw new DeveloperError(
123
+ name1 + " must be equal to " + name2 + ", the actual values are " + test1 + " and " + test2
124
+ );
125
+ }
126
+ };
127
+
128
+ /**
129
+ * 如果 test 不是 target 的实例则抛出异常。
130
+ *
131
+ * @param {string} name 被检测变量的名称
132
+ * @param {*} test 待检测的值
133
+ * @param {*} target instanceof 的目标类型
134
+ * @exception {DeveloperError} test 必须为 target 的实例
135
+ * @memberof Check
136
+ * @static
137
+ */
138
+ Check.instanceOf = function (name, test, target) {
139
+ if (test instanceof target === false) {
140
+ throw new DeveloperError(Check.getFailedTypeErrorMessage(false, target.name, name));
141
+ }
142
+ };
143
+
144
+ /**
145
+ * 如果 test1 与 test2 的值不相等则抛出异常。
146
+ *
147
+ * @param {string} name1 第一个被检测变量的名称
148
+ * @param {string} name2 第二个被检测变量的名称
149
+ * @param {*} test1 第一个待检测的值
150
+ * @param {*} test2 第二个用于比较的值
151
+ * @exception {DeveloperError} test1 与 test2 的值必须相等
152
+ * @memberof Check
153
+ * @static
154
+ */
155
+ Check.typeOf.number.equals = function (name1, name2, test1, test2) {
156
+ if (test1 !== test2) {
157
+ throw new DeveloperError(
158
+ `${name1} must be equal to ${name2}, the actual values are ${test1} and ${test2}`,
159
+ );
160
+ }
161
+ };
162
+
163
+ export default Check;
164
+ export { Check };