@cesium/engine 4.0.0 → 6.0.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 (127) hide show
  1. package/Build/Workers/{chunk-SGRWJKNO.js → chunk-2AEUVYIC.js} +15 -15
  2. package/Build/Workers/{chunk-FKHRSGKP.js → chunk-2HEFBNI2.js} +13 -13
  3. package/Build/Workers/{chunk-2C65EKYA.js → chunk-2IZ2LJ3N.js} +1 -1
  4. package/Build/Workers/{chunk-YLS3FX3U.js → chunk-3ENSLRZD.js} +7 -7
  5. package/Build/Workers/{chunk-H6MBQ4W4.js → chunk-3FNFTDKS.js} +4 -4
  6. package/Build/Workers/{chunk-27R2KRIK.js → chunk-437Q4WBM.js} +6 -6
  7. package/Build/Workers/{chunk-RRUPTJ6P.js → chunk-54QBXZYE.js} +6 -6
  8. package/Build/Workers/{chunk-UN7AK64D.js → chunk-6EZ4NFIC.js} +2 -2
  9. package/Build/Workers/{chunk-YMJPANZZ.js → chunk-7FAOTOUR.js} +10 -34
  10. package/Build/Workers/{chunk-KAFF2QX3.js → chunk-7W3AMBD6.js} +5 -5
  11. package/Build/Workers/{chunk-PWDYKCNC.js → chunk-A7T4GOG3.js} +4 -4
  12. package/Build/Workers/{chunk-LGSGX2RH.js → chunk-AMGYJNEB.js} +10 -10
  13. package/Build/Workers/{chunk-F7P2HCYZ.js → chunk-ASJKRCO4.js} +2 -2
  14. package/Build/Workers/chunk-AXODHVUI.js +55 -0
  15. package/Build/Workers/{chunk-P7PWX5HR.js → chunk-BKVKFLIC.js} +7 -7
  16. package/Build/Workers/{chunk-YLAFWVOW.js → chunk-BWTCHYX6.js} +10 -10
  17. package/Build/Workers/{chunk-DJUTBX6A.js → chunk-BZHAJSUN.js} +2 -2
  18. package/Build/Workers/{chunk-LQRFWCNX.js → chunk-CBV4JE6S.js} +5 -5
  19. package/Build/Workers/{chunk-BT6YIL2N.js → chunk-CGHLEZ43.js} +1 -1
  20. package/Build/Workers/{chunk-TF5D2H7B.js → chunk-CLVX47CD.js} +5 -5
  21. package/Build/Workers/{chunk-P4M4QUNQ.js → chunk-DI3VM6NF.js} +6 -6
  22. package/Build/Workers/{chunk-U5LKG6LX.js → chunk-DUMQKN4C.js} +2 -2
  23. package/Build/Workers/{chunk-H52L6U76.js → chunk-DZUFRYQK.js} +11 -11
  24. package/Build/Workers/{chunk-RDCDRNJ7.js → chunk-EFUPZTUD.js} +6 -6
  25. package/Build/Workers/{chunk-PW5CA4MJ.js → chunk-EJWAO37W.js} +7 -7
  26. package/Build/Workers/{chunk-A6EA6KIE.js → chunk-EZPA2AXQ.js} +1 -1
  27. package/Build/Workers/{chunk-7CZEWQWE.js → chunk-FBRBVOAJ.js} +6 -6
  28. package/Build/Workers/{chunk-PGB3EFR7.js → chunk-FDNL4I6K.js} +6 -6
  29. package/Build/Workers/{chunk-FYHCAKU6.js → chunk-FK5BM4WD.js} +11 -11
  30. package/Build/Workers/{chunk-527JG4D7.js → chunk-GQ66IPL6.js} +1 -1
  31. package/Build/Workers/{chunk-V2LKNJGT.js → chunk-HW6ANEVG.js} +5 -5
  32. package/Build/Workers/{chunk-2NLMZNJI.js → chunk-HYNBEK4C.js} +4 -4
  33. package/Build/Workers/{chunk-N5MMDSD2.js → chunk-I6R5G76Q.js} +2 -2
  34. package/Build/Workers/{chunk-XZVQMPWG.js → chunk-J5YKECLG.js} +5 -5
  35. package/Build/Workers/{chunk-7IMAWM6A.js → chunk-KGVHVTX7.js} +229 -17
  36. package/Build/Workers/{chunk-QIS3NB7U.js → chunk-KXTDRKW5.js} +7 -7
  37. package/Build/Workers/{chunk-4VWUFKYW.js → chunk-LCMSJE5D.js} +12 -12
  38. package/Build/Workers/{chunk-XJCTFTBM.js → chunk-M57VBCI4.js} +5 -5
  39. package/Build/Workers/{chunk-EQ6ZAP37.js → chunk-MOSBHBQO.js} +7 -7
  40. package/Build/Workers/{chunk-FE2XG3SS.js → chunk-MQ32KIOU.js} +3 -3
  41. package/Build/Workers/{chunk-TVYIHH4V.js → chunk-PZKVP2WI.js} +14 -14
  42. package/Build/Workers/{chunk-NRETMGYL.js → chunk-SAYI6XNA.js} +13 -13
  43. package/Build/Workers/{chunk-5U4UHRZ2.js → chunk-TV4Q4TKV.js} +10 -10
  44. package/Build/Workers/{chunk-4V6RCTVH.js → chunk-TWN33EAP.js} +10 -10
  45. package/Build/Workers/{chunk-AXGQUPXA.js → chunk-VBOAZG67.js} +17 -17
  46. package/Build/Workers/{chunk-UGZGTV5K.js → chunk-VEPSTOBV.js} +8 -8
  47. package/Build/Workers/{chunk-C6MRR5YL.js → chunk-W2LZZCAF.js} +7 -7
  48. package/Build/Workers/{chunk-VSCXSFHE.js → chunk-XEOY7FXL.js} +13 -13
  49. package/Build/Workers/{chunk-QVJ6IRKV.js → chunk-XZKRFAT7.js} +1 -1
  50. package/Build/Workers/{chunk-I5MQWHBR.js → chunk-YOZZHZVR.js} +4 -4
  51. package/Build/Workers/{chunk-RDM3BKNC.js → chunk-Z6SS6KIF.js} +11 -11
  52. package/Build/Workers/{chunk-FVDTKX3F.js → chunk-ZADWOYGF.js} +2 -2
  53. package/Build/Workers/{chunk-G3MOT7BZ.js → chunk-ZBTL2GWA.js} +6 -6
  54. package/Build/Workers/{chunk-HCZR75II.js → chunk-ZEHXFKIR.js} +15 -15
  55. package/Build/Workers/combineGeometry.js +23 -23
  56. package/Build/Workers/createBoxGeometry.js +17 -17
  57. package/Build/Workers/createBoxOutlineGeometry.js +15 -15
  58. package/Build/Workers/createCircleGeometry.js +25 -25
  59. package/Build/Workers/createCircleOutlineGeometry.js +18 -18
  60. package/Build/Workers/createCoplanarPolygonGeometry.js +32 -32
  61. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +30 -30
  62. package/Build/Workers/createCorridorGeometry.js +29 -28
  63. package/Build/Workers/createCorridorOutlineGeometry.js +28 -27
  64. package/Build/Workers/createCylinderGeometry.js +19 -19
  65. package/Build/Workers/createCylinderOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipseGeometry.js +25 -25
  67. package/Build/Workers/createEllipseOutlineGeometry.js +18 -18
  68. package/Build/Workers/createEllipsoidGeometry.js +18 -18
  69. package/Build/Workers/createEllipsoidOutlineGeometry.js +17 -17
  70. package/Build/Workers/createFrustumGeometry.js +17 -17
  71. package/Build/Workers/createFrustumOutlineGeometry.js +17 -17
  72. package/Build/Workers/createGeometry.js +23 -23
  73. package/Build/Workers/createGroundPolylineGeometry.js +21 -21
  74. package/Build/Workers/createPlaneGeometry.js +15 -15
  75. package/Build/Workers/createPlaneOutlineGeometry.js +14 -14
  76. package/Build/Workers/createPolygonGeometry.js +469 -60
  77. package/Build/Workers/createPolygonOutlineGeometry.js +29 -29
  78. package/Build/Workers/createPolylineGeometry.js +24 -24
  79. package/Build/Workers/createPolylineVolumeGeometry.js +33 -31
  80. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -26
  81. package/Build/Workers/createRectangleGeometry.js +26 -26
  82. package/Build/Workers/createRectangleOutlineGeometry.js +19 -19
  83. package/Build/Workers/createSimplePolylineGeometry.js +22 -22
  84. package/Build/Workers/createSphereGeometry.js +18 -18
  85. package/Build/Workers/createSphereOutlineGeometry.js +17 -17
  86. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  87. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  88. package/Build/Workers/createVectorTileGeometries.js +23 -23
  89. package/Build/Workers/createVectorTilePoints.js +12 -12
  90. package/Build/Workers/createVectorTilePolygons.js +21 -21
  91. package/Build/Workers/createVectorTilePolylines.js +14 -14
  92. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +21 -21
  93. package/Build/Workers/createVerticesFromHeightmap.js +21 -21
  94. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +18 -18
  95. package/Build/Workers/createWallGeometry.js +23 -23
  96. package/Build/Workers/createWallOutlineGeometry.js +22 -22
  97. package/Build/Workers/decodeDraco.js +11 -11
  98. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  99. package/Build/Workers/decodeI3S.js +9 -9
  100. package/Build/Workers/transcodeKTX2.js +7 -7
  101. package/Build/Workers/transferTypedArrayTest.js +1 -1
  102. package/Build/Workers/upsampleQuantizedTerrainMesh.js +21 -21
  103. package/Source/Core/Credit.js +7 -1
  104. package/Source/Core/GoogleMaps.js +8 -24
  105. package/Source/Core/Ion.js +1 -2
  106. package/Source/Core/PolygonGeometry.js +340 -27
  107. package/Source/Core/PolygonGeometryLibrary.js +302 -1
  108. package/Source/Core/Stereographic.js +247 -0
  109. package/Source/Core/TaskProcessor.js +53 -40
  110. package/Source/Core/buildModuleUrl.js +1 -1
  111. package/Source/Core/sampleTerrain.js +43 -10
  112. package/Source/Core/sampleTerrainMostDetailed.js +27 -3
  113. package/Source/Scene/ArcGisMapService.js +1 -2
  114. package/Source/Scene/Billboard.js +7 -0
  115. package/Source/Scene/Cesium3DTilePass.js +1 -1
  116. package/Source/Scene/Cesium3DTileset.js +38 -81
  117. package/Source/Scene/CreditDisplay.js +2 -2
  118. package/Source/Scene/LabelCollection.js +3 -1
  119. package/Source/Scene/Model/Model.js +16 -22
  120. package/Source/Scene/PostProcessStageLibrary.js +3 -3
  121. package/Source/Scene/PrimitiveCollection.js +39 -0
  122. package/Source/Scene/Scene.js +3 -0
  123. package/Source/Scene/createGooglePhotorealistic3DTileset.js +38 -8
  124. package/Source/Widget/CesiumWidget.js +2 -1
  125. package/index.d.ts +65 -31
  126. package/index.js +168 -167
  127. package/package.json +1 -1
