-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathCzmlDataSource.js
5141 lines (4864 loc) · 120 KB
/
CzmlDataSource.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ArcType from "../Core/ArcType.js";
import BoundingRectangle from "../Core/BoundingRectangle.js";
import Cartesian2 from "../Core/Cartesian2.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Cartographic from "../Core/Cartographic.js";
import ClockRange from "../Core/ClockRange.js";
import ClockStep from "../Core/ClockStep.js";
import Color from "../Core/Color.js";
import CornerType from "../Core/CornerType.js";
import Credit from "../Core/Credit.js";
import createGuid from "../Core/createGuid.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
import Ellipsoid from "../Core/Ellipsoid.js";
import Event from "../Core/Event.js";
import ExtrapolationType from "../Core/ExtrapolationType.js";
import getFilenameFromUri from "../Core/getFilenameFromUri.js";
import HermitePolynomialApproximation from "../Core/HermitePolynomialApproximation.js";
import Iso8601 from "../Core/Iso8601.js";
import JulianDate from "../Core/JulianDate.js";
import LagrangePolynomialApproximation from "../Core/LagrangePolynomialApproximation.js";
import LinearApproximation from "../Core/LinearApproximation.js";
import CesiumMath from "../Core/Math.js";
import NearFarScalar from "../Core/NearFarScalar.js";
import PolygonHierarchy from "../Core/PolygonHierarchy.js";
import Quaternion from "../Core/Quaternion.js";
import Rectangle from "../Core/Rectangle.js";
import ReferenceFrame from "../Core/ReferenceFrame.js";
import Resource from "../Core/Resource.js";
import RuntimeError from "../Core/RuntimeError.js";
import Spherical from "../Core/Spherical.js";
import TimeInterval from "../Core/TimeInterval.js";
import TimeIntervalCollection from "../Core/TimeIntervalCollection.js";
import ClassificationType from "../Scene/ClassificationType.js";
import ColorBlendMode from "../Scene/ColorBlendMode.js";
import HeightReference from "../Scene/HeightReference.js";
import HorizontalOrigin from "../Scene/HorizontalOrigin.js";
import LabelStyle from "../Scene/LabelStyle.js";
import ShadowMode from "../Scene/ShadowMode.js";
import VerticalOrigin from "../Scene/VerticalOrigin.js";
import Uri from "../ThirdParty/Uri.js";
import BillboardGraphics from "./BillboardGraphics.js";
import BoxGraphics from "./BoxGraphics.js";
import CallbackProperty from "./CallbackProperty.js";
import CheckerboardMaterialProperty from "./CheckerboardMaterialProperty.js";
import ColorMaterialProperty from "./ColorMaterialProperty.js";
import CompositeMaterialProperty from "./CompositeMaterialProperty.js";
import CompositePositionProperty from "./CompositePositionProperty.js";
import CompositeProperty from "./CompositeProperty.js";
import ConstantPositionProperty from "./ConstantPositionProperty.js";
import ConstantProperty from "./ConstantProperty.js";
import CorridorGraphics from "./CorridorGraphics.js";
import CylinderGraphics from "./CylinderGraphics.js";
import DataSource from "./DataSource.js";
import DataSourceClock from "./DataSourceClock.js";
import EllipseGraphics from "./EllipseGraphics.js";
import EllipsoidGraphics from "./EllipsoidGraphics.js";
import EntityCluster from "./EntityCluster.js";
import EntityCollection from "./EntityCollection.js";
import GridMaterialProperty from "./GridMaterialProperty.js";
import ImageMaterialProperty from "./ImageMaterialProperty.js";
import LabelGraphics from "./LabelGraphics.js";
import ModelGraphics from "./ModelGraphics.js";
import NodeTransformationProperty from "./NodeTransformationProperty.js";
import PathGraphics from "./PathGraphics.js";
import PointGraphics from "./PointGraphics.js";
import PolygonGraphics from "./PolygonGraphics.js";
import PolylineArrowMaterialProperty from "./PolylineArrowMaterialProperty.js";
import PolylineDashMaterialProperty from "./PolylineDashMaterialProperty.js";
import PolylineGlowMaterialProperty from "./PolylineGlowMaterialProperty.js";
import PolylineGraphics from "./PolylineGraphics.js";
import PolylineOutlineMaterialProperty from "./PolylineOutlineMaterialProperty.js";
import PolylineVolumeGraphics from "./PolylineVolumeGraphics.js";
import PositionPropertyArray from "./PositionPropertyArray.js";
import Property from "./Property.js";
import PropertyArray from "./PropertyArray.js";
import PropertyBag from "./PropertyBag.js";
import RectangleGraphics from "./RectangleGraphics.js";
import ReferenceProperty from "./ReferenceProperty.js";
import Rotation from "./Rotation.js";
import SampledPositionProperty from "./SampledPositionProperty.js";
import SampledProperty from "./SampledProperty.js";
import StripeMaterialProperty from "./StripeMaterialProperty.js";
import StripeOrientation from "./StripeOrientation.js";
import TimeIntervalCollectionPositionProperty from "./TimeIntervalCollectionPositionProperty.js";
import TimeIntervalCollectionProperty from "./TimeIntervalCollectionProperty.js";
import VelocityOrientationProperty from "./VelocityOrientationProperty.js";
import VelocityVectorProperty from "./VelocityVectorProperty.js";
import WallGraphics from "./WallGraphics.js";
import Cesium3DTilesetGraphics from "./Cesium3DTilesetGraphics.js";
// A marker type to distinguish CZML properties where we need to end up with a unit vector.
// The data is still loaded into Cartesian3 objects but they are normalized.
function UnitCartesian3() {}
UnitCartesian3.packedLength = Cartesian3.packedLength;
UnitCartesian3.unpack = Cartesian3.unpack;
UnitCartesian3.pack = Cartesian3.pack;
// As a side note, for the purposes of CZML, Quaternion always indicates a unit quaternion.
let currentId;
function createReferenceProperty(entityCollection, referenceString) {
if (referenceString[0] === "#") {
referenceString = currentId + referenceString;
}
return ReferenceProperty.fromString(entityCollection, referenceString);
}
function createSpecializedProperty(type, entityCollection, packetData) {
if (defined(packetData.reference)) {
return createReferenceProperty(entityCollection, packetData.reference);
}
if (defined(packetData.velocityReference)) {
const referenceProperty = createReferenceProperty(
entityCollection,
packetData.velocityReference
);
switch (type) {
case Cartesian3:
case UnitCartesian3:
return new VelocityVectorProperty(
referenceProperty,
type === UnitCartesian3
);
case Quaternion:
return new VelocityOrientationProperty(referenceProperty);
}
}
throw new RuntimeError(`${JSON.stringify(packetData)} is not valid CZML.`);
}
function createAdapterProperty(property, adapterFunction) {
return new CallbackProperty(function (time, result) {
return adapterFunction(property.getValue(time, result));
}, property.isConstant);
}
const scratchCartesian = new Cartesian3();
const scratchSpherical = new Spherical();
const scratchCartographic = new Cartographic();
const scratchTimeInterval = new TimeInterval();
const scratchQuaternion = new Quaternion();
function unwrapColorInterval(czmlInterval) {
let rgbaf = czmlInterval.rgbaf;
if (defined(rgbaf)) {
return rgbaf;
}
const rgba = czmlInterval.rgba;
if (!defined(rgba)) {
return undefined;
}
const length = rgba.length;
if (length === Color.packedLength) {
return [
Color.byteToFloat(rgba[0]),
Color.byteToFloat(rgba[1]),
Color.byteToFloat(rgba[2]),
Color.byteToFloat(rgba[3]),
];
}
rgbaf = new Array(length);
for (let i = 0; i < length; i += 5) {
rgbaf[i] = rgba[i];
rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]);
rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]);
rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]);
rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]);
}
return rgbaf;
}
function unwrapUriInterval(czmlInterval, sourceUri) {
const uri = defaultValue(czmlInterval.uri, czmlInterval);
if (defined(sourceUri)) {
return sourceUri.getDerivedResource({
url: uri,
});
}
return Resource.createIfNeeded(uri);
}
function unwrapRectangleInterval(czmlInterval) {
let wsen = czmlInterval.wsen;
if (defined(wsen)) {
return wsen;
}
const wsenDegrees = czmlInterval.wsenDegrees;
if (!defined(wsenDegrees)) {
return undefined;
}
const length = wsenDegrees.length;
if (length === Rectangle.packedLength) {
return [
CesiumMath.toRadians(wsenDegrees[0]),
CesiumMath.toRadians(wsenDegrees[1]),
CesiumMath.toRadians(wsenDegrees[2]),
CesiumMath.toRadians(wsenDegrees[3]),
];
}
wsen = new Array(length);
for (let i = 0; i < length; i += 5) {
wsen[i] = wsenDegrees[i];
wsen[i + 1] = CesiumMath.toRadians(wsenDegrees[i + 1]);
wsen[i + 2] = CesiumMath.toRadians(wsenDegrees[i + 2]);
wsen[i + 3] = CesiumMath.toRadians(wsenDegrees[i + 3]);
wsen[i + 4] = CesiumMath.toRadians(wsenDegrees[i + 4]);
}
return wsen;
}
function convertUnitSphericalToCartesian(unitSpherical) {
const length = unitSpherical.length;
scratchSpherical.magnitude = 1.0;
if (length === 2) {
scratchSpherical.clock = unitSpherical[0];
scratchSpherical.cone = unitSpherical[1];
Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
}
const result = new Array((length / 3) * 4);
for (let i = 0, j = 0; i < length; i += 3, j += 4) {
result[j] = unitSpherical[i];
scratchSpherical.clock = unitSpherical[i + 1];
scratchSpherical.cone = unitSpherical[i + 2];
Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
result[j + 1] = scratchCartesian.x;
result[j + 2] = scratchCartesian.y;
result[j + 3] = scratchCartesian.z;
}
return result;
}
function convertSphericalToCartesian(spherical) {
const length = spherical.length;
if (length === 3) {
scratchSpherical.clock = spherical[0];
scratchSpherical.cone = spherical[1];
scratchSpherical.magnitude = spherical[2];
Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
}
const result = new Array(length);
for (let i = 0; i < length; i += 4) {
result[i] = spherical[i];
scratchSpherical.clock = spherical[i + 1];
scratchSpherical.cone = spherical[i + 2];
scratchSpherical.magnitude = spherical[i + 3];
Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
result[i + 1] = scratchCartesian.x;
result[i + 2] = scratchCartesian.y;
result[i + 3] = scratchCartesian.z;
}
return result;
}
function convertCartographicRadiansToCartesian(cartographicRadians) {
const length = cartographicRadians.length;
if (length === 3) {
scratchCartographic.longitude = cartographicRadians[0];
scratchCartographic.latitude = cartographicRadians[1];
scratchCartographic.height = cartographicRadians[2];
Ellipsoid.WGS84.cartographicToCartesian(
scratchCartographic,
scratchCartesian
);
return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
}
const result = new Array(length);
for (let i = 0; i < length; i += 4) {
result[i] = cartographicRadians[i];
scratchCartographic.longitude = cartographicRadians[i + 1];
scratchCartographic.latitude = cartographicRadians[i + 2];
scratchCartographic.height = cartographicRadians[i + 3];
Ellipsoid.WGS84.cartographicToCartesian(
scratchCartographic,
scratchCartesian
);
result[i + 1] = scratchCartesian.x;
result[i + 2] = scratchCartesian.y;
result[i + 3] = scratchCartesian.z;
}
return result;
}
function convertCartographicDegreesToCartesian(cartographicDegrees) {
const length = cartographicDegrees.length;
if (length === 3) {
scratchCartographic.longitude = CesiumMath.toRadians(
cartographicDegrees[0]
);
scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]);
scratchCartographic.height = cartographicDegrees[2];
Ellipsoid.WGS84.cartographicToCartesian(
scratchCartographic,
scratchCartesian
);
return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
}
const result = new Array(length);
for (let i = 0; i < length; i += 4) {
result[i] = cartographicDegrees[i];
scratchCartographic.longitude = CesiumMath.toRadians(
cartographicDegrees[i + 1]
);
scratchCartographic.latitude = CesiumMath.toRadians(
cartographicDegrees[i + 2]
);
scratchCartographic.height = cartographicDegrees[i + 3];
Ellipsoid.WGS84.cartographicToCartesian(
scratchCartographic,
scratchCartesian
);
result[i + 1] = scratchCartesian.x;
result[i + 2] = scratchCartesian.y;
result[i + 3] = scratchCartesian.z;
}
return result;
}
function unwrapCartesianInterval(czmlInterval) {
const cartesian = czmlInterval.cartesian;
if (defined(cartesian)) {
return cartesian;
}
const cartesianVelocity = czmlInterval.cartesianVelocity;
if (defined(cartesianVelocity)) {
return cartesianVelocity;
}
const unitCartesian = czmlInterval.unitCartesian;
if (defined(unitCartesian)) {
return unitCartesian;
}
const unitSpherical = czmlInterval.unitSpherical;
if (defined(unitSpherical)) {
return convertUnitSphericalToCartesian(unitSpherical);
}
const spherical = czmlInterval.spherical;
if (defined(spherical)) {
return convertSphericalToCartesian(spherical);
}
const cartographicRadians = czmlInterval.cartographicRadians;
if (defined(cartographicRadians)) {
return convertCartographicRadiansToCartesian(cartographicRadians);
}
const cartographicDegrees = czmlInterval.cartographicDegrees;
if (defined(cartographicDegrees)) {
return convertCartographicDegreesToCartesian(cartographicDegrees);
}
throw new RuntimeError(
`${JSON.stringify(czmlInterval)} is not a valid CZML interval.`
);
}
function normalizePackedCartesianArray(array, startingIndex) {
Cartesian3.unpack(array, startingIndex, scratchCartesian);
Cartesian3.normalize(scratchCartesian, scratchCartesian);
Cartesian3.pack(scratchCartesian, array, startingIndex);
}
function unwrapUnitCartesianInterval(czmlInterval) {
const cartesian = unwrapCartesianInterval(czmlInterval);
if (cartesian.length === 3) {
normalizePackedCartesianArray(cartesian, 0);
return cartesian;
}
for (let i = 1; i < cartesian.length; i += 4) {
normalizePackedCartesianArray(cartesian, i);
}
return cartesian;
}
function normalizePackedQuaternionArray(array, startingIndex) {
Quaternion.unpack(array, startingIndex, scratchQuaternion);
Quaternion.normalize(scratchQuaternion, scratchQuaternion);
Quaternion.pack(scratchQuaternion, array, startingIndex);
}
function unwrapQuaternionInterval(czmlInterval) {
const unitQuaternion = czmlInterval.unitQuaternion;
if (defined(unitQuaternion)) {
if (unitQuaternion.length === 4) {
normalizePackedQuaternionArray(unitQuaternion, 0);
return unitQuaternion;
}
for (let i = 1; i < unitQuaternion.length; i += 5) {
normalizePackedQuaternionArray(unitQuaternion, i);
}
}
return unitQuaternion;
}
function getPropertyType(czmlInterval) {
// The associations in this function need to be kept in sync with the
// associations in unwrapInterval.
// Intentionally omitted due to conficts in CZML property names:
// * Image (conflicts with Uri)
// * Rotation (conflicts with Number)
//
// cartesianVelocity is also omitted due to incomplete support for
// derivative information in CZML properties.
// (Currently cartesianVelocity is hacked directly into the position processing code)
if (typeof czmlInterval === "boolean") {
return Boolean;
} else if (typeof czmlInterval === "number") {
return Number;
} else if (typeof czmlInterval === "string") {
return String;
} else if (czmlInterval.hasOwnProperty("array")) {
return Array;
} else if (czmlInterval.hasOwnProperty("boolean")) {
return Boolean;
} else if (czmlInterval.hasOwnProperty("boundingRectangle")) {
return BoundingRectangle;
} else if (czmlInterval.hasOwnProperty("cartesian2")) {
return Cartesian2;
} else if (
czmlInterval.hasOwnProperty("cartesian") ||
czmlInterval.hasOwnProperty("spherical") ||
czmlInterval.hasOwnProperty("cartographicRadians") ||
czmlInterval.hasOwnProperty("cartographicDegrees")
) {
return Cartesian3;
} else if (
czmlInterval.hasOwnProperty("unitCartesian") ||
czmlInterval.hasOwnProperty("unitSpherical")
) {
return UnitCartesian3;
} else if (
czmlInterval.hasOwnProperty("rgba") ||
czmlInterval.hasOwnProperty("rgbaf")
) {
return Color;
} else if (czmlInterval.hasOwnProperty("arcType")) {
return ArcType;
} else if (czmlInterval.hasOwnProperty("classificationType")) {
return ClassificationType;
} else if (czmlInterval.hasOwnProperty("colorBlendMode")) {
return ColorBlendMode;
} else if (czmlInterval.hasOwnProperty("cornerType")) {
return CornerType;
} else if (czmlInterval.hasOwnProperty("heightReference")) {
return HeightReference;
} else if (czmlInterval.hasOwnProperty("horizontalOrigin")) {
return HorizontalOrigin;
} else if (czmlInterval.hasOwnProperty("date")) {
return JulianDate;
} else if (czmlInterval.hasOwnProperty("labelStyle")) {
return LabelStyle;
} else if (czmlInterval.hasOwnProperty("number")) {
return Number;
} else if (czmlInterval.hasOwnProperty("nearFarScalar")) {
return NearFarScalar;
} else if (czmlInterval.hasOwnProperty("distanceDisplayCondition")) {
return DistanceDisplayCondition;
} else if (
czmlInterval.hasOwnProperty("object") ||
czmlInterval.hasOwnProperty("value")
) {
return Object;
} else if (czmlInterval.hasOwnProperty("unitQuaternion")) {
return Quaternion;
} else if (czmlInterval.hasOwnProperty("shadowMode")) {
return ShadowMode;
} else if (czmlInterval.hasOwnProperty("string")) {
return String;
} else if (czmlInterval.hasOwnProperty("stripeOrientation")) {
return StripeOrientation;
} else if (
czmlInterval.hasOwnProperty("wsen") ||
czmlInterval.hasOwnProperty("wsenDegrees")
) {
return Rectangle;
} else if (czmlInterval.hasOwnProperty("uri")) {
return Uri;
} else if (czmlInterval.hasOwnProperty("verticalOrigin")) {
return VerticalOrigin;
}
// fallback case
return Object;
}
function unwrapInterval(type, czmlInterval, sourceUri) {
// The associations in this function need to be kept in sync with the
// associations in getPropertyType
switch (type) {
case ArcType:
return ArcType[defaultValue(czmlInterval.arcType, czmlInterval)];
case Array:
return czmlInterval.array;
case Boolean:
return defaultValue(czmlInterval["boolean"], czmlInterval);
case BoundingRectangle:
return czmlInterval.boundingRectangle;
case Cartesian2:
return czmlInterval.cartesian2;
case Cartesian3:
return unwrapCartesianInterval(czmlInterval);
case UnitCartesian3:
return unwrapUnitCartesianInterval(czmlInterval);
case Color:
return unwrapColorInterval(czmlInterval);
case ClassificationType:
return ClassificationType[
defaultValue(czmlInterval.classificationType, czmlInterval)
];
case ColorBlendMode:
return ColorBlendMode[
defaultValue(czmlInterval.colorBlendMode, czmlInterval)
];
case CornerType:
return CornerType[defaultValue(czmlInterval.cornerType, czmlInterval)];
case HeightReference:
return HeightReference[
defaultValue(czmlInterval.heightReference, czmlInterval)
];
case HorizontalOrigin:
return HorizontalOrigin[
defaultValue(czmlInterval.horizontalOrigin, czmlInterval)
];
case Image:
return unwrapUriInterval(czmlInterval, sourceUri);
case JulianDate:
return JulianDate.fromIso8601(
defaultValue(czmlInterval.date, czmlInterval)
);
case LabelStyle:
return LabelStyle[defaultValue(czmlInterval.labelStyle, czmlInterval)];
case Number:
return defaultValue(czmlInterval.number, czmlInterval);
case NearFarScalar:
return czmlInterval.nearFarScalar;
case DistanceDisplayCondition:
return czmlInterval.distanceDisplayCondition;
case Object:
return defaultValue(
defaultValue(czmlInterval.object, czmlInterval.value),
czmlInterval
);
case Quaternion:
return unwrapQuaternionInterval(czmlInterval);
case Rotation:
return defaultValue(czmlInterval.number, czmlInterval);
case ShadowMode:
return ShadowMode[
defaultValue(
defaultValue(czmlInterval.shadowMode, czmlInterval.shadows),
czmlInterval
)
];
case String:
return defaultValue(czmlInterval.string, czmlInterval);
case StripeOrientation:
return StripeOrientation[
defaultValue(czmlInterval.stripeOrientation, czmlInterval)
];
case Rectangle:
return unwrapRectangleInterval(czmlInterval);
case Uri:
return unwrapUriInterval(czmlInterval, sourceUri);
case VerticalOrigin:
return VerticalOrigin[
defaultValue(czmlInterval.verticalOrigin, czmlInterval)
];
default:
throw new RuntimeError(type);
}
}
const interpolators = {
HERMITE: HermitePolynomialApproximation,
LAGRANGE: LagrangePolynomialApproximation,
LINEAR: LinearApproximation,
};
function updateInterpolationSettings(packetData, property) {
const interpolationAlgorithm = packetData.interpolationAlgorithm;
const interpolationDegree = packetData.interpolationDegree;
if (defined(interpolationAlgorithm) || defined(interpolationDegree)) {
property.setInterpolationOptions({
interpolationAlgorithm: interpolators[interpolationAlgorithm],
interpolationDegree: interpolationDegree,
});
}
const forwardExtrapolationType = packetData.forwardExtrapolationType;
if (defined(forwardExtrapolationType)) {
property.forwardExtrapolationType =
ExtrapolationType[forwardExtrapolationType];
}
const forwardExtrapolationDuration = packetData.forwardExtrapolationDuration;
if (defined(forwardExtrapolationDuration)) {
property.forwardExtrapolationDuration = forwardExtrapolationDuration;
}
const backwardExtrapolationType = packetData.backwardExtrapolationType;
if (defined(backwardExtrapolationType)) {
property.backwardExtrapolationType =
ExtrapolationType[backwardExtrapolationType];
}
const backwardExtrapolationDuration =
packetData.backwardExtrapolationDuration;
if (defined(backwardExtrapolationDuration)) {
property.backwardExtrapolationDuration = backwardExtrapolationDuration;
}
}
const iso8601Scratch = {
iso8601: undefined,
};
function intervalFromString(intervalString) {
if (!defined(intervalString)) {
return undefined;
}
iso8601Scratch.iso8601 = intervalString;
return TimeInterval.fromIso8601(iso8601Scratch);
}
function wrapPropertyInInfiniteInterval(property) {
const interval = Iso8601.MAXIMUM_INTERVAL.clone();
interval.data = property;
return interval;
}
function convertPropertyToComposite(property) {
// Create the composite and add the old property, wrapped in an infinite interval.
const composite = new CompositeProperty();
composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
return composite;
}
function convertPositionPropertyToComposite(property) {
// Create the composite and add the old property, wrapped in an infinite interval.
const composite = new CompositePositionProperty(property.referenceFrame);
composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
return composite;
}
function processProperty(
type,
object,
propertyName,
packetData,
constrainedInterval,
sourceUri,
entityCollection
) {
let combinedInterval = intervalFromString(packetData.interval);
if (defined(constrainedInterval)) {
if (defined(combinedInterval)) {
combinedInterval = TimeInterval.intersect(
combinedInterval,
constrainedInterval,
scratchTimeInterval
);
} else {
combinedInterval = constrainedInterval;
}
}
let packedLength;
let unwrappedInterval;
let unwrappedIntervalLength;
// CZML properties can be defined in many ways. Most ways represent a structure for
// encoding a single value (number, string, cartesian, etc.) Regardless of the value type,
// if it encodes a single value it will get loaded into a ConstantProperty eventually.
// Alternatively, there are ways of defining a property that require specialized
// client-side representation. Currently, these are ReferenceProperty,
// and client-side velocity computation properties such as VelocityVectorProperty.
const isValue =
!defined(packetData.reference) && !defined(packetData.velocityReference);
const hasInterval =
defined(combinedInterval) &&
!combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
if (packetData.delete === true) {
// If deleting this property for all time, we can simply set to undefined and return.
if (!hasInterval) {
object[propertyName] = undefined;
return;
}
// Deleting depends on the type of property we have.
return removePropertyData(object[propertyName], combinedInterval);
}
let isSampled = false;
if (isValue) {
unwrappedInterval = unwrapInterval(type, packetData, sourceUri);
if (!defined(unwrappedInterval)) {
// not a known value type, bail
return;
}
packedLength = defaultValue(type.packedLength, 1);
unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
isSampled =
!defined(packetData.array) &&
typeof unwrappedInterval !== "string" &&
unwrappedIntervalLength > packedLength &&
type !== Object;
}
// Rotation is a special case because it represents a native type (Number)
// and therefore does not need to be unpacked when loaded as a constant value.
const needsUnpacking = typeof type.unpack === "function" && type !== Rotation;
// Any time a constant value is assigned, it completely blows away anything else.
if (!isSampled && !hasInterval) {
if (isValue) {
object[propertyName] = new ConstantProperty(
needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval
);
} else {
object[propertyName] = createSpecializedProperty(
type,
entityCollection,
packetData
);
}
return;
}
let property = object[propertyName];
let epoch;
const packetEpoch = packetData.epoch;
if (defined(packetEpoch)) {
epoch = JulianDate.fromIso8601(packetEpoch);
}
// Without an interval, any sampled value is infinite, meaning it completely
// replaces any non-sampled property that may exist.
if (isSampled && !hasInterval) {
if (!(property instanceof SampledProperty)) {
object[propertyName] = property = new SampledProperty(type);
}
property.addSamplesPackedArray(unwrappedInterval, epoch);
updateInterpolationSettings(packetData, property);
return;
}
let interval;
// A constant value with an interval is normally part of a TimeIntervalCollection,
// However, if the current property is not a time-interval collection, we need
// to turn it into a Composite, preserving the old data with the new interval.
if (!isSampled && hasInterval) {
// Create a new interval for the constant value.
combinedInterval = combinedInterval.clone();
if (isValue) {
combinedInterval.data = needsUnpacking
? type.unpack(unwrappedInterval, 0)
: unwrappedInterval;
} else {
combinedInterval.data = createSpecializedProperty(
type,
entityCollection,
packetData
);
}
// If no property exists, simply use a new interval collection
if (!defined(property)) {
object[propertyName] = property = isValue
? new TimeIntervalCollectionProperty()
: new CompositeProperty();
}
if (isValue && property instanceof TimeIntervalCollectionProperty) {
// If we created a collection, or it already was one, use it.
property.intervals.addInterval(combinedInterval);
} else if (property instanceof CompositeProperty) {
// If the collection was already a CompositeProperty, use it.
if (isValue) {
combinedInterval.data = new ConstantProperty(combinedInterval.data);
}
property.intervals.addInterval(combinedInterval);
} else {
// Otherwise, create a CompositeProperty but preserve the existing data.
object[propertyName] = property = convertPropertyToComposite(property);
// Change the new data to a ConstantProperty and add it.
if (isValue) {
combinedInterval.data = new ConstantProperty(combinedInterval.data);
}
property.intervals.addInterval(combinedInterval);
}
return;
}
// isSampled && hasInterval
if (!defined(property)) {
object[propertyName] = property = new CompositeProperty();
}
// Create a CompositeProperty but preserve the existing data.
if (!(property instanceof CompositeProperty)) {
object[propertyName] = property = convertPropertyToComposite(property);
}
// Check if the interval already exists in the composite.
const intervals = property.intervals;
interval = intervals.findInterval(combinedInterval);
if (!defined(interval) || !(interval.data instanceof SampledProperty)) {
// If not, create a SampledProperty for it.
interval = combinedInterval.clone();
interval.data = new SampledProperty(type);
intervals.addInterval(interval);
}
interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
updateInterpolationSettings(packetData, interval.data);
}
function removePropertyData(property, interval) {
if (property instanceof SampledProperty) {
property.removeSamples(interval);
return;
} else if (property instanceof TimeIntervalCollectionProperty) {
property.intervals.removeInterval(interval);
return;
} else if (property instanceof CompositeProperty) {
const intervals = property.intervals;
for (let i = 0; i < intervals.length; ++i) {
const intersection = TimeInterval.intersect(
intervals.get(i),
interval,
scratchTimeInterval
);
if (!intersection.isEmpty) {
// remove data from the contained properties
removePropertyData(intersection.data, interval);
}
}
// remove the intervals from the composite
intervals.removeInterval(interval);
return;
}
}
function processPacketData(
type,
object,
propertyName,
packetData,
interval,
sourceUri,
entityCollection
) {
if (!defined(packetData)) {
return;
}
if (Array.isArray(packetData)) {
for (let i = 0, len = packetData.length; i < len; ++i) {
processProperty(
type,
object,
propertyName,
packetData[i],
interval,
sourceUri,
entityCollection
);
}
} else {
processProperty(
type,
object,
propertyName,
packetData,
interval,
sourceUri,
entityCollection
);
}
}
function processPositionProperty(
object,
propertyName,
packetData,
constrainedInterval,
sourceUri,
entityCollection
) {
let combinedInterval = intervalFromString(packetData.interval);
if (defined(constrainedInterval)) {
if (defined(combinedInterval)) {
combinedInterval = TimeInterval.intersect(
combinedInterval,
constrainedInterval,
scratchTimeInterval
);
} else {
combinedInterval = constrainedInterval;
}
}
const numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0;
const packedLength = Cartesian3.packedLength * (numberOfDerivatives + 1);
let unwrappedInterval;
let unwrappedIntervalLength;
const isValue = !defined(packetData.reference);
const hasInterval =
defined(combinedInterval) &&
!combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
if (packetData.delete === true) {
// If deleting this property for all time, we can simply set to undefined and return.
if (!hasInterval) {
object[propertyName] = undefined;
return;
}
// Deleting depends on the type of property we have.
return removePositionPropertyData(object[propertyName], combinedInterval);
}
let referenceFrame;
let isSampled = false;
if (isValue) {
if (defined(packetData.referenceFrame)) {
referenceFrame = ReferenceFrame[packetData.referenceFrame];
}
referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);
unwrappedInterval = unwrapCartesianInterval(packetData);
unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
isSampled = unwrappedIntervalLength > packedLength;
}
// Any time a constant value is assigned, it completely blows away anything else.
if (!isSampled && !hasInterval) {
if (isValue) {
object[propertyName] = new ConstantPositionProperty(
Cartesian3.unpack(unwrappedInterval),
referenceFrame
);
} else {
object[propertyName] = createReferenceProperty(
entityCollection,
packetData.reference
);
}
return;
}
let property = object[propertyName];
let epoch;
const packetEpoch = packetData.epoch;
if (defined(packetEpoch)) {
epoch = JulianDate.fromIso8601(packetEpoch);
}
// Without an interval, any sampled value is infinite, meaning it completely
// replaces any non-sampled property that may exist.
if (isSampled && !hasInterval) {
if (