@@ -13,8 +13,11 @@ import GeometryAttribute from "./GeometryAttribute.js";
13
13
  import GeometryAttributes from "./GeometryAttributes.js";
14
14
  import GeometryPipeline from "./GeometryPipeline.js";
15
15
  import IndexDatatype from "./IndexDatatype.js";
16
+ import IntersectionTests from "./IntersectionTests.js";
16
17
  import CesiumMath from "./Math.js";
17
18
  import Matrix3 from "./Matrix3.js";
19
+ import Plane from "./Plane.js";
20
+ import PolygonHierarchy from "./PolygonHierarchy.js";
18
21
  import PolygonPipeline from "./PolygonPipeline.js";
19
22
  import PrimitiveType from "./PrimitiveType.js";
20
23
  import Quaternion from "./Quaternion.js";
@@ -466,12 +469,294 @@ PolygonGeometryLibrary.polygonOutlinesFromHierarchy = function (
466
469
  return polygons;
467
470
  };
468
471
 
472
+ const scratchRhumbIntersection = new Cartographic();
473
+ function computeEquatorIntersectionRhumb(start, end, ellipsoid) {
474
+ const c0 = ellipsoid.cartesianToCartographic(start, scratchCartographic0);
475
+ const c1 = ellipsoid.cartesianToCartographic(end, scratchCartographic1);
476
+
477
+ if (Math.sign(c0.latitude) === Math.sign(c1.latitude)) {
478
+ return;
479
+ }
480
+
481
+ scratchRhumbLine.setEndPoints(c0, c1);
482
+
483
+ const intersection = scratchRhumbLine.findIntersectionWithLatitude(
484
+ 0,
485
+ scratchRhumbIntersection
486
+ );
487
+
488
+ if (!defined(intersection)) {
489
+ return;
490
+ }
491
+
492
+ let minLongitude = Math.min(c0.longitude, c1.longitude);
493
+ let maxLongitude = Math.max(c0.longitude, c1.longitude);
494
+
495
+ if (Math.abs(maxLongitude - minLongitude) > CesiumMath.PI) {
496
+ // Crosses IDL, flip min and max
497
+ const swap = minLongitude;
498
+ minLongitude = maxLongitude;
499
+ maxLongitude = swap;
500
+ }
501
+
502
+ if (
503
+ intersection.longitude < minLongitude ||
504
+ intersection.longitude > maxLongitude
505
+ ) {
506
+ return;
507
+ }
508
+
509
+ return ellipsoid.cartographicToCartesian(intersection);
510
+ }
511
+
512
+ function computeEquatorIntersection(start, end, ellipsoid, arcType) {
513
+ if (arcType === ArcType.RHUMB) {
514
+ return computeEquatorIntersectionRhumb(start, end, ellipsoid);
515
+ }
516
+
517
+ const intersection = IntersectionTests.lineSegmentPlane(
518
+ start,
519
+ end,
520
+ Plane.ORIGIN_XY_PLANE
521
+ );
522
+
523
+ if (!defined(intersection)) {
524
+ return;
525
+ }
526
+
527
+ return ellipsoid.scaleToGeodeticSurface(intersection, intersection);
528
+ }
529
+
530
+ const scratchCartographic = new Cartographic();
531
+ function computeEdgesOnPlane(positions, ellipsoid, arcType) {
532
+ const edgesOnPlane = [];
533
+ let startPoint,
534
+ endPoint,
535
+ type,
536
+ next,
537
+ intersection,
538
+ i = 0;
539
+ while (i < positions.length) {
540
+ startPoint = positions[i];
541
+ endPoint = positions[(i + 1) % positions.length];
542
+
543
+ type = CesiumMath.sign(startPoint.z);
544
+ next = CesiumMath.sign(endPoint.z);
545
+
546
+ const getLongitude = (position) => {
547
+ const cartographic = ellipsoid.cartesianToCartographic(
548
+ position,
549
+ scratchCartographic
550
+ );
551
+ return cartographic.longitude;
552
+ };
553
+
554
+ if (type === 0) {
555
+ // The start position is on the split
556
+ edgesOnPlane.push({
557
+ position: i,
558
+ type: type,
559
+ visited: false,
560
+ next: next,
561
+ theta: getLongitude(startPoint),
562
+ });
563
+ } else if (next !== 0) {
564
+ intersection = computeEquatorIntersection(
565
+ startPoint,
566
+ endPoint,
567
+ ellipsoid,
568
+ arcType
569
+ );
570
+
571
+ ++i;
572
+ if (!defined(intersection)) {
573
+ // The line segment is entirely above or below
574
+ continue;
575
+ }
576
+
577
+ // The line segment passed through
578
+ positions.splice(i, 0, intersection);
579
+ edgesOnPlane.push({
580
+ position: i,
581
+ type: type,
582
+ visited: false,
583
+ next: next,
584
+ theta: getLongitude(intersection),
585
+ });
586
+ }
587
+
588
+ ++i;
589
+ }
590
+
591
+ return edgesOnPlane;
592
+ }
593
+
594
+ function wirePolygon(
595
+ polygons,
596
+ polygonIndex,
597
+ positions,
598
+ edgesOnPlane,
599
+ toDelete,
600
+ startIndex,
601
+ abovePlane
602
+ ) {
603
+ const polygon = [];
604
+ let i = startIndex;
605
+ const getMatchingEdge = (i) => (edge) => edge.position === i;
606
+ const polygonsToWire = [];
607
+ do {
608
+ const position = positions[i];
609
+ polygon.push(position);
610
+
611
+ const edgeIndex = edgesOnPlane.findIndex(getMatchingEdge(i));
612
+ const edge = edgesOnPlane[edgeIndex];
613
+ if (!defined(edge)) {
614
+ // The current segment does not intersect
615
+ ++i;
616
+ continue;
617
+ }
618
+
619
+ const { visited: hasBeenVisited, type, next } = edge;
620
+ edge.visited = true;
621
+
622
+ if (type === 0) {
623
+ if (next === 0) {
624
+ // Special case where we'll need to backtrack along the edge
625
+ const previousEdge = edgesOnPlane[edgeIndex - (abovePlane ? 1 : -1)];
626
+ if (previousEdge?.position === i + 1) {
627
+ previousEdge.visited = true;
628
+ } else {
629
+ ++i;
630
+ continue;
631
+ }
632
+ }
633
+
634
+ // Special case where 3 polygons meet
635
+ if (
636
+ (!hasBeenVisited && abovePlane && next > 0) ||
637
+ (startIndex === i && !abovePlane && next < 0)
638
+ ) {
639
+ ++i;
640
+ continue;
641
+ }
642
+ }
643
+
644
+ const followEdge = abovePlane ? type >= 0 : type <= 0;
645
+ if (!followEdge) {
646
+ ++i;
647
+ continue;
648
+ }
649
+
650
+ if (!hasBeenVisited) {
651
+ // Wire another polygon starting at this position on the other side of the edge
652
+ polygonsToWire.push(i);
653
+ }
654
+
655
+ // Continue counter-clockwise to the next edge
656
+ const nextEdgeIndex = edgeIndex + (abovePlane ? 1 : -1);
657
+ const nextEdge = edgesOnPlane[nextEdgeIndex];
658
+ if (!defined(nextEdge)) {
659
+ ++i;
660
+ continue;
661
+ }
662
+
663
+ i = nextEdge.position;
664
+ } while (
665
+ i < positions.length &&
666
+ i >= 0 &&
667
+ i !== startIndex &&
668
+ polygon.length < positions.length
669
+ );
670
+
671
+ polygons.splice(polygonIndex, toDelete, polygon);
672
+
673
+ for (const index of polygonsToWire) {
674
+ polygonIndex = wirePolygon(
675
+ polygons,
676
+ ++polygonIndex,
677
+ positions,
678
+ edgesOnPlane,
679
+ 0,
680
+ index,
681
+ !abovePlane
682
+ );
683
+ }
684
+
685
+ return polygonIndex;
686
+ }
687
+
688
+ /**
689
+ * Splits an array of polygons, defined as a list of Cartesian3 positions in counter-clockwise winding order, along the equator.
690
+ *
691
+ * @param {Array<Cartesian3[]>} outerRings An array of polygons, defined as a list of Cartesian3 positions in counter-clockwise winding order.
692
+ * @param {Ellipsoid} ellipsoid The ellipsoid to be used as a reference.
693
+ * @param {ArcType} arcType The type of line the polygon edges must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.
694
+ * @param {Array<Cartesian3[]>} [result] An array of split polygons.
695
+ *
696
+ * @returns {Array<Cartesian3[]>} An array of split polygons.
697
+ */
698
+ PolygonGeometryLibrary.splitPolygonsOnEquator = function (
699
+ outerRings,
700
+ ellipsoid,
701
+ arcType,
702
+ result
703
+ ) {
704
+ if (!defined(result)) {
705
+ result = [];
706
+ }
707
+
708
+ result.splice(0, 0, ...outerRings);
709
+ result.length = outerRings.length;
710
+
711
+ let currentPolygon = 0;
712
+ while (currentPolygon < result.length) {
713
+ // Adapted from https://www.sciencedirect.com/science/article/abs/pii/B9780125434577500589#:~:text=If%20the%20plane%20intersects%20the,tree%20and%20polygon%20intersection%20libraries
714
+ const outerRing = result[currentPolygon];
715
+ const positions = outerRing.slice();
716
+
717
+ if (outerRing.length < 3) {
718
+ result[currentPolygon] = positions;
719
+ ++currentPolygon;
720
+ continue;
721
+ }
722
+
723
+ // Step 1: Get all edges which intersect the split line, splciing any found intersections points into the list of positions
724
+ const edgesOnPlane = computeEdgesOnPlane(positions, ellipsoid, arcType);
725
+ // If nothing intersected (no point were added), or there is only a single point on the plane, use the original polygon
726
+ if (positions.length === outerRing.length || edgesOnPlane.length <= 1) {
727
+ result[currentPolygon] = positions;
728
+ ++currentPolygon;
729
+ continue;
730
+ }
731
+
732
+ // Step 2: Sort the edges along the split line by the distance between their starting points and the starting point of the split line.
733
+ edgesOnPlane.sort((a, b) => {
734
+ return a.theta - b.theta;
735
+ });
736
+
737
+ // Step 3: Rewire polygons, splicing each polygon into the array of results
738
+ const north = positions[0].z >= 0.0;
739
+ currentPolygon = wirePolygon(
740
+ result,
741
+ currentPolygon,
742
+ positions,
743
+ edgesOnPlane,
744
+ 1,
745
+ 0,
746
+ north
747
+ );
748
+ }
749
+
750
+ return result;
751
+ };
752
+
469
753
  PolygonGeometryLibrary.polygonsFromHierarchy = function (
470
754
  polygonHierarchy,
471
755
  keepDuplicates,
472
756
  projectPointsTo2D,
473
757
  scaleToEllipsoidSurface,
474
- ellipsoid
758
+ ellipsoid,
759
+ splitPolygons
475
760
  ) {
476
761
  // create from a polygon hierarchy
477
762
  // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
@@ -481,6 +766,8 @@ PolygonGeometryLibrary.polygonsFromHierarchy = function (
481
766
  const queue = new Queue();
482
767
  queue.enqueue(polygonHierarchy);
483
768
 
769
+ let split = defined(splitPolygons);
770
+
484
771
  while (queue.length !== 0) {
485
772
  const outerNode = queue.dequeue();
486
773
  let outerRing = outerNode.positions;
@@ -520,6 +807,20 @@ PolygonGeometryLibrary.polygonsFromHierarchy = function (
520
807
  outerRing = outerRing.slice().reverse();
521
808
  }
522
809
 
810
+ if (split) {
811
+ split = false;
812
+ let polygons = [outerRing];
813
+ polygons = splitPolygons(polygons, polygons);
814
+
815
+ if (polygons.length > 1) {
816
+ for (const positions of polygons) {
817
+ queue.enqueue(new PolygonHierarchy(positions, holes));
818
+ }
819
+
820
+ continue;
821
+ }
822
+ }
823
+
523
824
  let positions = outerRing.slice();
524
825
  const numChildren = defined(holes) ? holes.length : 0;
525
826
  const polygonHoles = [];
@@ -0,0 +1,247 @@
1
+ import Cartesian2 from "./Cartesian2.js";
2
+ import Cartesian3 from "./Cartesian3.js";
3
+ import Cartographic from "./Cartographic.js";
4
+ import Check from "./Check.js";
5
+ import defined from "./defined.js";
6
+ import Ellipsoid from "./Ellipsoid.js";
7
+ import EllipsoidTangentPlane from "./EllipsoidTangentPlane.js";
8
+ import IntersectionTests from "./IntersectionTests.js";
9
+ import CesiumMath from "./Math.js";
10
+ import Ray from "./Ray.js";
11
+
12
+ /**
13
+ * Represents a point in stereographic coordinates, which can be obtained by projecting a cartesian coordinate from one pole onto a tangent plane at the other pole.
14
+ * The stereographic projection faithfully represents the relative directions of all great circles passing through its center point.
15
+ * To faithfully represents angles everywhere, this is a conformal projection, which means points are projected onto an arbrary sphere.
16
+ * @param {Cartesian2} [position] The steroegraphic coordinates.
17
+ * @param {EllipseGeometry} [tangentPlane] The tangent plane onto which the point was projected.
18
+ */
19
+ function Stereographic(position, tangentPlane) {
20
+ this.position = position;
21
+ if (!defined(this.position)) {
22
+ this.position = new Cartesian2();
23
+ }
24
+
25
+ this.tangentPlane = tangentPlane;
26
+ if (!defined(this.tangentPlane)) {
27
+ this.tangentPlane = Stereographic.NORTH_POLE_TANGENT_PLANE;
28
+ }
29
+ }
30
+
31
+ Object.defineProperties(Stereographic.prototype, {
32
+ /**
33
+ * Gets the ellipsoid.
34
+ * @memberof Stereographic.prototype
35
+ * @type {Ellipsoid}
36
+ */
37
+ ellipsoid: {
38
+ get: function () {
39
+ return this.tangentPlane.ellipsoid;
40
+ },
41
+ },
42
+
43
+ /**
44
+ * Gets the x coordinate
45
+ * @memberof Stereographic.prototype
46
+ * @type {number}
47
+ */
48
+ x: {
49
+ get: function () {
50
+ return this.position.x;
51
+ },
52
+ },
53
+
54
+ /**
55
+ * Gets the y coordinate
56
+ * @memberof Stereographic.prototype
57
+ * @type {number}
58
+ */
59
+ y: {
60
+ get: function () {
61
+ return this.position.y;
62
+ },
63
+ },
64
+
65
+ /**
66
+ * Computes the conformal latitude, or the ellipsoidal latitude projected onto an arbitrary sphere.
67
+ * @memberof Stereographic.prototype
68
+ * @type {number}
69
+ */
70
+ conformalLatitude: {
71
+ get: function () {
72
+ const r = Cartesian2.magnitude(this.position);
73
+ const d = 2 * this.ellipsoid.maximumRadius;
74
+ const sign = this.tangentPlane.plane.normal.z;
75
+ return sign * (CesiumMath.PI_OVER_TWO - 2 * Math.atan2(r, d));
76
+ },
77
+ },
78
+
79
+ /**
80
+ * Computes the longitude
81
+ * @memberof Stereographic.prototype
82
+ * @type {number}
83
+ */
84
+ longitude: {
85
+ get: function () {
86
+ let longitude = CesiumMath.PI_OVER_TWO + Math.atan2(this.y, this.x);
87
+ if (longitude > Math.PI) {
88
+ longitude -= CesiumMath.TWO_PI;
89
+ }
90
+
91
+ return longitude;
92
+ },
93
+ },
94
+ });
95
+
96
+ const scratchCartographic = new Cartographic();
97
+ const scratchCartesian = new Cartesian3();
98
+
99
+ /**
100
+ * Computes the latitude based on an ellipsoid.
101
+ *
102
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which to compute the longitude.
103
+ * @returns {number} The latitude
104
+ */
105
+ Stereographic.prototype.getLatitude = function (ellipsoid) {
106
+ if (!defined(ellipsoid)) {
107
+ ellipsoid = Ellipsoid.WGS84;
108
+ }
109
+
110
+ scratchCartographic.latitude = this.conformalLatitude;
111
+ scratchCartographic.longitude = this.longitude;
112
+ scratchCartographic.height = 0.0;
113
+ const cartesian = this.ellipsoid.cartographicToCartesian(
114
+ scratchCartographic,
115
+ scratchCartesian
116
+ );
117
+ ellipsoid.cartesianToCartographic(cartesian, scratchCartographic);
118
+ return scratchCartographic.latitude;
119
+ };
120
+
121
+ const scratchProjectPointOntoPlaneRay = new Ray();
122
+ const scratchProjectPointOntoPlaneRayDirection = new Cartesian3();
123
+ const scratchProjectPointOntoPlaneCartesian3 = new Cartesian3();
124
+
125
+ /**
126
+ * Computes the projection of the provided 3D position onto the 2D polar plane, radially outward from the provided origin.
127
+ *
128
+ * @param {Cartesian3} cartesian The point to project.
129
+ * @param {Stereographic} [result] The object onto which to store the result.
130
+ * @returns {Sterographic} The modified result parameter or a new Sterographic instance if none was provided.
131
+ */
132
+ Stereographic.fromCartesian = function (cartesian, result) {
133
+ //>>includeStart('debug', pragmas.debug);
134
+ Check.defined("cartesian", cartesian);
135
+ //>>includeEnd('debug');
136
+
137
+ const sign = CesiumMath.signNotZero(cartesian.z);
138
+ let tangentPlane = Stereographic.NORTH_POLE_TANGENT_PLANE;
139
+ let origin = Stereographic.SOUTH_POLE;
140
+ if (sign < 0) {
141
+ tangentPlane = Stereographic.SOUTH_POLE_TANGENT_PLANE;
142
+ origin = Stereographic.NORTH_POLE;
143
+ }
144
+
145
+ const ray = scratchProjectPointOntoPlaneRay;
146
+ ray.origin = tangentPlane.ellipsoid.scaleToGeocentricSurface(
147
+ cartesian,
148
+ ray.origin
149
+ );
150
+ ray.direction = Cartesian3.subtract(
151
+ ray.origin,
152
+ origin,
153
+ scratchProjectPointOntoPlaneRayDirection
154
+ );
155
+ Cartesian3.normalize(ray.direction, ray.direction);
156
+
157
+ const intersectionPoint = IntersectionTests.rayPlane(
158
+ ray,
159
+ tangentPlane.plane,
160
+ scratchProjectPointOntoPlaneCartesian3
161
+ );
162
+ const v = Cartesian3.subtract(intersectionPoint, origin, intersectionPoint);
163
+ const x = Cartesian3.dot(tangentPlane.xAxis, v);
164
+ const y = sign * Cartesian3.dot(tangentPlane.yAxis, v);
165
+
166
+ if (!defined(result)) {
167
+ return new Stereographic(new Cartesian2(x, y), tangentPlane);
168
+ }
169
+
170
+ result.position = new Cartesian2(x, y);
171
+ result.tangentPlane = tangentPlane;
172
+ return result;
173
+ };
174
+
175
+ /**
176
+ * Computes the projection of the provided 3D positions onto the 2D polar plane, radially outward from the provided origin.
177
+ *
178
+ * @param {Cartesian3[]} cartesians The points to project.
179
+ * @param {Stereographic[]} [result] The object onto which to store the result.
180
+ * @returns {Sterographic[]} The modified result parameter or a new Sterographic instance if none was provided.
181
+ */
182
+ Stereographic.fromCartesianArray = function (cartesians, result) {
183
+ //>>includeStart('debug', pragmas.debug);
184
+ Check.defined("cartesians", cartesians);
185
+ //>>includeEnd('debug');
186
+
187
+ const length = cartesians.length;
188
+ if (!defined(result)) {
189
+ result = new Array(length);
190
+ } else {
191
+ result.length = length;
192
+ }
193
+ for (let i = 0; i < length; i++) {
194
+ result[i] = Stereographic.fromCartesian(cartesians[i], result[i]);
195
+ }
196
+ return result;
197
+ };
198
+
199
+ /**
200
+ * Duplicates a Stereographic instance.
201
+ *
202
+ * @param {Stereographic} stereographic The Stereographic to duplicate.
203
+ * @param {Stereographic} [result] The object onto which to store the result.
204
+ * @returns {Stereographic} The modified result parameter or a new Stereographic instance if one was not provided. (Returns undefined if stereographic is undefined)
205
+ */
206
+ Stereographic.clone = function (stereographic, result) {
207
+ if (!defined(stereographic)) {
208
+ return undefined;
209
+ }
210
+ if (!defined(result)) {
211
+ return new Stereographic(
212
+ stereographic.position,
213
+ stereographic.tangentPlane
214
+ );
215
+ }
216
+
217
+ result.position = stereographic.position;
218
+ result.tangentPlane = stereographic.tangentPlane;
219
+
220
+ return result;
221
+ };
222
+
223
+ /**
224
+ * An Ellipsoid instance initialized to radii of (0.5, 0.5, 0.5).
225
+ *
226
+ * @type {Stereographic}
227
+ * @constant
228
+ */
229
+ Stereographic.HALF_UNIT_SPHERE = Object.freeze(new Ellipsoid(0.5, 0.5, 0.5));
230
+
231
+ Stereographic.NORTH_POLE = Object.freeze(new Cartesian3(0.0, 0.0, 0.5));
232
+ Stereographic.SOUTH_POLE = Object.freeze(new Cartesian3(0.0, 0.0, -0.5));
233
+
234
+ Stereographic.NORTH_POLE_TANGENT_PLANE = Object.freeze(
235
+ new EllipsoidTangentPlane(
236
+ Stereographic.NORTH_POLE,
237
+ Stereographic.HALF_UNIT_SPHERE
238
+ )
239
+ );
240
+ Stereographic.SOUTH_POLE_TANGENT_PLANE = Object.freeze(
241
+ new EllipsoidTangentPlane(
242
+ Stereographic.SOUTH_POLE,
243
+ Stereographic.HALF_UNIT_SPHERE
244
+ )
245
+ );
246
+
247
+ export default Stereographic;
@@ -12,9 +12,7 @@ import RuntimeError from "./RuntimeError.js";
12
12
 
13
13
  function canTransferArrayBuffer() {
14
14
  if (!defined(TaskProcessor._canTransferArrayBuffer)) {
15
- const worker = new Worker(
16
- getWorkerUrl("Workers/transferTypedArrayTest.js")
17
- );
15
+ const worker = createWorker("transferTypedArrayTest");
18
16
  worker.postMessage = defaultValue(
19
17
  worker.webkitPostMessage,
20
18
  worker.postMessage
@@ -59,55 +57,70 @@ function canTransferArrayBuffer() {
59
57
 
60
58
  const taskCompletedEvent = new Event();
61
59
 
62
- function getWorkerUrl(moduleID) {
63
- let url = buildModuleUrl(moduleID);
60
+ function urlFromScript(script) {
61
+ let blob;
62
+ try {
63
+ blob = new Blob([script], {
64
+ type: "application/javascript",
65
+ });
66
+ } catch (e) {
67
+ const BlobBuilder =
68
+ window.BlobBuilder ||
69
+ window.WebKitBlobBuilder ||
70
+ window.MozBlobBuilder ||
71
+ window.MSBlobBuilder;
72
+ const blobBuilder = new BlobBuilder();
73
+ blobBuilder.append(script);
74
+ blob = blobBuilder.getBlob("application/javascript");
75
+ }
76
+
77
+ const URL = window.URL || window.webkitURL;
78
+ return URL.createObjectURL(blob);
79
+ }
80
+
81
+ function createWorker(url) {
82
+ const uri = new Uri(url);
83
+ const isUri = uri.scheme().length !== 0 && uri.fragment().length === 0;
64
84
 
85
+ const options = {};
86
+ let workerPath;
65
87
  if (isCrossOriginUrl(url)) {
66
- //to load cross-origin, create a shim worker from a blob URL
88
+ // To load cross-origin, create a shim worker from a blob URL
67
89
  const script = `importScripts("${url}");`;
90
+ workerPath = urlFromScript(script);
91
+ return new Worker(workerPath, options);
92
+ }
68
93
 
69
- let blob;
70
- try {
71
- blob = new Blob([script], {
72
- type: "application/javascript",
73
- });
74
- } catch (e) {
75
- const BlobBuilder =
76
- window.BlobBuilder ||
77
- window.WebKitBlobBuilder ||
78
- window.MozBlobBuilder ||
79
- window.MSBlobBuilder;
80
- const blobBuilder = new BlobBuilder();
81
- blobBuilder.append(script);
82
- blob = blobBuilder.getBlob("application/javascript");
83
- }
84
-
85
- const URL = window.URL || window.webkitURL;
86
- url = URL.createObjectURL(blob);
94
+ const moduleID = url.replace(/\.js$/, "");
95
+
96
+ /* global CESIUM_WORKERS */
97
+ if (!isUri && typeof CESIUM_WORKERS !== "undefined") {
98
+ // If the workers are embedded, create a shim worker from the embedded script data
99
+ const script = `
100
+ importScripts("${urlFromScript(CESIUM_WORKERS)}");
101
+ CesiumWorkers["${moduleID}"]();
102
+ `;
103
+ workerPath = urlFromScript(script);
104
+ return new Worker(workerPath, options);
87
105
  }
88
106
 
89
- return url;
90
- }
107
+ workerPath = url;
108
+
109
+ if (!isUri) {
110
+ workerPath = buildModuleUrl(
111
+ `${TaskProcessor._workerModulePrefix + moduleID}.js`
112
+ );
113
+ }
91
114
 
92
- function createWorker(processor) {
93
115
  if (!FeatureDetection.supportsEsmWebWorkers()) {
94
116
  throw new RuntimeError(
95
117
  "This browser is not supported. Please update your browser to continue."
96
118
  );
97
119
  }
98
120
 
99
- const uri = new Uri(processor._workerPath);
100
- const isUri = uri.scheme().length !== 0 && uri.fragment().length === 0;
101
- const workerPath = isUri
102
- ? processor._workerPath
103
- : getWorkerUrl(
104
- `${
105
- TaskProcessor._workerModulePrefix +
106
- processor._workerPath.replace(/\.js$/, "")
107
- }.js`
108
- );
121
+ options.type = "module";
109
122
 
110
- return new Worker(workerPath, { type: "module" });
123
+ return new Worker(workerPath, options);
111
124
  }
112
125
 
113
126
  async function getWebAssemblyLoaderConfig(processor, wasmOptions) {
@@ -269,7 +282,7 @@ TaskProcessor.prototype.scheduleTask = function (
269
282
  transferableObjects
270
283
  ) {
271
284
  if (!defined(this._worker)) {
272
- this._worker = createWorker(this);
285
+ this._worker = createWorker(this._workerPath);
273
286
  }
274
287
 
275
288
  if (this._activeTasks >= this._maximumActiveTasks) {
@@ -300,7 +313,7 @@ TaskProcessor.prototype.initWebAssemblyModule = async function (
300
313
  }
301
314
 
302
315
  const init = async () => {
303
- const worker = (this._worker = createWorker(this));
316
+ const worker = (this._worker = createWorker(this._workerPath));
304
317
  const wasmConfig = await getWebAssemblyLoaderConfig(
305
318
  this,
306
319
  webAssemblyOptions