智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151
  1. import ArcType from "../Core/ArcType.js";
  2. import BoundingRectangle from "../Core/BoundingRectangle.js";
  3. import Cartesian2 from "../Core/Cartesian2.js";
  4. import Cartesian3 from "../Core/Cartesian3.js";
  5. import Cartographic from "../Core/Cartographic.js";
  6. import ClockRange from "../Core/ClockRange.js";
  7. import ClockStep from "../Core/ClockStep.js";
  8. import Color from "../Core/Color.js";
  9. import CornerType from "../Core/CornerType.js";
  10. import Credit from "../Core/Credit.js";
  11. import createGuid from "../Core/createGuid.js";
  12. import Frozen from "../Core/Frozen.js";
  13. import defined from "../Core/defined.js";
  14. import DeveloperError from "../Core/DeveloperError.js";
  15. import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
  16. import Ellipsoid from "../Core/Ellipsoid.js";
  17. import Event from "../Core/Event.js";
  18. import ExtrapolationType from "../Core/ExtrapolationType.js";
  19. import getFilenameFromUri from "../Core/getFilenameFromUri.js";
  20. import HermitePolynomialApproximation from "../Core/HermitePolynomialApproximation.js";
  21. import Iso8601 from "../Core/Iso8601.js";
  22. import JulianDate from "../Core/JulianDate.js";
  23. import LagrangePolynomialApproximation from "../Core/LagrangePolynomialApproximation.js";
  24. import LinearApproximation from "../Core/LinearApproximation.js";
  25. import CesiumMath from "../Core/Math.js";
  26. import NearFarScalar from "../Core/NearFarScalar.js";
  27. import PolygonHierarchy from "../Core/PolygonHierarchy.js";
  28. import Quaternion from "../Core/Quaternion.js";
  29. import Rectangle from "../Core/Rectangle.js";
  30. import ReferenceFrame from "../Core/ReferenceFrame.js";
  31. import Resource from "../Core/Resource.js";
  32. import RuntimeError from "../Core/RuntimeError.js";
  33. import Spherical from "../Core/Spherical.js";
  34. import TimeInterval from "../Core/TimeInterval.js";
  35. import TimeIntervalCollection from "../Core/TimeIntervalCollection.js";
  36. import ClassificationType from "../Scene/ClassificationType.js";
  37. import ColorBlendMode from "../Scene/ColorBlendMode.js";
  38. import HeightReference from "../Scene/HeightReference.js";
  39. import HorizontalOrigin from "../Scene/HorizontalOrigin.js";
  40. import LabelStyle from "../Scene/LabelStyle.js";
  41. import ShadowMode from "../Scene/ShadowMode.js";
  42. import VerticalOrigin from "../Scene/VerticalOrigin.js";
  43. import Uri from "urijs";
  44. import BillboardGraphics from "./BillboardGraphics.js";
  45. import BoxGraphics from "./BoxGraphics.js";
  46. import CallbackProperty from "./CallbackProperty.js";
  47. import CheckerboardMaterialProperty from "./CheckerboardMaterialProperty.js";
  48. import ColorMaterialProperty from "./ColorMaterialProperty.js";
  49. import CompositeMaterialProperty from "./CompositeMaterialProperty.js";
  50. import CompositePositionProperty from "./CompositePositionProperty.js";
  51. import CompositeProperty from "./CompositeProperty.js";
  52. import ConstantPositionProperty from "./ConstantPositionProperty.js";
  53. import ConstantProperty from "./ConstantProperty.js";
  54. import CorridorGraphics from "./CorridorGraphics.js";
  55. import CylinderGraphics from "./CylinderGraphics.js";
  56. import DataSource from "./DataSource.js";
  57. import DataSourceClock from "./DataSourceClock.js";
  58. import EllipseGraphics from "./EllipseGraphics.js";
  59. import EllipsoidGraphics from "./EllipsoidGraphics.js";
  60. import EntityCluster from "./EntityCluster.js";
  61. import EntityCollection from "./EntityCollection.js";
  62. import GridMaterialProperty from "./GridMaterialProperty.js";
  63. import ImageMaterialProperty from "./ImageMaterialProperty.js";
  64. import LabelGraphics from "./LabelGraphics.js";
  65. import ModelGraphics from "./ModelGraphics.js";
  66. import NodeTransformationProperty from "./NodeTransformationProperty.js";
  67. import PathGraphics from "./PathGraphics.js";
  68. import PointGraphics from "./PointGraphics.js";
  69. import PolygonGraphics from "./PolygonGraphics.js";
  70. import PolylineArrowMaterialProperty from "./PolylineArrowMaterialProperty.js";
  71. import PolylineDashMaterialProperty from "./PolylineDashMaterialProperty.js";
  72. import PolylineGlowMaterialProperty from "./PolylineGlowMaterialProperty.js";
  73. import PolylineGraphics from "./PolylineGraphics.js";
  74. import PolylineOutlineMaterialProperty from "./PolylineOutlineMaterialProperty.js";
  75. import PolylineVolumeGraphics from "./PolylineVolumeGraphics.js";
  76. import PositionPropertyArray from "./PositionPropertyArray.js";
  77. import Property from "./Property.js";
  78. import PropertyArray from "./PropertyArray.js";
  79. import PropertyBag from "./PropertyBag.js";
  80. import RectangleGraphics from "./RectangleGraphics.js";
  81. import ReferenceProperty from "./ReferenceProperty.js";
  82. import Rotation from "./Rotation.js";
  83. import SampledPositionProperty from "./SampledPositionProperty.js";
  84. import SampledProperty from "./SampledProperty.js";
  85. import StripeMaterialProperty from "./StripeMaterialProperty.js";
  86. import StripeOrientation from "./StripeOrientation.js";
  87. import TimeIntervalCollectionPositionProperty from "./TimeIntervalCollectionPositionProperty.js";
  88. import TimeIntervalCollectionProperty from "./TimeIntervalCollectionProperty.js";
  89. import VelocityOrientationProperty from "./VelocityOrientationProperty.js";
  90. import VelocityVectorProperty from "./VelocityVectorProperty.js";
  91. import WallGraphics from "./WallGraphics.js";
  92. import Cesium3DTilesetGraphics from "./Cesium3DTilesetGraphics.js";
  93. import SensorVolumePortionToDisplay from "../Scene/SensorVolumePortionToDisplay.js";
  94. // A marker type to distinguish CZML properties where we need to end up with a unit vector.
  95. // The data is still loaded into Cartesian3 objects but they are normalized.
  96. function UnitCartesian3() {}
  97. UnitCartesian3.packedLength = Cartesian3.packedLength;
  98. UnitCartesian3.unpack = Cartesian3.unpack;
  99. UnitCartesian3.pack = Cartesian3.pack;
  100. // As a side note, for the purposes of CZML, Quaternion always indicates a unit quaternion.
  101. let currentId;
  102. function createReferenceProperty(entityCollection, referenceString) {
  103. if (referenceString[0] === "#") {
  104. referenceString = currentId + referenceString;
  105. }
  106. return ReferenceProperty.fromString(entityCollection, referenceString);
  107. }
  108. function createSpecializedProperty(type, entityCollection, packetData) {
  109. if (defined(packetData.reference)) {
  110. return createReferenceProperty(entityCollection, packetData.reference);
  111. }
  112. if (defined(packetData.velocityReference)) {
  113. const referenceProperty = createReferenceProperty(
  114. entityCollection,
  115. packetData.velocityReference,
  116. );
  117. switch (type) {
  118. case Cartesian3:
  119. case UnitCartesian3:
  120. return new VelocityVectorProperty(
  121. referenceProperty,
  122. type === UnitCartesian3,
  123. );
  124. case Quaternion:
  125. return new VelocityOrientationProperty(referenceProperty);
  126. }
  127. }
  128. throw new RuntimeError(`${JSON.stringify(packetData)} is not valid CZML.`);
  129. }
  130. function createAdapterProperty(property, adapterFunction) {
  131. return new CallbackProperty(function (time, result) {
  132. return adapterFunction(property.getValue(time, result));
  133. }, property.isConstant);
  134. }
  135. const scratchCartesian = new Cartesian3();
  136. const scratchSpherical = new Spherical();
  137. const scratchCartographic = new Cartographic();
  138. const scratchTimeInterval = new TimeInterval();
  139. const scratchQuaternion = new Quaternion();
  140. function unwrapColorInterval(czmlInterval) {
  141. let rgbaf = czmlInterval.rgbaf;
  142. if (defined(rgbaf)) {
  143. return rgbaf;
  144. }
  145. const rgba = czmlInterval.rgba;
  146. if (!defined(rgba)) {
  147. return undefined;
  148. }
  149. const length = rgba.length;
  150. if (length === Color.packedLength) {
  151. return [
  152. Color.byteToFloat(rgba[0]),
  153. Color.byteToFloat(rgba[1]),
  154. Color.byteToFloat(rgba[2]),
  155. Color.byteToFloat(rgba[3]),
  156. ];
  157. }
  158. rgbaf = new Array(length);
  159. for (let i = 0; i < length; i += 5) {
  160. rgbaf[i] = rgba[i];
  161. rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]);
  162. rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]);
  163. rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]);
  164. rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]);
  165. }
  166. return rgbaf;
  167. }
  168. function unwrapUriInterval(czmlInterval, sourceUri) {
  169. const uri = czmlInterval.uri ?? czmlInterval;
  170. if (defined(sourceUri)) {
  171. return sourceUri.getDerivedResource({
  172. url: uri,
  173. });
  174. }
  175. return Resource.createIfNeeded(uri);
  176. }
  177. function unwrapRectangleInterval(czmlInterval) {
  178. let wsen = czmlInterval.wsen;
  179. if (defined(wsen)) {
  180. return wsen;
  181. }
  182. const wsenDegrees = czmlInterval.wsenDegrees;
  183. if (!defined(wsenDegrees)) {
  184. return undefined;
  185. }
  186. const length = wsenDegrees.length;
  187. if (length === Rectangle.packedLength) {
  188. return [
  189. CesiumMath.toRadians(wsenDegrees[0]),
  190. CesiumMath.toRadians(wsenDegrees[1]),
  191. CesiumMath.toRadians(wsenDegrees[2]),
  192. CesiumMath.toRadians(wsenDegrees[3]),
  193. ];
  194. }
  195. wsen = new Array(length);
  196. for (let i = 0; i < length; i += 5) {
  197. wsen[i] = wsenDegrees[i];
  198. wsen[i + 1] = CesiumMath.toRadians(wsenDegrees[i + 1]);
  199. wsen[i + 2] = CesiumMath.toRadians(wsenDegrees[i + 2]);
  200. wsen[i + 3] = CesiumMath.toRadians(wsenDegrees[i + 3]);
  201. wsen[i + 4] = CesiumMath.toRadians(wsenDegrees[i + 4]);
  202. }
  203. return wsen;
  204. }
  205. function convertUnitSphericalToCartesian(unitSpherical) {
  206. const length = unitSpherical.length;
  207. scratchSpherical.magnitude = 1.0;
  208. if (length === 2) {
  209. scratchSpherical.clock = unitSpherical[0];
  210. scratchSpherical.cone = unitSpherical[1];
  211. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  212. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  213. }
  214. const result = new Array((length / 3) * 4);
  215. for (let i = 0, j = 0; i < length; i += 3, j += 4) {
  216. result[j] = unitSpherical[i];
  217. scratchSpherical.clock = unitSpherical[i + 1];
  218. scratchSpherical.cone = unitSpherical[i + 2];
  219. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  220. result[j + 1] = scratchCartesian.x;
  221. result[j + 2] = scratchCartesian.y;
  222. result[j + 3] = scratchCartesian.z;
  223. }
  224. return result;
  225. }
  226. function convertSphericalToCartesian(spherical) {
  227. const length = spherical.length;
  228. if (length === 3) {
  229. scratchSpherical.clock = spherical[0];
  230. scratchSpherical.cone = spherical[1];
  231. scratchSpherical.magnitude = spherical[2];
  232. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  233. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  234. }
  235. const result = new Array(length);
  236. for (let i = 0; i < length; i += 4) {
  237. result[i] = spherical[i];
  238. scratchSpherical.clock = spherical[i + 1];
  239. scratchSpherical.cone = spherical[i + 2];
  240. scratchSpherical.magnitude = spherical[i + 3];
  241. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  242. result[i + 1] = scratchCartesian.x;
  243. result[i + 2] = scratchCartesian.y;
  244. result[i + 3] = scratchCartesian.z;
  245. }
  246. return result;
  247. }
  248. function convertCartographicRadiansToCartesian(cartographicRadians) {
  249. const length = cartographicRadians.length;
  250. if (length === 3) {
  251. scratchCartographic.longitude = cartographicRadians[0];
  252. scratchCartographic.latitude = cartographicRadians[1];
  253. scratchCartographic.height = cartographicRadians[2];
  254. Ellipsoid.default.cartographicToCartesian(
  255. scratchCartographic,
  256. scratchCartesian,
  257. );
  258. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  259. }
  260. const result = new Array(length);
  261. for (let i = 0; i < length; i += 4) {
  262. result[i] = cartographicRadians[i];
  263. scratchCartographic.longitude = cartographicRadians[i + 1];
  264. scratchCartographic.latitude = cartographicRadians[i + 2];
  265. scratchCartographic.height = cartographicRadians[i + 3];
  266. Ellipsoid.default.cartographicToCartesian(
  267. scratchCartographic,
  268. scratchCartesian,
  269. );
  270. result[i + 1] = scratchCartesian.x;
  271. result[i + 2] = scratchCartesian.y;
  272. result[i + 3] = scratchCartesian.z;
  273. }
  274. return result;
  275. }
  276. function convertCartographicDegreesToCartesian(cartographicDegrees) {
  277. const length = cartographicDegrees.length;
  278. if (length === 3) {
  279. scratchCartographic.longitude = CesiumMath.toRadians(
  280. cartographicDegrees[0],
  281. );
  282. scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]);
  283. scratchCartographic.height = cartographicDegrees[2];
  284. Ellipsoid.default.cartographicToCartesian(
  285. scratchCartographic,
  286. scratchCartesian,
  287. );
  288. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  289. }
  290. const result = new Array(length);
  291. for (let i = 0; i < length; i += 4) {
  292. result[i] = cartographicDegrees[i];
  293. scratchCartographic.longitude = CesiumMath.toRadians(
  294. cartographicDegrees[i + 1],
  295. );
  296. scratchCartographic.latitude = CesiumMath.toRadians(
  297. cartographicDegrees[i + 2],
  298. );
  299. scratchCartographic.height = cartographicDegrees[i + 3];
  300. Ellipsoid.default.cartographicToCartesian(
  301. scratchCartographic,
  302. scratchCartesian,
  303. );
  304. result[i + 1] = scratchCartesian.x;
  305. result[i + 2] = scratchCartesian.y;
  306. result[i + 3] = scratchCartesian.z;
  307. }
  308. return result;
  309. }
  310. function unwrapCartesianInterval(czmlInterval) {
  311. const cartesian = czmlInterval.cartesian;
  312. if (defined(cartesian)) {
  313. return cartesian;
  314. }
  315. const cartesianVelocity = czmlInterval.cartesianVelocity;
  316. if (defined(cartesianVelocity)) {
  317. return cartesianVelocity;
  318. }
  319. const unitCartesian = czmlInterval.unitCartesian;
  320. if (defined(unitCartesian)) {
  321. return unitCartesian;
  322. }
  323. const unitSpherical = czmlInterval.unitSpherical;
  324. if (defined(unitSpherical)) {
  325. return convertUnitSphericalToCartesian(unitSpherical);
  326. }
  327. const spherical = czmlInterval.spherical;
  328. if (defined(spherical)) {
  329. return convertSphericalToCartesian(spherical);
  330. }
  331. const cartographicRadians = czmlInterval.cartographicRadians;
  332. if (defined(cartographicRadians)) {
  333. return convertCartographicRadiansToCartesian(cartographicRadians);
  334. }
  335. const cartographicDegrees = czmlInterval.cartographicDegrees;
  336. if (defined(cartographicDegrees)) {
  337. return convertCartographicDegreesToCartesian(cartographicDegrees);
  338. }
  339. throw new RuntimeError(
  340. `${JSON.stringify(czmlInterval)} is not a valid CZML interval.`,
  341. );
  342. }
  343. function normalizePackedCartesianArray(array, startingIndex) {
  344. Cartesian3.unpack(array, startingIndex, scratchCartesian);
  345. Cartesian3.normalize(scratchCartesian, scratchCartesian);
  346. Cartesian3.pack(scratchCartesian, array, startingIndex);
  347. }
  348. function unwrapUnitCartesianInterval(czmlInterval) {
  349. const cartesian = unwrapCartesianInterval(czmlInterval);
  350. if (cartesian.length === 3) {
  351. normalizePackedCartesianArray(cartesian, 0);
  352. return cartesian;
  353. }
  354. for (let i = 1; i < cartesian.length; i += 4) {
  355. normalizePackedCartesianArray(cartesian, i);
  356. }
  357. return cartesian;
  358. }
  359. function normalizePackedQuaternionArray(array, startingIndex) {
  360. Quaternion.unpack(array, startingIndex, scratchQuaternion);
  361. Quaternion.normalize(scratchQuaternion, scratchQuaternion);
  362. Quaternion.pack(scratchQuaternion, array, startingIndex);
  363. }
  364. function unwrapQuaternionInterval(czmlInterval) {
  365. const unitQuaternion = czmlInterval.unitQuaternion;
  366. if (defined(unitQuaternion)) {
  367. if (unitQuaternion.length === 4) {
  368. normalizePackedQuaternionArray(unitQuaternion, 0);
  369. return unitQuaternion;
  370. }
  371. for (let i = 1; i < unitQuaternion.length; i += 5) {
  372. normalizePackedQuaternionArray(unitQuaternion, i);
  373. }
  374. }
  375. return unitQuaternion;
  376. }
  377. function getPropertyType(czmlInterval) {
  378. // The associations in this function need to be kept in sync with the
  379. // associations in unwrapInterval.
  380. // Intentionally omitted due to conficts in CZML property names:
  381. // * Image (conflicts with Uri)
  382. // * Rotation (conflicts with Number)
  383. //
  384. // cartesianVelocity is also omitted due to incomplete support for
  385. // derivative information in CZML properties.
  386. // (Currently cartesianVelocity is hacked directly into the position processing code)
  387. if (typeof czmlInterval === "boolean") {
  388. return Boolean;
  389. } else if (typeof czmlInterval === "number") {
  390. return Number;
  391. } else if (typeof czmlInterval === "string") {
  392. return String;
  393. } else if (czmlInterval.hasOwnProperty("array")) {
  394. return Array;
  395. } else if (czmlInterval.hasOwnProperty("boolean")) {
  396. return Boolean;
  397. } else if (czmlInterval.hasOwnProperty("boundingRectangle")) {
  398. return BoundingRectangle;
  399. } else if (czmlInterval.hasOwnProperty("cartesian2")) {
  400. return Cartesian2;
  401. } else if (
  402. czmlInterval.hasOwnProperty("cartesian") ||
  403. czmlInterval.hasOwnProperty("spherical") ||
  404. czmlInterval.hasOwnProperty("cartographicRadians") ||
  405. czmlInterval.hasOwnProperty("cartographicDegrees")
  406. ) {
  407. return Cartesian3;
  408. } else if (
  409. czmlInterval.hasOwnProperty("unitCartesian") ||
  410. czmlInterval.hasOwnProperty("unitSpherical")
  411. ) {
  412. return UnitCartesian3;
  413. } else if (
  414. czmlInterval.hasOwnProperty("rgba") ||
  415. czmlInterval.hasOwnProperty("rgbaf")
  416. ) {
  417. return Color;
  418. } else if (czmlInterval.hasOwnProperty("arcType")) {
  419. return ArcType;
  420. } else if (czmlInterval.hasOwnProperty("classificationType")) {
  421. return ClassificationType;
  422. } else if (czmlInterval.hasOwnProperty("colorBlendMode")) {
  423. return ColorBlendMode;
  424. } else if (czmlInterval.hasOwnProperty("cornerType")) {
  425. return CornerType;
  426. } else if (czmlInterval.hasOwnProperty("heightReference")) {
  427. return HeightReference;
  428. } else if (czmlInterval.hasOwnProperty("horizontalOrigin")) {
  429. return HorizontalOrigin;
  430. } else if (czmlInterval.hasOwnProperty("date")) {
  431. return JulianDate;
  432. } else if (czmlInterval.hasOwnProperty("labelStyle")) {
  433. return LabelStyle;
  434. } else if (czmlInterval.hasOwnProperty("number")) {
  435. return Number;
  436. } else if (czmlInterval.hasOwnProperty("nearFarScalar")) {
  437. return NearFarScalar;
  438. } else if (czmlInterval.hasOwnProperty("distanceDisplayCondition")) {
  439. return DistanceDisplayCondition;
  440. } else if (
  441. czmlInterval.hasOwnProperty("object") ||
  442. czmlInterval.hasOwnProperty("value")
  443. ) {
  444. return Object;
  445. } else if (czmlInterval.hasOwnProperty("unitQuaternion")) {
  446. return Quaternion;
  447. } else if (czmlInterval.hasOwnProperty("shadowMode")) {
  448. return ShadowMode;
  449. } else if (czmlInterval.hasOwnProperty("string")) {
  450. return String;
  451. } else if (czmlInterval.hasOwnProperty("stripeOrientation")) {
  452. return StripeOrientation;
  453. } else if (
  454. czmlInterval.hasOwnProperty("wsen") ||
  455. czmlInterval.hasOwnProperty("wsenDegrees")
  456. ) {
  457. return Rectangle;
  458. } else if (czmlInterval.hasOwnProperty("uri")) {
  459. return Uri;
  460. } else if (czmlInterval.hasOwnProperty("verticalOrigin")) {
  461. return VerticalOrigin;
  462. }
  463. // fallback case
  464. return Object;
  465. }
  466. function unwrapInterval(type, czmlInterval, sourceUri) {
  467. // The associations in this function need to be kept in sync with the
  468. // associations in getPropertyType
  469. switch (type) {
  470. case ArcType:
  471. return ArcType[czmlInterval.arcType ?? czmlInterval];
  472. case Array:
  473. return czmlInterval.array;
  474. case Boolean:
  475. return czmlInterval["boolean"] ?? czmlInterval;
  476. case BoundingRectangle:
  477. return czmlInterval.boundingRectangle;
  478. case Cartesian2:
  479. return czmlInterval.cartesian2;
  480. case Cartesian3:
  481. return unwrapCartesianInterval(czmlInterval);
  482. case UnitCartesian3:
  483. return unwrapUnitCartesianInterval(czmlInterval);
  484. case Color:
  485. return unwrapColorInterval(czmlInterval);
  486. case ClassificationType:
  487. return ClassificationType[
  488. czmlInterval.classificationType ?? czmlInterval
  489. ];
  490. case ColorBlendMode:
  491. return ColorBlendMode[czmlInterval.colorBlendMode ?? czmlInterval];
  492. case CornerType:
  493. return CornerType[czmlInterval.cornerType ?? czmlInterval];
  494. case HeightReference:
  495. return HeightReference[czmlInterval.heightReference ?? czmlInterval];
  496. case HorizontalOrigin:
  497. return HorizontalOrigin[czmlInterval.horizontalOrigin ?? czmlInterval];
  498. case Image:
  499. return unwrapUriInterval(czmlInterval, sourceUri);
  500. case JulianDate:
  501. return JulianDate.fromIso8601(czmlInterval.date ?? czmlInterval);
  502. case LabelStyle:
  503. return LabelStyle[czmlInterval.labelStyle ?? czmlInterval];
  504. case Number:
  505. return czmlInterval.number ?? czmlInterval;
  506. case NearFarScalar:
  507. return czmlInterval.nearFarScalar;
  508. case DistanceDisplayCondition:
  509. return czmlInterval.distanceDisplayCondition;
  510. case Object:
  511. return czmlInterval.object ?? czmlInterval.value ?? czmlInterval;
  512. case Quaternion:
  513. return unwrapQuaternionInterval(czmlInterval);
  514. case Rotation:
  515. return czmlInterval.number ?? czmlInterval;
  516. case SensorVolumePortionToDisplay:
  517. return SensorVolumePortionToDisplay[
  518. czmlInterval.portionToDisplay ?? czmlInterval
  519. ];
  520. case ShadowMode:
  521. return ShadowMode[
  522. czmlInterval.shadowMode ?? czmlInterval.shadows ?? czmlInterval
  523. ];
  524. case String:
  525. return czmlInterval.string ?? czmlInterval;
  526. case StripeOrientation:
  527. return StripeOrientation[czmlInterval.stripeOrientation ?? czmlInterval];
  528. case Rectangle:
  529. return unwrapRectangleInterval(czmlInterval);
  530. case Uri:
  531. return unwrapUriInterval(czmlInterval, sourceUri);
  532. case VerticalOrigin:
  533. return VerticalOrigin[czmlInterval.verticalOrigin ?? czmlInterval];
  534. default:
  535. throw new RuntimeError(`Unknown CzmlDataSource interval type: ${type}`);
  536. }
  537. }
  538. const interpolators = {
  539. HERMITE: HermitePolynomialApproximation,
  540. LAGRANGE: LagrangePolynomialApproximation,
  541. LINEAR: LinearApproximation,
  542. };
  543. function updateInterpolationSettings(packetData, property) {
  544. const interpolationAlgorithm = packetData.interpolationAlgorithm;
  545. const interpolationDegree = packetData.interpolationDegree;
  546. if (defined(interpolationAlgorithm) || defined(interpolationDegree)) {
  547. property.setInterpolationOptions({
  548. interpolationAlgorithm: interpolators[interpolationAlgorithm],
  549. interpolationDegree: interpolationDegree,
  550. });
  551. }
  552. const forwardExtrapolationType = packetData.forwardExtrapolationType;
  553. if (defined(forwardExtrapolationType)) {
  554. property.forwardExtrapolationType =
  555. ExtrapolationType[forwardExtrapolationType];
  556. }
  557. const forwardExtrapolationDuration = packetData.forwardExtrapolationDuration;
  558. if (defined(forwardExtrapolationDuration)) {
  559. property.forwardExtrapolationDuration = forwardExtrapolationDuration;
  560. }
  561. const backwardExtrapolationType = packetData.backwardExtrapolationType;
  562. if (defined(backwardExtrapolationType)) {
  563. property.backwardExtrapolationType =
  564. ExtrapolationType[backwardExtrapolationType];
  565. }
  566. const backwardExtrapolationDuration =
  567. packetData.backwardExtrapolationDuration;
  568. if (defined(backwardExtrapolationDuration)) {
  569. property.backwardExtrapolationDuration = backwardExtrapolationDuration;
  570. }
  571. }
  572. const iso8601Scratch = {
  573. iso8601: undefined,
  574. };
  575. function intervalFromString(intervalString) {
  576. if (!defined(intervalString)) {
  577. return undefined;
  578. }
  579. iso8601Scratch.iso8601 = intervalString;
  580. return TimeInterval.fromIso8601(iso8601Scratch);
  581. }
  582. function wrapPropertyInInfiniteInterval(property) {
  583. const interval = Iso8601.MAXIMUM_INTERVAL.clone();
  584. interval.data = property;
  585. return interval;
  586. }
  587. function convertPropertyToComposite(property) {
  588. // Create the composite and add the old property, wrapped in an infinite interval.
  589. const composite = new CompositeProperty();
  590. composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
  591. return composite;
  592. }
  593. function convertPositionPropertyToComposite(property) {
  594. // Create the composite and add the old property, wrapped in an infinite interval.
  595. const composite = new CompositePositionProperty(property.referenceFrame);
  596. composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
  597. return composite;
  598. }
  599. function processProperty(
  600. type,
  601. object,
  602. propertyName,
  603. packetData,
  604. constrainedInterval,
  605. sourceUri,
  606. entityCollection,
  607. ) {
  608. let combinedInterval = intervalFromString(packetData.interval);
  609. if (defined(constrainedInterval)) {
  610. if (defined(combinedInterval)) {
  611. combinedInterval = TimeInterval.intersect(
  612. combinedInterval,
  613. constrainedInterval,
  614. scratchTimeInterval,
  615. );
  616. } else {
  617. combinedInterval = constrainedInterval;
  618. }
  619. }
  620. let packedLength;
  621. let unwrappedInterval;
  622. let unwrappedIntervalLength;
  623. // CZML properties can be defined in many ways. Most ways represent a structure for
  624. // encoding a single value (number, string, cartesian, etc.) Regardless of the value type,
  625. // if it encodes a single value it will get loaded into a ConstantProperty eventually.
  626. // Alternatively, there are ways of defining a property that require specialized
  627. // client-side representation. Currently, these are ReferenceProperty,
  628. // and client-side velocity computation properties such as VelocityVectorProperty.
  629. const isValue =
  630. !defined(packetData.reference) && !defined(packetData.velocityReference);
  631. const hasInterval =
  632. defined(combinedInterval) &&
  633. !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
  634. if (packetData.delete === true) {
  635. // If deleting this property for all time, we can simply set to undefined and return.
  636. if (!hasInterval) {
  637. object[propertyName] = undefined;
  638. return;
  639. }
  640. // Deleting depends on the type of property we have.
  641. return removePropertyData(object[propertyName], combinedInterval);
  642. }
  643. let isSampled = false;
  644. if (isValue) {
  645. unwrappedInterval = unwrapInterval(type, packetData, sourceUri);
  646. if (!defined(unwrappedInterval)) {
  647. // not a known value type, bail
  648. return;
  649. }
  650. packedLength = type.packedLength ?? 1;
  651. unwrappedIntervalLength = unwrappedInterval.length ?? 1;
  652. isSampled =
  653. !defined(packetData.array) &&
  654. typeof unwrappedInterval !== "string" &&
  655. unwrappedIntervalLength > packedLength &&
  656. type !== Object;
  657. }
  658. // Rotation is a special case because it represents a native type (Number)
  659. // and therefore does not need to be unpacked when loaded as a constant value.
  660. const needsUnpacking = typeof type.unpack === "function" && type !== Rotation;
  661. // Any time a constant value is assigned, it completely blows away anything else.
  662. if (!isSampled && !hasInterval) {
  663. if (isValue) {
  664. object[propertyName] = new ConstantProperty(
  665. needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval,
  666. );
  667. } else {
  668. object[propertyName] = createSpecializedProperty(
  669. type,
  670. entityCollection,
  671. packetData,
  672. );
  673. }
  674. return;
  675. }
  676. let property = object[propertyName];
  677. let epoch;
  678. const packetEpoch = packetData.epoch;
  679. if (defined(packetEpoch)) {
  680. epoch = JulianDate.fromIso8601(packetEpoch);
  681. }
  682. // Without an interval, any sampled value is infinite, meaning it completely
  683. // replaces any non-sampled property that may exist.
  684. if (isSampled && !hasInterval) {
  685. if (!(property instanceof SampledProperty)) {
  686. object[propertyName] = property = new SampledProperty(type);
  687. }
  688. property.addSamplesPackedArray(unwrappedInterval, epoch);
  689. updateInterpolationSettings(packetData, property);
  690. return;
  691. }
  692. let interval;
  693. // A constant value with an interval is normally part of a TimeIntervalCollection,
  694. // However, if the current property is not a time-interval collection, we need
  695. // to turn it into a Composite, preserving the old data with the new interval.
  696. if (!isSampled && hasInterval) {
  697. // Create a new interval for the constant value.
  698. combinedInterval = combinedInterval.clone();
  699. if (isValue) {
  700. combinedInterval.data = needsUnpacking
  701. ? type.unpack(unwrappedInterval, 0)
  702. : unwrappedInterval;
  703. } else {
  704. combinedInterval.data = createSpecializedProperty(
  705. type,
  706. entityCollection,
  707. packetData,
  708. );
  709. }
  710. // If no property exists, simply use a new interval collection
  711. if (!defined(property)) {
  712. object[propertyName] = property = isValue
  713. ? new TimeIntervalCollectionProperty()
  714. : new CompositeProperty();
  715. }
  716. if (isValue && property instanceof TimeIntervalCollectionProperty) {
  717. // If we created a collection, or it already was one, use it.
  718. property.intervals.addInterval(combinedInterval);
  719. } else if (property instanceof CompositeProperty) {
  720. // If the collection was already a CompositeProperty, use it.
  721. if (isValue) {
  722. combinedInterval.data = new ConstantProperty(combinedInterval.data);
  723. }
  724. property.intervals.addInterval(combinedInterval);
  725. } else {
  726. // Otherwise, create a CompositeProperty but preserve the existing data.
  727. object[propertyName] = property = convertPropertyToComposite(property);
  728. // Change the new data to a ConstantProperty and add it.
  729. if (isValue) {
  730. combinedInterval.data = new ConstantProperty(combinedInterval.data);
  731. }
  732. property.intervals.addInterval(combinedInterval);
  733. }
  734. return;
  735. }
  736. // isSampled && hasInterval
  737. if (!defined(property)) {
  738. object[propertyName] = property = new CompositeProperty();
  739. }
  740. // Create a CompositeProperty but preserve the existing data.
  741. if (!(property instanceof CompositeProperty)) {
  742. object[propertyName] = property = convertPropertyToComposite(property);
  743. }
  744. // Check if the interval already exists in the composite.
  745. const intervals = property.intervals;
  746. interval = intervals.findInterval(combinedInterval);
  747. if (!defined(interval) || !(interval.data instanceof SampledProperty)) {
  748. // If not, create a SampledProperty for it.
  749. interval = combinedInterval.clone();
  750. interval.data = new SampledProperty(type);
  751. intervals.addInterval(interval);
  752. }
  753. interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
  754. updateInterpolationSettings(packetData, interval.data);
  755. }
  756. function removePropertyData(property, interval) {
  757. if (property instanceof SampledProperty) {
  758. property.removeSamples(interval);
  759. return;
  760. } else if (property instanceof TimeIntervalCollectionProperty) {
  761. property.intervals.removeInterval(interval);
  762. return;
  763. } else if (property instanceof CompositeProperty) {
  764. const intervals = property.intervals;
  765. for (let i = 0; i < intervals.length; ++i) {
  766. const intersection = TimeInterval.intersect(
  767. intervals.get(i),
  768. interval,
  769. scratchTimeInterval,
  770. );
  771. if (!intersection.isEmpty) {
  772. // remove data from the contained properties
  773. removePropertyData(intersection.data, interval);
  774. }
  775. }
  776. // remove the intervals from the composite
  777. intervals.removeInterval(interval);
  778. return;
  779. }
  780. }
  781. function processPacketData(
  782. type,
  783. object,
  784. propertyName,
  785. packetData,
  786. interval,
  787. sourceUri,
  788. entityCollection,
  789. ) {
  790. if (!defined(packetData)) {
  791. return;
  792. }
  793. if (Array.isArray(packetData)) {
  794. for (let i = 0, len = packetData.length; i < len; ++i) {
  795. processProperty(
  796. type,
  797. object,
  798. propertyName,
  799. packetData[i],
  800. interval,
  801. sourceUri,
  802. entityCollection,
  803. );
  804. }
  805. } else {
  806. processProperty(
  807. type,
  808. object,
  809. propertyName,
  810. packetData,
  811. interval,
  812. sourceUri,
  813. entityCollection,
  814. );
  815. }
  816. }
  817. function processPositionProperty(
  818. object,
  819. propertyName,
  820. packetData,
  821. constrainedInterval,
  822. sourceUri,
  823. entityCollection,
  824. ) {
  825. let combinedInterval = intervalFromString(packetData.interval);
  826. if (defined(constrainedInterval)) {
  827. if (defined(combinedInterval)) {
  828. combinedInterval = TimeInterval.intersect(
  829. combinedInterval,
  830. constrainedInterval,
  831. scratchTimeInterval,
  832. );
  833. } else {
  834. combinedInterval = constrainedInterval;
  835. }
  836. }
  837. const numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0;
  838. const packedLength = Cartesian3.packedLength * (numberOfDerivatives + 1);
  839. let unwrappedInterval;
  840. let unwrappedIntervalLength;
  841. const isValue = !defined(packetData.reference);
  842. const hasInterval =
  843. defined(combinedInterval) &&
  844. !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
  845. if (packetData.delete === true) {
  846. // If deleting this property for all time, we can simply set to undefined and return.
  847. if (!hasInterval) {
  848. object[propertyName] = undefined;
  849. return;
  850. }
  851. // Deleting depends on the type of property we have.
  852. return removePositionPropertyData(object[propertyName], combinedInterval);
  853. }
  854. let referenceFrame;
  855. let isSampled = false;
  856. if (isValue) {
  857. if (defined(packetData.referenceFrame)) {
  858. referenceFrame = ReferenceFrame[packetData.referenceFrame];
  859. }
  860. referenceFrame = referenceFrame ?? ReferenceFrame.FIXED;
  861. unwrappedInterval = unwrapCartesianInterval(packetData);
  862. unwrappedIntervalLength = unwrappedInterval.length ?? 1;
  863. isSampled = unwrappedIntervalLength > packedLength;
  864. }
  865. // Any time a constant value is assigned, it completely blows away anything else.
  866. if (!isSampled && !hasInterval) {
  867. if (isValue) {
  868. object[propertyName] = new ConstantPositionProperty(
  869. Cartesian3.unpack(unwrappedInterval),
  870. referenceFrame,
  871. );
  872. } else {
  873. object[propertyName] = createReferenceProperty(
  874. entityCollection,
  875. packetData.reference,
  876. );
  877. }
  878. return;
  879. }
  880. let property = object[propertyName];
  881. let epoch;
  882. const packetEpoch = packetData.epoch;
  883. if (defined(packetEpoch)) {
  884. epoch = JulianDate.fromIso8601(packetEpoch);
  885. }
  886. // Without an interval, any sampled value is infinite, meaning it completely
  887. // replaces any non-sampled property that may exist.
  888. if (isSampled && !hasInterval) {
  889. if (
  890. !(property instanceof SampledPositionProperty) ||
  891. (defined(referenceFrame) && property.referenceFrame !== referenceFrame)
  892. ) {
  893. object[propertyName] = property = new SampledPositionProperty(
  894. referenceFrame,
  895. numberOfDerivatives,
  896. );
  897. }
  898. property.addSamplesPackedArray(unwrappedInterval, epoch);
  899. updateInterpolationSettings(packetData, property);
  900. return;
  901. }
  902. let interval;
  903. // A constant value with an interval is normally part of a TimeIntervalCollection,
  904. // However, if the current property is not a time-interval collection, we need
  905. // to turn it into a Composite, preserving the old data with the new interval.
  906. if (!isSampled && hasInterval) {
  907. // Create a new interval for the constant value.
  908. combinedInterval = combinedInterval.clone();
  909. if (isValue) {
  910. combinedInterval.data = Cartesian3.unpack(unwrappedInterval);
  911. } else {
  912. combinedInterval.data = createReferenceProperty(
  913. entityCollection,
  914. packetData.reference,
  915. );
  916. }
  917. // If no property exists, simply use a new interval collection
  918. if (!defined(property)) {
  919. if (isValue) {
  920. property = new TimeIntervalCollectionPositionProperty(referenceFrame);
  921. } else {
  922. property = new CompositePositionProperty(referenceFrame);
  923. }
  924. object[propertyName] = property;
  925. }
  926. if (
  927. isValue &&
  928. property instanceof TimeIntervalCollectionPositionProperty &&
  929. defined(referenceFrame) &&
  930. property.referenceFrame === referenceFrame
  931. ) {
  932. // If we create a collection, or it already existed, use it.
  933. property.intervals.addInterval(combinedInterval);
  934. } else if (property instanceof CompositePositionProperty) {
  935. // If the collection was already a CompositePositionProperty, use it.
  936. if (isValue) {
  937. combinedInterval.data = new ConstantPositionProperty(
  938. combinedInterval.data,
  939. referenceFrame,
  940. );
  941. }
  942. property.intervals.addInterval(combinedInterval);
  943. } else {
  944. // Otherwise, create a CompositePositionProperty but preserve the existing data.
  945. object[propertyName] = property =
  946. convertPositionPropertyToComposite(property);
  947. // Change the new data to a ConstantPositionProperty and add it.
  948. if (isValue) {
  949. combinedInterval.data = new ConstantPositionProperty(
  950. combinedInterval.data,
  951. referenceFrame,
  952. );
  953. }
  954. property.intervals.addInterval(combinedInterval);
  955. }
  956. return;
  957. }
  958. // isSampled && hasInterval
  959. if (!defined(property)) {
  960. object[propertyName] = property = new CompositePositionProperty(
  961. referenceFrame,
  962. );
  963. } else if (!(property instanceof CompositePositionProperty)) {
  964. // Create a CompositeProperty but preserve the existing data.
  965. object[propertyName] = property =
  966. convertPositionPropertyToComposite(property);
  967. }
  968. // Check if the interval already exists in the composite.
  969. const intervals = property.intervals;
  970. interval = intervals.findInterval(combinedInterval);
  971. if (
  972. !defined(interval) ||
  973. !(interval.data instanceof SampledPositionProperty) ||
  974. (defined(referenceFrame) && interval.data.referenceFrame !== referenceFrame)
  975. ) {
  976. // If not, create a SampledPositionProperty for it.
  977. interval = combinedInterval.clone();
  978. interval.data = new SampledPositionProperty(
  979. referenceFrame,
  980. numberOfDerivatives,
  981. );
  982. intervals.addInterval(interval);
  983. }
  984. interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
  985. updateInterpolationSettings(packetData, interval.data);
  986. }
  987. function removePositionPropertyData(property, interval) {
  988. if (property instanceof SampledPositionProperty) {
  989. property.removeSamples(interval);
  990. return;
  991. } else if (property instanceof TimeIntervalCollectionPositionProperty) {
  992. property.intervals.removeInterval(interval);
  993. return;
  994. } else if (property instanceof CompositePositionProperty) {
  995. const intervals = property.intervals;
  996. for (let i = 0; i < intervals.length; ++i) {
  997. const intersection = TimeInterval.intersect(
  998. intervals.get(i),
  999. interval,
  1000. scratchTimeInterval,
  1001. );
  1002. if (!intersection.isEmpty) {
  1003. // remove data from the contained properties
  1004. removePositionPropertyData(intersection.data, interval);
  1005. }
  1006. }
  1007. // remove the intervals from the composite
  1008. intervals.removeInterval(interval);
  1009. return;
  1010. }
  1011. }
  1012. function processPositionPacketData(
  1013. object,
  1014. propertyName,
  1015. packetData,
  1016. interval,
  1017. sourceUri,
  1018. entityCollection,
  1019. ) {
  1020. if (!defined(packetData)) {
  1021. return;
  1022. }
  1023. if (Array.isArray(packetData)) {
  1024. for (let i = 0, len = packetData.length; i < len; ++i) {
  1025. processPositionProperty(
  1026. object,
  1027. propertyName,
  1028. packetData[i],
  1029. interval,
  1030. sourceUri,
  1031. entityCollection,
  1032. );
  1033. }
  1034. } else {
  1035. processPositionProperty(
  1036. object,
  1037. propertyName,
  1038. packetData,
  1039. interval,
  1040. sourceUri,
  1041. entityCollection,
  1042. );
  1043. }
  1044. }
  1045. function processShapePacketData(
  1046. object,
  1047. propertyName,
  1048. packetData,
  1049. entityCollection,
  1050. ) {
  1051. if (defined(packetData.references)) {
  1052. processReferencesArrayPacketData(
  1053. object,
  1054. propertyName,
  1055. packetData.references,
  1056. packetData.interval,
  1057. entityCollection,
  1058. PropertyArray,
  1059. CompositeProperty,
  1060. );
  1061. } else {
  1062. if (defined(packetData.cartesian2)) {
  1063. packetData.array = Cartesian2.unpackArray(packetData.cartesian2);
  1064. } else if (defined(packetData.cartesian)) {
  1065. // for backwards compatibility, also accept `cartesian`
  1066. packetData.array = Cartesian2.unpackArray(packetData.cartesian);
  1067. }
  1068. if (defined(packetData.array)) {
  1069. processPacketData(
  1070. Array,
  1071. object,
  1072. propertyName,
  1073. packetData,
  1074. undefined,
  1075. undefined,
  1076. entityCollection,
  1077. );
  1078. }
  1079. }
  1080. }
  1081. function processMaterialProperty(
  1082. object,
  1083. propertyName,
  1084. packetData,
  1085. constrainedInterval,
  1086. sourceUri,
  1087. entityCollection,
  1088. ) {
  1089. let combinedInterval = intervalFromString(packetData.interval);
  1090. if (defined(constrainedInterval)) {
  1091. if (defined(combinedInterval)) {
  1092. combinedInterval = TimeInterval.intersect(
  1093. combinedInterval,
  1094. constrainedInterval,
  1095. scratchTimeInterval,
  1096. );
  1097. } else {
  1098. combinedInterval = constrainedInterval;
  1099. }
  1100. }
  1101. let property = object[propertyName];
  1102. let existingMaterial;
  1103. let existingInterval;
  1104. if (defined(combinedInterval)) {
  1105. if (!(property instanceof CompositeMaterialProperty)) {
  1106. property = new CompositeMaterialProperty();
  1107. object[propertyName] = property;
  1108. }
  1109. //See if we already have data at that interval.
  1110. const thisIntervals = property.intervals;
  1111. existingInterval = thisIntervals.findInterval({
  1112. start: combinedInterval.start,
  1113. stop: combinedInterval.stop,
  1114. });
  1115. if (defined(existingInterval)) {
  1116. //We have an interval, but we need to make sure the
  1117. //new data is the same type of material as the old data.
  1118. existingMaterial = existingInterval.data;
  1119. } else {
  1120. //If not, create it.
  1121. existingInterval = combinedInterval.clone();
  1122. thisIntervals.addInterval(existingInterval);
  1123. }
  1124. } else {
  1125. existingMaterial = property;
  1126. }
  1127. let materialData;
  1128. if (defined(packetData.solidColor)) {
  1129. if (!(existingMaterial instanceof ColorMaterialProperty)) {
  1130. existingMaterial = new ColorMaterialProperty();
  1131. }
  1132. materialData = packetData.solidColor;
  1133. processPacketData(
  1134. Color,
  1135. existingMaterial,
  1136. "color",
  1137. materialData.color,
  1138. undefined,
  1139. undefined,
  1140. entityCollection,
  1141. );
  1142. } else if (defined(packetData.grid)) {
  1143. if (!(existingMaterial instanceof GridMaterialProperty)) {
  1144. existingMaterial = new GridMaterialProperty();
  1145. }
  1146. materialData = packetData.grid;
  1147. processPacketData(
  1148. Color,
  1149. existingMaterial,
  1150. "color",
  1151. materialData.color,
  1152. undefined,
  1153. sourceUri,
  1154. entityCollection,
  1155. );
  1156. processPacketData(
  1157. Number,
  1158. existingMaterial,
  1159. "cellAlpha",
  1160. materialData.cellAlpha,
  1161. undefined,
  1162. sourceUri,
  1163. entityCollection,
  1164. );
  1165. processPacketData(
  1166. Cartesian2,
  1167. existingMaterial,
  1168. "lineCount",
  1169. materialData.lineCount,
  1170. undefined,
  1171. sourceUri,
  1172. entityCollection,
  1173. );
  1174. processPacketData(
  1175. Cartesian2,
  1176. existingMaterial,
  1177. "lineThickness",
  1178. materialData.lineThickness,
  1179. undefined,
  1180. sourceUri,
  1181. entityCollection,
  1182. );
  1183. processPacketData(
  1184. Cartesian2,
  1185. existingMaterial,
  1186. "lineOffset",
  1187. materialData.lineOffset,
  1188. undefined,
  1189. sourceUri,
  1190. entityCollection,
  1191. );
  1192. } else if (defined(packetData.image)) {
  1193. if (!(existingMaterial instanceof ImageMaterialProperty)) {
  1194. existingMaterial = new ImageMaterialProperty();
  1195. }
  1196. materialData = packetData.image;
  1197. processPacketData(
  1198. Image,
  1199. existingMaterial,
  1200. "image",
  1201. materialData.image,
  1202. undefined,
  1203. sourceUri,
  1204. entityCollection,
  1205. );
  1206. processPacketData(
  1207. Cartesian2,
  1208. existingMaterial,
  1209. "repeat",
  1210. materialData.repeat,
  1211. undefined,
  1212. sourceUri,
  1213. entityCollection,
  1214. );
  1215. processPacketData(
  1216. Color,
  1217. existingMaterial,
  1218. "color",
  1219. materialData.color,
  1220. undefined,
  1221. sourceUri,
  1222. entityCollection,
  1223. );
  1224. processPacketData(
  1225. Boolean,
  1226. existingMaterial,
  1227. "transparent",
  1228. materialData.transparent,
  1229. undefined,
  1230. sourceUri,
  1231. entityCollection,
  1232. );
  1233. } else if (defined(packetData.stripe)) {
  1234. if (!(existingMaterial instanceof StripeMaterialProperty)) {
  1235. existingMaterial = new StripeMaterialProperty();
  1236. }
  1237. materialData = packetData.stripe;
  1238. processPacketData(
  1239. StripeOrientation,
  1240. existingMaterial,
  1241. "orientation",
  1242. materialData.orientation,
  1243. undefined,
  1244. sourceUri,
  1245. entityCollection,
  1246. );
  1247. processPacketData(
  1248. Color,
  1249. existingMaterial,
  1250. "evenColor",
  1251. materialData.evenColor,
  1252. undefined,
  1253. sourceUri,
  1254. entityCollection,
  1255. );
  1256. processPacketData(
  1257. Color,
  1258. existingMaterial,
  1259. "oddColor",
  1260. materialData.oddColor,
  1261. undefined,
  1262. sourceUri,
  1263. entityCollection,
  1264. );
  1265. processPacketData(
  1266. Number,
  1267. existingMaterial,
  1268. "offset",
  1269. materialData.offset,
  1270. undefined,
  1271. sourceUri,
  1272. entityCollection,
  1273. );
  1274. processPacketData(
  1275. Number,
  1276. existingMaterial,
  1277. "repeat",
  1278. materialData.repeat,
  1279. undefined,
  1280. sourceUri,
  1281. entityCollection,
  1282. );
  1283. } else if (defined(packetData.polylineOutline)) {
  1284. if (!(existingMaterial instanceof PolylineOutlineMaterialProperty)) {
  1285. existingMaterial = new PolylineOutlineMaterialProperty();
  1286. }
  1287. materialData = packetData.polylineOutline;
  1288. processPacketData(
  1289. Color,
  1290. existingMaterial,
  1291. "color",
  1292. materialData.color,
  1293. undefined,
  1294. sourceUri,
  1295. entityCollection,
  1296. );
  1297. processPacketData(
  1298. Color,
  1299. existingMaterial,
  1300. "outlineColor",
  1301. materialData.outlineColor,
  1302. undefined,
  1303. sourceUri,
  1304. entityCollection,
  1305. );
  1306. processPacketData(
  1307. Number,
  1308. existingMaterial,
  1309. "outlineWidth",
  1310. materialData.outlineWidth,
  1311. undefined,
  1312. sourceUri,
  1313. entityCollection,
  1314. );
  1315. } else if (defined(packetData.polylineGlow)) {
  1316. if (!(existingMaterial instanceof PolylineGlowMaterialProperty)) {
  1317. existingMaterial = new PolylineGlowMaterialProperty();
  1318. }
  1319. materialData = packetData.polylineGlow;
  1320. processPacketData(
  1321. Color,
  1322. existingMaterial,
  1323. "color",
  1324. materialData.color,
  1325. undefined,
  1326. sourceUri,
  1327. entityCollection,
  1328. );
  1329. processPacketData(
  1330. Number,
  1331. existingMaterial,
  1332. "glowPower",
  1333. materialData.glowPower,
  1334. undefined,
  1335. sourceUri,
  1336. entityCollection,
  1337. );
  1338. processPacketData(
  1339. Number,
  1340. existingMaterial,
  1341. "taperPower",
  1342. materialData.taperPower,
  1343. undefined,
  1344. sourceUri,
  1345. entityCollection,
  1346. );
  1347. } else if (defined(packetData.polylineArrow)) {
  1348. if (!(existingMaterial instanceof PolylineArrowMaterialProperty)) {
  1349. existingMaterial = new PolylineArrowMaterialProperty();
  1350. }
  1351. materialData = packetData.polylineArrow;
  1352. processPacketData(
  1353. Color,
  1354. existingMaterial,
  1355. "color",
  1356. materialData.color,
  1357. undefined,
  1358. undefined,
  1359. entityCollection,
  1360. );
  1361. } else if (defined(packetData.polylineDash)) {
  1362. if (!(existingMaterial instanceof PolylineDashMaterialProperty)) {
  1363. existingMaterial = new PolylineDashMaterialProperty();
  1364. }
  1365. materialData = packetData.polylineDash;
  1366. processPacketData(
  1367. Color,
  1368. existingMaterial,
  1369. "color",
  1370. materialData.color,
  1371. undefined,
  1372. undefined,
  1373. entityCollection,
  1374. );
  1375. processPacketData(
  1376. Color,
  1377. existingMaterial,
  1378. "gapColor",
  1379. materialData.gapColor,
  1380. undefined,
  1381. undefined,
  1382. entityCollection,
  1383. );
  1384. processPacketData(
  1385. Number,
  1386. existingMaterial,
  1387. "dashLength",
  1388. materialData.dashLength,
  1389. undefined,
  1390. sourceUri,
  1391. entityCollection,
  1392. );
  1393. processPacketData(
  1394. Number,
  1395. existingMaterial,
  1396. "dashPattern",
  1397. materialData.dashPattern,
  1398. undefined,
  1399. sourceUri,
  1400. entityCollection,
  1401. );
  1402. } else if (defined(packetData.checkerboard)) {
  1403. if (!(existingMaterial instanceof CheckerboardMaterialProperty)) {
  1404. existingMaterial = new CheckerboardMaterialProperty();
  1405. }
  1406. materialData = packetData.checkerboard;
  1407. processPacketData(
  1408. Color,
  1409. existingMaterial,
  1410. "evenColor",
  1411. materialData.evenColor,
  1412. undefined,
  1413. sourceUri,
  1414. entityCollection,
  1415. );
  1416. processPacketData(
  1417. Color,
  1418. existingMaterial,
  1419. "oddColor",
  1420. materialData.oddColor,
  1421. undefined,
  1422. sourceUri,
  1423. entityCollection,
  1424. );
  1425. processPacketData(
  1426. Cartesian2,
  1427. existingMaterial,
  1428. "repeat",
  1429. materialData.repeat,
  1430. undefined,
  1431. sourceUri,
  1432. entityCollection,
  1433. );
  1434. }
  1435. if (defined(existingInterval)) {
  1436. existingInterval.data = existingMaterial;
  1437. } else {
  1438. object[propertyName] = existingMaterial;
  1439. }
  1440. }
  1441. function processMaterialPacketData(
  1442. object,
  1443. propertyName,
  1444. packetData,
  1445. interval,
  1446. sourceUri,
  1447. entityCollection,
  1448. ) {
  1449. if (!defined(packetData)) {
  1450. return;
  1451. }
  1452. if (Array.isArray(packetData)) {
  1453. for (let i = 0, len = packetData.length; i < len; ++i) {
  1454. processMaterialProperty(
  1455. object,
  1456. propertyName,
  1457. packetData[i],
  1458. interval,
  1459. sourceUri,
  1460. entityCollection,
  1461. );
  1462. }
  1463. } else {
  1464. processMaterialProperty(
  1465. object,
  1466. propertyName,
  1467. packetData,
  1468. interval,
  1469. sourceUri,
  1470. entityCollection,
  1471. );
  1472. }
  1473. }
  1474. function processName(entity, packet, entityCollection, sourceUri) {
  1475. const nameData = packet.name;
  1476. if (defined(nameData)) {
  1477. entity.name = packet.name;
  1478. }
  1479. }
  1480. function processDescription(entity, packet, entityCollection, sourceUri) {
  1481. const descriptionData = packet.description;
  1482. if (defined(descriptionData)) {
  1483. processPacketData(
  1484. String,
  1485. entity,
  1486. "description",
  1487. descriptionData,
  1488. undefined,
  1489. sourceUri,
  1490. entityCollection,
  1491. );
  1492. }
  1493. }
  1494. function processPosition(entity, packet, entityCollection, sourceUri) {
  1495. const positionData = packet.position;
  1496. if (defined(positionData)) {
  1497. processPositionPacketData(
  1498. entity,
  1499. "position",
  1500. positionData,
  1501. undefined,
  1502. sourceUri,
  1503. entityCollection,
  1504. );
  1505. }
  1506. }
  1507. function processViewFrom(entity, packet, entityCollection, sourceUri) {
  1508. const viewFromData = packet.viewFrom;
  1509. if (defined(viewFromData)) {
  1510. processPacketData(
  1511. Cartesian3,
  1512. entity,
  1513. "viewFrom",
  1514. viewFromData,
  1515. undefined,
  1516. sourceUri,
  1517. entityCollection,
  1518. );
  1519. }
  1520. }
  1521. function processOrientation(entity, packet, entityCollection, sourceUri) {
  1522. const orientationData = packet.orientation;
  1523. if (defined(orientationData)) {
  1524. processPacketData(
  1525. Quaternion,
  1526. entity,
  1527. "orientation",
  1528. orientationData,
  1529. undefined,
  1530. sourceUri,
  1531. entityCollection,
  1532. );
  1533. }
  1534. }
  1535. function processProperties(entity, packet, entityCollection, sourceUri) {
  1536. const propertiesData = packet.properties;
  1537. if (defined(propertiesData)) {
  1538. if (!defined(entity.properties)) {
  1539. entity.properties = new PropertyBag();
  1540. }
  1541. // We cannot simply call processPacketData(entity, 'properties', propertyData, undefined, sourceUri, entityCollection)
  1542. // because each property of "properties" may vary separately.
  1543. // The properties will be accessible as entity.properties.myprop.getValue(time).
  1544. for (const key in propertiesData) {
  1545. if (propertiesData.hasOwnProperty(key)) {
  1546. if (!entity.properties.hasProperty(key)) {
  1547. entity.properties.addProperty(key);
  1548. }
  1549. const propertyData = propertiesData[key];
  1550. if (Array.isArray(propertyData)) {
  1551. for (let i = 0, len = propertyData.length; i < len; ++i) {
  1552. processProperty(
  1553. getPropertyType(propertyData[i]),
  1554. entity.properties,
  1555. key,
  1556. propertyData[i],
  1557. undefined,
  1558. sourceUri,
  1559. entityCollection,
  1560. );
  1561. }
  1562. } else {
  1563. processProperty(
  1564. getPropertyType(propertyData),
  1565. entity.properties,
  1566. key,
  1567. propertyData,
  1568. undefined,
  1569. sourceUri,
  1570. entityCollection,
  1571. );
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. function processReferencesArrayPacketData(
  1578. object,
  1579. propertyName,
  1580. references,
  1581. interval,
  1582. entityCollection,
  1583. PropertyArrayType,
  1584. CompositePropertyArrayType,
  1585. ) {
  1586. const properties = references.map(function (reference) {
  1587. return createReferenceProperty(entityCollection, reference);
  1588. });
  1589. if (defined(interval)) {
  1590. interval = intervalFromString(interval);
  1591. let property = object[propertyName];
  1592. if (!(property instanceof CompositePropertyArrayType)) {
  1593. // If the property was not already a CompositeProperty,
  1594. // create a CompositeProperty but preserve the existing data.
  1595. // Create the composite and add the old property, wrapped in an infinite interval.
  1596. const composite = new CompositePropertyArrayType();
  1597. composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
  1598. object[propertyName] = property = composite;
  1599. }
  1600. interval.data = new PropertyArrayType(properties);
  1601. property.intervals.addInterval(interval);
  1602. } else {
  1603. object[propertyName] = new PropertyArrayType(properties);
  1604. }
  1605. }
  1606. function processArrayPacketData(
  1607. object,
  1608. propertyName,
  1609. packetData,
  1610. entityCollection,
  1611. ) {
  1612. const references = packetData.references;
  1613. if (defined(references)) {
  1614. processReferencesArrayPacketData(
  1615. object,
  1616. propertyName,
  1617. references,
  1618. packetData.interval,
  1619. entityCollection,
  1620. PropertyArray,
  1621. CompositeProperty,
  1622. );
  1623. } else {
  1624. processPacketData(
  1625. Array,
  1626. object,
  1627. propertyName,
  1628. packetData,
  1629. undefined,
  1630. undefined,
  1631. entityCollection,
  1632. );
  1633. }
  1634. }
  1635. function processArray(object, propertyName, packetData, entityCollection) {
  1636. if (!defined(packetData)) {
  1637. return;
  1638. }
  1639. if (Array.isArray(packetData)) {
  1640. for (let i = 0, length = packetData.length; i < length; ++i) {
  1641. processArrayPacketData(
  1642. object,
  1643. propertyName,
  1644. packetData[i],
  1645. entityCollection,
  1646. );
  1647. }
  1648. } else {
  1649. processArrayPacketData(object, propertyName, packetData, entityCollection);
  1650. }
  1651. }
  1652. function processPositionArrayPacketData(
  1653. object,
  1654. propertyName,
  1655. packetData,
  1656. entityCollection,
  1657. ) {
  1658. const references = packetData.references;
  1659. if (defined(references)) {
  1660. processReferencesArrayPacketData(
  1661. object,
  1662. propertyName,
  1663. references,
  1664. packetData.interval,
  1665. entityCollection,
  1666. PositionPropertyArray,
  1667. CompositePositionProperty,
  1668. );
  1669. } else {
  1670. if (defined(packetData.cartesian)) {
  1671. packetData.array = Cartesian3.unpackArray(packetData.cartesian);
  1672. } else if (defined(packetData.cartographicRadians)) {
  1673. packetData.array = Cartesian3.fromRadiansArrayHeights(
  1674. packetData.cartographicRadians,
  1675. Ellipsoid.default,
  1676. );
  1677. } else if (defined(packetData.cartographicDegrees)) {
  1678. packetData.array = Cartesian3.fromDegreesArrayHeights(
  1679. packetData.cartographicDegrees,
  1680. Ellipsoid.default,
  1681. );
  1682. }
  1683. if (defined(packetData.array)) {
  1684. processPacketData(
  1685. Array,
  1686. object,
  1687. propertyName,
  1688. packetData,
  1689. undefined,
  1690. undefined,
  1691. entityCollection,
  1692. );
  1693. }
  1694. }
  1695. }
  1696. function processPositionArray(
  1697. object,
  1698. propertyName,
  1699. packetData,
  1700. entityCollection,
  1701. ) {
  1702. if (!defined(packetData)) {
  1703. return;
  1704. }
  1705. if (Array.isArray(packetData)) {
  1706. for (let i = 0, length = packetData.length; i < length; ++i) {
  1707. processPositionArrayPacketData(
  1708. object,
  1709. propertyName,
  1710. packetData[i],
  1711. entityCollection,
  1712. );
  1713. }
  1714. } else {
  1715. processPositionArrayPacketData(
  1716. object,
  1717. propertyName,
  1718. packetData,
  1719. entityCollection,
  1720. );
  1721. }
  1722. }
  1723. function unpackCartesianArray(array) {
  1724. return Cartesian3.unpackArray(array);
  1725. }
  1726. function unpackCartographicRadiansArray(array) {
  1727. return Cartesian3.fromRadiansArrayHeights(array, Ellipsoid.default);
  1728. }
  1729. function unpackCartographicDegreesArray(array) {
  1730. return Cartesian3.fromDegreesArrayHeights(array, Ellipsoid.default);
  1731. }
  1732. function processPositionArrayOfArraysPacketData(
  1733. object,
  1734. propertyName,
  1735. packetData,
  1736. entityCollection,
  1737. ) {
  1738. const references = packetData.references;
  1739. if (defined(references)) {
  1740. const properties = references.map(function (referenceArray) {
  1741. const tempObj = {};
  1742. processReferencesArrayPacketData(
  1743. tempObj,
  1744. "positions",
  1745. referenceArray,
  1746. packetData.interval,
  1747. entityCollection,
  1748. PositionPropertyArray,
  1749. CompositePositionProperty,
  1750. );
  1751. return tempObj.positions;
  1752. });
  1753. object[propertyName] = new PositionPropertyArray(properties);
  1754. } else {
  1755. if (defined(packetData.cartesian)) {
  1756. packetData.array = packetData.cartesian.map(unpackCartesianArray);
  1757. } else if (defined(packetData.cartographicRadians)) {
  1758. packetData.array = packetData.cartographicRadians.map(
  1759. unpackCartographicRadiansArray,
  1760. );
  1761. } else if (defined(packetData.cartographicDegrees)) {
  1762. packetData.array = packetData.cartographicDegrees.map(
  1763. unpackCartographicDegreesArray,
  1764. );
  1765. }
  1766. if (defined(packetData.array)) {
  1767. processPacketData(
  1768. Array,
  1769. object,
  1770. propertyName,
  1771. packetData,
  1772. undefined,
  1773. undefined,
  1774. entityCollection,
  1775. );
  1776. }
  1777. }
  1778. }
  1779. function processPositionArrayOfArrays(
  1780. object,
  1781. propertyName,
  1782. packetData,
  1783. entityCollection,
  1784. ) {
  1785. if (!defined(packetData)) {
  1786. return;
  1787. }
  1788. if (Array.isArray(packetData)) {
  1789. for (let i = 0, length = packetData.length; i < length; ++i) {
  1790. processPositionArrayOfArraysPacketData(
  1791. object,
  1792. propertyName,
  1793. packetData[i],
  1794. entityCollection,
  1795. );
  1796. }
  1797. } else {
  1798. processPositionArrayOfArraysPacketData(
  1799. object,
  1800. propertyName,
  1801. packetData,
  1802. entityCollection,
  1803. );
  1804. }
  1805. }
  1806. function processShape(object, propertyName, packetData, entityCollection) {
  1807. if (!defined(packetData)) {
  1808. return;
  1809. }
  1810. if (Array.isArray(packetData)) {
  1811. for (let i = 0, length = packetData.length; i < length; i++) {
  1812. processShapePacketData(
  1813. object,
  1814. propertyName,
  1815. packetData[i],
  1816. entityCollection,
  1817. );
  1818. }
  1819. } else {
  1820. processShapePacketData(object, propertyName, packetData, entityCollection);
  1821. }
  1822. }
  1823. function processAvailability(entity, packet, entityCollection, sourceUri) {
  1824. const packetData = packet.availability;
  1825. if (!defined(packetData)) {
  1826. return;
  1827. }
  1828. let intervals;
  1829. if (Array.isArray(packetData)) {
  1830. for (let i = 0, len = packetData.length; i < len; ++i) {
  1831. if (!defined(intervals)) {
  1832. intervals = new TimeIntervalCollection();
  1833. }
  1834. intervals.addInterval(intervalFromString(packetData[i]));
  1835. }
  1836. } else {
  1837. intervals = new TimeIntervalCollection();
  1838. intervals.addInterval(intervalFromString(packetData));
  1839. }
  1840. entity.availability = intervals;
  1841. }
  1842. function processAlignedAxis(
  1843. billboard,
  1844. packetData,
  1845. interval,
  1846. sourceUri,
  1847. entityCollection,
  1848. ) {
  1849. if (!defined(packetData)) {
  1850. return;
  1851. }
  1852. processPacketData(
  1853. UnitCartesian3,
  1854. billboard,
  1855. "alignedAxis",
  1856. packetData,
  1857. interval,
  1858. sourceUri,
  1859. entityCollection,
  1860. );
  1861. }
  1862. function processBillboard(entity, packet, entityCollection, sourceUri) {
  1863. const billboardData = packet.billboard;
  1864. if (!defined(billboardData)) {
  1865. return;
  1866. }
  1867. const interval = intervalFromString(billboardData.interval);
  1868. let billboard = entity.billboard;
  1869. if (!defined(billboard)) {
  1870. entity.billboard = billboard = new BillboardGraphics();
  1871. }
  1872. processPacketData(
  1873. Boolean,
  1874. billboard,
  1875. "show",
  1876. billboardData.show,
  1877. interval,
  1878. sourceUri,
  1879. entityCollection,
  1880. );
  1881. processPacketData(
  1882. Image,
  1883. billboard,
  1884. "image",
  1885. billboardData.image,
  1886. interval,
  1887. sourceUri,
  1888. entityCollection,
  1889. );
  1890. processPacketData(
  1891. Number,
  1892. billboard,
  1893. "scale",
  1894. billboardData.scale,
  1895. interval,
  1896. sourceUri,
  1897. entityCollection,
  1898. );
  1899. processPacketData(
  1900. Cartesian2,
  1901. billboard,
  1902. "pixelOffset",
  1903. billboardData.pixelOffset,
  1904. interval,
  1905. sourceUri,
  1906. entityCollection,
  1907. );
  1908. processPacketData(
  1909. Cartesian3,
  1910. billboard,
  1911. "eyeOffset",
  1912. billboardData.eyeOffset,
  1913. interval,
  1914. sourceUri,
  1915. entityCollection,
  1916. );
  1917. processPacketData(
  1918. HorizontalOrigin,
  1919. billboard,
  1920. "horizontalOrigin",
  1921. billboardData.horizontalOrigin,
  1922. interval,
  1923. sourceUri,
  1924. entityCollection,
  1925. );
  1926. processPacketData(
  1927. VerticalOrigin,
  1928. billboard,
  1929. "verticalOrigin",
  1930. billboardData.verticalOrigin,
  1931. interval,
  1932. sourceUri,
  1933. entityCollection,
  1934. );
  1935. processPacketData(
  1936. HeightReference,
  1937. billboard,
  1938. "heightReference",
  1939. billboardData.heightReference,
  1940. interval,
  1941. sourceUri,
  1942. entityCollection,
  1943. );
  1944. processPacketData(
  1945. Color,
  1946. billboard,
  1947. "color",
  1948. billboardData.color,
  1949. interval,
  1950. sourceUri,
  1951. entityCollection,
  1952. );
  1953. processPacketData(
  1954. Rotation,
  1955. billboard,
  1956. "rotation",
  1957. billboardData.rotation,
  1958. interval,
  1959. sourceUri,
  1960. entityCollection,
  1961. );
  1962. processAlignedAxis(
  1963. billboard,
  1964. billboardData.alignedAxis,
  1965. interval,
  1966. sourceUri,
  1967. entityCollection,
  1968. );
  1969. processPacketData(
  1970. Boolean,
  1971. billboard,
  1972. "sizeInMeters",
  1973. billboardData.sizeInMeters,
  1974. interval,
  1975. sourceUri,
  1976. entityCollection,
  1977. );
  1978. processPacketData(
  1979. Number,
  1980. billboard,
  1981. "width",
  1982. billboardData.width,
  1983. interval,
  1984. sourceUri,
  1985. entityCollection,
  1986. );
  1987. processPacketData(
  1988. Number,
  1989. billboard,
  1990. "height",
  1991. billboardData.height,
  1992. interval,
  1993. sourceUri,
  1994. entityCollection,
  1995. );
  1996. processPacketData(
  1997. NearFarScalar,
  1998. billboard,
  1999. "scaleByDistance",
  2000. billboardData.scaleByDistance,
  2001. interval,
  2002. sourceUri,
  2003. entityCollection,
  2004. );
  2005. processPacketData(
  2006. NearFarScalar,
  2007. billboard,
  2008. "translucencyByDistance",
  2009. billboardData.translucencyByDistance,
  2010. interval,
  2011. sourceUri,
  2012. entityCollection,
  2013. );
  2014. processPacketData(
  2015. NearFarScalar,
  2016. billboard,
  2017. "pixelOffsetScaleByDistance",
  2018. billboardData.pixelOffsetScaleByDistance,
  2019. interval,
  2020. sourceUri,
  2021. entityCollection,
  2022. );
  2023. processPacketData(
  2024. BoundingRectangle,
  2025. billboard,
  2026. "imageSubRegion",
  2027. billboardData.imageSubRegion,
  2028. interval,
  2029. sourceUri,
  2030. entityCollection,
  2031. );
  2032. processPacketData(
  2033. DistanceDisplayCondition,
  2034. billboard,
  2035. "distanceDisplayCondition",
  2036. billboardData.distanceDisplayCondition,
  2037. interval,
  2038. sourceUri,
  2039. entityCollection,
  2040. );
  2041. processPacketData(
  2042. Number,
  2043. billboard,
  2044. "disableDepthTestDistance",
  2045. billboardData.disableDepthTestDistance,
  2046. interval,
  2047. sourceUri,
  2048. entityCollection,
  2049. );
  2050. }
  2051. function processBox(entity, packet, entityCollection, sourceUri) {
  2052. const boxData = packet.box;
  2053. if (!defined(boxData)) {
  2054. return;
  2055. }
  2056. const interval = intervalFromString(boxData.interval);
  2057. let box = entity.box;
  2058. if (!defined(box)) {
  2059. entity.box = box = new BoxGraphics();
  2060. }
  2061. processPacketData(
  2062. Boolean,
  2063. box,
  2064. "show",
  2065. boxData.show,
  2066. interval,
  2067. sourceUri,
  2068. entityCollection,
  2069. );
  2070. processPacketData(
  2071. Cartesian3,
  2072. box,
  2073. "dimensions",
  2074. boxData.dimensions,
  2075. interval,
  2076. sourceUri,
  2077. entityCollection,
  2078. );
  2079. processPacketData(
  2080. HeightReference,
  2081. box,
  2082. "heightReference",
  2083. boxData.heightReference,
  2084. interval,
  2085. sourceUri,
  2086. entityCollection,
  2087. );
  2088. processPacketData(
  2089. Boolean,
  2090. box,
  2091. "fill",
  2092. boxData.fill,
  2093. interval,
  2094. sourceUri,
  2095. entityCollection,
  2096. );
  2097. processMaterialPacketData(
  2098. box,
  2099. "material",
  2100. boxData.material,
  2101. interval,
  2102. sourceUri,
  2103. entityCollection,
  2104. );
  2105. processPacketData(
  2106. Boolean,
  2107. box,
  2108. "outline",
  2109. boxData.outline,
  2110. interval,
  2111. sourceUri,
  2112. entityCollection,
  2113. );
  2114. processPacketData(
  2115. Color,
  2116. box,
  2117. "outlineColor",
  2118. boxData.outlineColor,
  2119. interval,
  2120. sourceUri,
  2121. entityCollection,
  2122. );
  2123. processPacketData(
  2124. Number,
  2125. box,
  2126. "outlineWidth",
  2127. boxData.outlineWidth,
  2128. interval,
  2129. sourceUri,
  2130. entityCollection,
  2131. );
  2132. processPacketData(
  2133. ShadowMode,
  2134. box,
  2135. "shadows",
  2136. boxData.shadows,
  2137. interval,
  2138. sourceUri,
  2139. entityCollection,
  2140. );
  2141. processPacketData(
  2142. DistanceDisplayCondition,
  2143. box,
  2144. "distanceDisplayCondition",
  2145. boxData.distanceDisplayCondition,
  2146. interval,
  2147. sourceUri,
  2148. entityCollection,
  2149. );
  2150. }
  2151. function processCorridor(entity, packet, entityCollection, sourceUri) {
  2152. const corridorData = packet.corridor;
  2153. if (!defined(corridorData)) {
  2154. return;
  2155. }
  2156. const interval = intervalFromString(corridorData.interval);
  2157. let corridor = entity.corridor;
  2158. if (!defined(corridor)) {
  2159. entity.corridor = corridor = new CorridorGraphics();
  2160. }
  2161. processPacketData(
  2162. Boolean,
  2163. corridor,
  2164. "show",
  2165. corridorData.show,
  2166. interval,
  2167. sourceUri,
  2168. entityCollection,
  2169. );
  2170. processPositionArray(
  2171. corridor,
  2172. "positions",
  2173. corridorData.positions,
  2174. entityCollection,
  2175. );
  2176. processPacketData(
  2177. Number,
  2178. corridor,
  2179. "width",
  2180. corridorData.width,
  2181. interval,
  2182. sourceUri,
  2183. entityCollection,
  2184. );
  2185. processPacketData(
  2186. Number,
  2187. corridor,
  2188. "height",
  2189. corridorData.height,
  2190. interval,
  2191. sourceUri,
  2192. entityCollection,
  2193. );
  2194. processPacketData(
  2195. HeightReference,
  2196. corridor,
  2197. "heightReference",
  2198. corridorData.heightReference,
  2199. interval,
  2200. sourceUri,
  2201. entityCollection,
  2202. );
  2203. processPacketData(
  2204. Number,
  2205. corridor,
  2206. "extrudedHeight",
  2207. corridorData.extrudedHeight,
  2208. interval,
  2209. sourceUri,
  2210. entityCollection,
  2211. );
  2212. processPacketData(
  2213. HeightReference,
  2214. corridor,
  2215. "extrudedHeightReference",
  2216. corridorData.extrudedHeightReference,
  2217. interval,
  2218. sourceUri,
  2219. entityCollection,
  2220. );
  2221. processPacketData(
  2222. CornerType,
  2223. corridor,
  2224. "cornerType",
  2225. corridorData.cornerType,
  2226. interval,
  2227. sourceUri,
  2228. entityCollection,
  2229. );
  2230. processPacketData(
  2231. Number,
  2232. corridor,
  2233. "granularity",
  2234. corridorData.granularity,
  2235. interval,
  2236. sourceUri,
  2237. entityCollection,
  2238. );
  2239. processPacketData(
  2240. Boolean,
  2241. corridor,
  2242. "fill",
  2243. corridorData.fill,
  2244. interval,
  2245. sourceUri,
  2246. entityCollection,
  2247. );
  2248. processMaterialPacketData(
  2249. corridor,
  2250. "material",
  2251. corridorData.material,
  2252. interval,
  2253. sourceUri,
  2254. entityCollection,
  2255. );
  2256. processPacketData(
  2257. Boolean,
  2258. corridor,
  2259. "outline",
  2260. corridorData.outline,
  2261. interval,
  2262. sourceUri,
  2263. entityCollection,
  2264. );
  2265. processPacketData(
  2266. Color,
  2267. corridor,
  2268. "outlineColor",
  2269. corridorData.outlineColor,
  2270. interval,
  2271. sourceUri,
  2272. entityCollection,
  2273. );
  2274. processPacketData(
  2275. Number,
  2276. corridor,
  2277. "outlineWidth",
  2278. corridorData.outlineWidth,
  2279. interval,
  2280. sourceUri,
  2281. entityCollection,
  2282. );
  2283. processPacketData(
  2284. ShadowMode,
  2285. corridor,
  2286. "shadows",
  2287. corridorData.shadows,
  2288. interval,
  2289. sourceUri,
  2290. entityCollection,
  2291. );
  2292. processPacketData(
  2293. DistanceDisplayCondition,
  2294. corridor,
  2295. "distanceDisplayCondition",
  2296. corridorData.distanceDisplayCondition,
  2297. interval,
  2298. sourceUri,
  2299. entityCollection,
  2300. );
  2301. processPacketData(
  2302. ClassificationType,
  2303. corridor,
  2304. "classificationType",
  2305. corridorData.classificationType,
  2306. interval,
  2307. sourceUri,
  2308. entityCollection,
  2309. );
  2310. processPacketData(
  2311. Number,
  2312. corridor,
  2313. "zIndex",
  2314. corridorData.zIndex,
  2315. interval,
  2316. sourceUri,
  2317. entityCollection,
  2318. );
  2319. }
  2320. function processCylinder(entity, packet, entityCollection, sourceUri) {
  2321. const cylinderData = packet.cylinder;
  2322. if (!defined(cylinderData)) {
  2323. return;
  2324. }
  2325. const interval = intervalFromString(cylinderData.interval);
  2326. let cylinder = entity.cylinder;
  2327. if (!defined(cylinder)) {
  2328. entity.cylinder = cylinder = new CylinderGraphics();
  2329. }
  2330. processPacketData(
  2331. Boolean,
  2332. cylinder,
  2333. "show",
  2334. cylinderData.show,
  2335. interval,
  2336. sourceUri,
  2337. entityCollection,
  2338. );
  2339. processPacketData(
  2340. Number,
  2341. cylinder,
  2342. "length",
  2343. cylinderData.length,
  2344. interval,
  2345. sourceUri,
  2346. entityCollection,
  2347. );
  2348. processPacketData(
  2349. Number,
  2350. cylinder,
  2351. "topRadius",
  2352. cylinderData.topRadius,
  2353. interval,
  2354. sourceUri,
  2355. entityCollection,
  2356. );
  2357. processPacketData(
  2358. Number,
  2359. cylinder,
  2360. "bottomRadius",
  2361. cylinderData.bottomRadius,
  2362. interval,
  2363. sourceUri,
  2364. entityCollection,
  2365. );
  2366. processPacketData(
  2367. HeightReference,
  2368. cylinder,
  2369. "heightReference",
  2370. cylinderData.heightReference,
  2371. interval,
  2372. sourceUri,
  2373. entityCollection,
  2374. );
  2375. processPacketData(
  2376. Boolean,
  2377. cylinder,
  2378. "fill",
  2379. cylinderData.fill,
  2380. interval,
  2381. sourceUri,
  2382. entityCollection,
  2383. );
  2384. processMaterialPacketData(
  2385. cylinder,
  2386. "material",
  2387. cylinderData.material,
  2388. interval,
  2389. sourceUri,
  2390. entityCollection,
  2391. );
  2392. processPacketData(
  2393. Boolean,
  2394. cylinder,
  2395. "outline",
  2396. cylinderData.outline,
  2397. interval,
  2398. sourceUri,
  2399. entityCollection,
  2400. );
  2401. processPacketData(
  2402. Color,
  2403. cylinder,
  2404. "outlineColor",
  2405. cylinderData.outlineColor,
  2406. interval,
  2407. sourceUri,
  2408. entityCollection,
  2409. );
  2410. processPacketData(
  2411. Number,
  2412. cylinder,
  2413. "outlineWidth",
  2414. cylinderData.outlineWidth,
  2415. interval,
  2416. sourceUri,
  2417. entityCollection,
  2418. );
  2419. processPacketData(
  2420. Number,
  2421. cylinder,
  2422. "numberOfVerticalLines",
  2423. cylinderData.numberOfVerticalLines,
  2424. interval,
  2425. sourceUri,
  2426. entityCollection,
  2427. );
  2428. processPacketData(
  2429. Number,
  2430. cylinder,
  2431. "slices",
  2432. cylinderData.slices,
  2433. interval,
  2434. sourceUri,
  2435. entityCollection,
  2436. );
  2437. processPacketData(
  2438. ShadowMode,
  2439. cylinder,
  2440. "shadows",
  2441. cylinderData.shadows,
  2442. interval,
  2443. sourceUri,
  2444. entityCollection,
  2445. );
  2446. processPacketData(
  2447. DistanceDisplayCondition,
  2448. cylinder,
  2449. "distanceDisplayCondition",
  2450. cylinderData.distanceDisplayCondition,
  2451. interval,
  2452. sourceUri,
  2453. entityCollection,
  2454. );
  2455. }
  2456. function processDocument(packet, dataSource) {
  2457. const version = packet.version;
  2458. if (defined(version)) {
  2459. if (typeof version === "string") {
  2460. const tokens = version.split(".");
  2461. if (tokens.length === 2) {
  2462. if (tokens[0] !== "1") {
  2463. throw new RuntimeError("Cesium only supports CZML version 1.");
  2464. }
  2465. dataSource._version = version;
  2466. }
  2467. }
  2468. }
  2469. if (!defined(dataSource._version)) {
  2470. throw new RuntimeError(
  2471. "CZML version information invalid. It is expected to be a property on the document object in the <Major>.<Minor> version format.",
  2472. );
  2473. }
  2474. const documentPacket = dataSource._documentPacket;
  2475. if (defined(packet.name)) {
  2476. documentPacket.name = packet.name;
  2477. }
  2478. const clockPacket = packet.clock;
  2479. if (defined(clockPacket)) {
  2480. const clock = documentPacket.clock;
  2481. if (!defined(clock)) {
  2482. documentPacket.clock = {
  2483. interval: clockPacket.interval,
  2484. currentTime: clockPacket.currentTime,
  2485. range: clockPacket.range,
  2486. step: clockPacket.step,
  2487. multiplier: clockPacket.multiplier,
  2488. };
  2489. } else {
  2490. clock.interval = clockPacket.interval ?? clock.interval;
  2491. clock.currentTime = clockPacket.currentTime ?? clock.currentTime;
  2492. clock.range = clockPacket.range ?? clock.range;
  2493. clock.step = clockPacket.step ?? clock.step;
  2494. clock.multiplier = clockPacket.multiplier ?? clock.multiplier;
  2495. }
  2496. }
  2497. }
  2498. function processEllipse(entity, packet, entityCollection, sourceUri) {
  2499. const ellipseData = packet.ellipse;
  2500. if (!defined(ellipseData)) {
  2501. return;
  2502. }
  2503. const interval = intervalFromString(ellipseData.interval);
  2504. let ellipse = entity.ellipse;
  2505. if (!defined(ellipse)) {
  2506. entity.ellipse = ellipse = new EllipseGraphics();
  2507. }
  2508. processPacketData(
  2509. Boolean,
  2510. ellipse,
  2511. "show",
  2512. ellipseData.show,
  2513. interval,
  2514. sourceUri,
  2515. entityCollection,
  2516. );
  2517. processPacketData(
  2518. Number,
  2519. ellipse,
  2520. "semiMajorAxis",
  2521. ellipseData.semiMajorAxis,
  2522. interval,
  2523. sourceUri,
  2524. entityCollection,
  2525. );
  2526. processPacketData(
  2527. Number,
  2528. ellipse,
  2529. "semiMinorAxis",
  2530. ellipseData.semiMinorAxis,
  2531. interval,
  2532. sourceUri,
  2533. entityCollection,
  2534. );
  2535. processPacketData(
  2536. Number,
  2537. ellipse,
  2538. "height",
  2539. ellipseData.height,
  2540. interval,
  2541. sourceUri,
  2542. entityCollection,
  2543. );
  2544. processPacketData(
  2545. HeightReference,
  2546. ellipse,
  2547. "heightReference",
  2548. ellipseData.heightReference,
  2549. interval,
  2550. sourceUri,
  2551. entityCollection,
  2552. );
  2553. processPacketData(
  2554. Number,
  2555. ellipse,
  2556. "extrudedHeight",
  2557. ellipseData.extrudedHeight,
  2558. interval,
  2559. sourceUri,
  2560. entityCollection,
  2561. );
  2562. processPacketData(
  2563. HeightReference,
  2564. ellipse,
  2565. "extrudedHeightReference",
  2566. ellipseData.extrudedHeightReference,
  2567. interval,
  2568. sourceUri,
  2569. entityCollection,
  2570. );
  2571. processPacketData(
  2572. Rotation,
  2573. ellipse,
  2574. "rotation",
  2575. ellipseData.rotation,
  2576. interval,
  2577. sourceUri,
  2578. entityCollection,
  2579. );
  2580. processPacketData(
  2581. Rotation,
  2582. ellipse,
  2583. "stRotation",
  2584. ellipseData.stRotation,
  2585. interval,
  2586. sourceUri,
  2587. entityCollection,
  2588. );
  2589. processPacketData(
  2590. Number,
  2591. ellipse,
  2592. "granularity",
  2593. ellipseData.granularity,
  2594. interval,
  2595. sourceUri,
  2596. entityCollection,
  2597. );
  2598. processPacketData(
  2599. Boolean,
  2600. ellipse,
  2601. "fill",
  2602. ellipseData.fill,
  2603. interval,
  2604. sourceUri,
  2605. entityCollection,
  2606. );
  2607. processMaterialPacketData(
  2608. ellipse,
  2609. "material",
  2610. ellipseData.material,
  2611. interval,
  2612. sourceUri,
  2613. entityCollection,
  2614. );
  2615. processPacketData(
  2616. Boolean,
  2617. ellipse,
  2618. "outline",
  2619. ellipseData.outline,
  2620. interval,
  2621. sourceUri,
  2622. entityCollection,
  2623. );
  2624. processPacketData(
  2625. Color,
  2626. ellipse,
  2627. "outlineColor",
  2628. ellipseData.outlineColor,
  2629. interval,
  2630. sourceUri,
  2631. entityCollection,
  2632. );
  2633. processPacketData(
  2634. Number,
  2635. ellipse,
  2636. "outlineWidth",
  2637. ellipseData.outlineWidth,
  2638. interval,
  2639. sourceUri,
  2640. entityCollection,
  2641. );
  2642. processPacketData(
  2643. Number,
  2644. ellipse,
  2645. "numberOfVerticalLines",
  2646. ellipseData.numberOfVerticalLines,
  2647. interval,
  2648. sourceUri,
  2649. entityCollection,
  2650. );
  2651. processPacketData(
  2652. ShadowMode,
  2653. ellipse,
  2654. "shadows",
  2655. ellipseData.shadows,
  2656. interval,
  2657. sourceUri,
  2658. entityCollection,
  2659. );
  2660. processPacketData(
  2661. DistanceDisplayCondition,
  2662. ellipse,
  2663. "distanceDisplayCondition",
  2664. ellipseData.distanceDisplayCondition,
  2665. interval,
  2666. sourceUri,
  2667. entityCollection,
  2668. );
  2669. processPacketData(
  2670. ClassificationType,
  2671. ellipse,
  2672. "classificationType",
  2673. ellipseData.classificationType,
  2674. interval,
  2675. sourceUri,
  2676. entityCollection,
  2677. );
  2678. processPacketData(
  2679. Number,
  2680. ellipse,
  2681. "zIndex",
  2682. ellipseData.zIndex,
  2683. interval,
  2684. sourceUri,
  2685. entityCollection,
  2686. );
  2687. }
  2688. function processEllipsoid(entity, packet, entityCollection, sourceUri) {
  2689. const ellipsoidData = packet.ellipsoid;
  2690. if (!defined(ellipsoidData)) {
  2691. return;
  2692. }
  2693. const interval = intervalFromString(ellipsoidData.interval);
  2694. let ellipsoid = entity.ellipsoid;
  2695. if (!defined(ellipsoid)) {
  2696. entity.ellipsoid = ellipsoid = new EllipsoidGraphics();
  2697. }
  2698. processPacketData(
  2699. Boolean,
  2700. ellipsoid,
  2701. "show",
  2702. ellipsoidData.show,
  2703. interval,
  2704. sourceUri,
  2705. entityCollection,
  2706. );
  2707. processPacketData(
  2708. Cartesian3,
  2709. ellipsoid,
  2710. "radii",
  2711. ellipsoidData.radii,
  2712. interval,
  2713. sourceUri,
  2714. entityCollection,
  2715. );
  2716. processPacketData(
  2717. Cartesian3,
  2718. ellipsoid,
  2719. "innerRadii",
  2720. ellipsoidData.innerRadii,
  2721. interval,
  2722. sourceUri,
  2723. entityCollection,
  2724. );
  2725. processPacketData(
  2726. Number,
  2727. ellipsoid,
  2728. "minimumClock",
  2729. ellipsoidData.minimumClock,
  2730. interval,
  2731. sourceUri,
  2732. entityCollection,
  2733. );
  2734. processPacketData(
  2735. Number,
  2736. ellipsoid,
  2737. "maximumClock",
  2738. ellipsoidData.maximumClock,
  2739. interval,
  2740. sourceUri,
  2741. entityCollection,
  2742. );
  2743. processPacketData(
  2744. Number,
  2745. ellipsoid,
  2746. "minimumCone",
  2747. ellipsoidData.minimumCone,
  2748. interval,
  2749. sourceUri,
  2750. entityCollection,
  2751. );
  2752. processPacketData(
  2753. Number,
  2754. ellipsoid,
  2755. "maximumCone",
  2756. ellipsoidData.maximumCone,
  2757. interval,
  2758. sourceUri,
  2759. entityCollection,
  2760. );
  2761. processPacketData(
  2762. HeightReference,
  2763. ellipsoid,
  2764. "heightReference",
  2765. ellipsoidData.heightReference,
  2766. interval,
  2767. sourceUri,
  2768. entityCollection,
  2769. );
  2770. processPacketData(
  2771. Boolean,
  2772. ellipsoid,
  2773. "fill",
  2774. ellipsoidData.fill,
  2775. interval,
  2776. sourceUri,
  2777. entityCollection,
  2778. );
  2779. processMaterialPacketData(
  2780. ellipsoid,
  2781. "material",
  2782. ellipsoidData.material,
  2783. interval,
  2784. sourceUri,
  2785. entityCollection,
  2786. );
  2787. processPacketData(
  2788. Boolean,
  2789. ellipsoid,
  2790. "outline",
  2791. ellipsoidData.outline,
  2792. interval,
  2793. sourceUri,
  2794. entityCollection,
  2795. );
  2796. processPacketData(
  2797. Color,
  2798. ellipsoid,
  2799. "outlineColor",
  2800. ellipsoidData.outlineColor,
  2801. interval,
  2802. sourceUri,
  2803. entityCollection,
  2804. );
  2805. processPacketData(
  2806. Number,
  2807. ellipsoid,
  2808. "outlineWidth",
  2809. ellipsoidData.outlineWidth,
  2810. interval,
  2811. sourceUri,
  2812. entityCollection,
  2813. );
  2814. processPacketData(
  2815. Number,
  2816. ellipsoid,
  2817. "stackPartitions",
  2818. ellipsoidData.stackPartitions,
  2819. interval,
  2820. sourceUri,
  2821. entityCollection,
  2822. );
  2823. processPacketData(
  2824. Number,
  2825. ellipsoid,
  2826. "slicePartitions",
  2827. ellipsoidData.slicePartitions,
  2828. interval,
  2829. sourceUri,
  2830. entityCollection,
  2831. );
  2832. processPacketData(
  2833. Number,
  2834. ellipsoid,
  2835. "subdivisions",
  2836. ellipsoidData.subdivisions,
  2837. interval,
  2838. sourceUri,
  2839. entityCollection,
  2840. );
  2841. processPacketData(
  2842. ShadowMode,
  2843. ellipsoid,
  2844. "shadows",
  2845. ellipsoidData.shadows,
  2846. interval,
  2847. sourceUri,
  2848. entityCollection,
  2849. );
  2850. processPacketData(
  2851. DistanceDisplayCondition,
  2852. ellipsoid,
  2853. "distanceDisplayCondition",
  2854. ellipsoidData.distanceDisplayCondition,
  2855. interval,
  2856. sourceUri,
  2857. entityCollection,
  2858. );
  2859. }
  2860. function processLabel(entity, packet, entityCollection, sourceUri) {
  2861. const labelData = packet.label;
  2862. if (!defined(labelData)) {
  2863. return;
  2864. }
  2865. const interval = intervalFromString(labelData.interval);
  2866. let label = entity.label;
  2867. if (!defined(label)) {
  2868. entity.label = label = new LabelGraphics();
  2869. }
  2870. processPacketData(
  2871. Boolean,
  2872. label,
  2873. "show",
  2874. labelData.show,
  2875. interval,
  2876. sourceUri,
  2877. entityCollection,
  2878. );
  2879. processPacketData(
  2880. String,
  2881. label,
  2882. "text",
  2883. labelData.text,
  2884. interval,
  2885. sourceUri,
  2886. entityCollection,
  2887. );
  2888. processPacketData(
  2889. String,
  2890. label,
  2891. "font",
  2892. labelData.font,
  2893. interval,
  2894. sourceUri,
  2895. entityCollection,
  2896. );
  2897. processPacketData(
  2898. LabelStyle,
  2899. label,
  2900. "style",
  2901. labelData.style,
  2902. interval,
  2903. sourceUri,
  2904. entityCollection,
  2905. );
  2906. processPacketData(
  2907. Number,
  2908. label,
  2909. "scale",
  2910. labelData.scale,
  2911. interval,
  2912. sourceUri,
  2913. entityCollection,
  2914. );
  2915. processPacketData(
  2916. Boolean,
  2917. label,
  2918. "showBackground",
  2919. labelData.showBackground,
  2920. interval,
  2921. sourceUri,
  2922. entityCollection,
  2923. );
  2924. processPacketData(
  2925. Color,
  2926. label,
  2927. "backgroundColor",
  2928. labelData.backgroundColor,
  2929. interval,
  2930. sourceUri,
  2931. entityCollection,
  2932. );
  2933. processPacketData(
  2934. Cartesian2,
  2935. label,
  2936. "backgroundPadding",
  2937. labelData.backgroundPadding,
  2938. interval,
  2939. sourceUri,
  2940. entityCollection,
  2941. );
  2942. processPacketData(
  2943. Cartesian2,
  2944. label,
  2945. "pixelOffset",
  2946. labelData.pixelOffset,
  2947. interval,
  2948. sourceUri,
  2949. entityCollection,
  2950. );
  2951. processPacketData(
  2952. Cartesian3,
  2953. label,
  2954. "eyeOffset",
  2955. labelData.eyeOffset,
  2956. interval,
  2957. sourceUri,
  2958. entityCollection,
  2959. );
  2960. processPacketData(
  2961. HorizontalOrigin,
  2962. label,
  2963. "horizontalOrigin",
  2964. labelData.horizontalOrigin,
  2965. interval,
  2966. sourceUri,
  2967. entityCollection,
  2968. );
  2969. processPacketData(
  2970. VerticalOrigin,
  2971. label,
  2972. "verticalOrigin",
  2973. labelData.verticalOrigin,
  2974. interval,
  2975. sourceUri,
  2976. entityCollection,
  2977. );
  2978. processPacketData(
  2979. HeightReference,
  2980. label,
  2981. "heightReference",
  2982. labelData.heightReference,
  2983. interval,
  2984. sourceUri,
  2985. entityCollection,
  2986. );
  2987. processPacketData(
  2988. Color,
  2989. label,
  2990. "fillColor",
  2991. labelData.fillColor,
  2992. interval,
  2993. sourceUri,
  2994. entityCollection,
  2995. );
  2996. processPacketData(
  2997. Color,
  2998. label,
  2999. "outlineColor",
  3000. labelData.outlineColor,
  3001. interval,
  3002. sourceUri,
  3003. entityCollection,
  3004. );
  3005. processPacketData(
  3006. Number,
  3007. label,
  3008. "outlineWidth",
  3009. labelData.outlineWidth,
  3010. interval,
  3011. sourceUri,
  3012. entityCollection,
  3013. );
  3014. processPacketData(
  3015. NearFarScalar,
  3016. label,
  3017. "translucencyByDistance",
  3018. labelData.translucencyByDistance,
  3019. interval,
  3020. sourceUri,
  3021. entityCollection,
  3022. );
  3023. processPacketData(
  3024. NearFarScalar,
  3025. label,
  3026. "pixelOffsetScaleByDistance",
  3027. labelData.pixelOffsetScaleByDistance,
  3028. interval,
  3029. sourceUri,
  3030. entityCollection,
  3031. );
  3032. processPacketData(
  3033. NearFarScalar,
  3034. label,
  3035. "scaleByDistance",
  3036. labelData.scaleByDistance,
  3037. interval,
  3038. sourceUri,
  3039. entityCollection,
  3040. );
  3041. processPacketData(
  3042. DistanceDisplayCondition,
  3043. label,
  3044. "distanceDisplayCondition",
  3045. labelData.distanceDisplayCondition,
  3046. interval,
  3047. sourceUri,
  3048. entityCollection,
  3049. );
  3050. processPacketData(
  3051. Number,
  3052. label,
  3053. "disableDepthTestDistance",
  3054. labelData.disableDepthTestDistance,
  3055. interval,
  3056. sourceUri,
  3057. entityCollection,
  3058. );
  3059. }
  3060. function processModel(entity, packet, entityCollection, sourceUri) {
  3061. const modelData = packet.model;
  3062. if (!defined(modelData)) {
  3063. return;
  3064. }
  3065. const interval = intervalFromString(modelData.interval);
  3066. let model = entity.model;
  3067. if (!defined(model)) {
  3068. entity.model = model = new ModelGraphics();
  3069. }
  3070. processPacketData(
  3071. Boolean,
  3072. model,
  3073. "show",
  3074. modelData.show,
  3075. interval,
  3076. sourceUri,
  3077. entityCollection,
  3078. );
  3079. processPacketData(
  3080. Uri,
  3081. model,
  3082. "uri",
  3083. modelData.gltf,
  3084. interval,
  3085. sourceUri,
  3086. entityCollection,
  3087. );
  3088. processPacketData(
  3089. Number,
  3090. model,
  3091. "scale",
  3092. modelData.scale,
  3093. interval,
  3094. sourceUri,
  3095. entityCollection,
  3096. );
  3097. processPacketData(
  3098. Number,
  3099. model,
  3100. "minimumPixelSize",
  3101. modelData.minimumPixelSize,
  3102. interval,
  3103. sourceUri,
  3104. entityCollection,
  3105. );
  3106. processPacketData(
  3107. Number,
  3108. model,
  3109. "maximumScale",
  3110. modelData.maximumScale,
  3111. interval,
  3112. sourceUri,
  3113. entityCollection,
  3114. );
  3115. processPacketData(
  3116. Boolean,
  3117. model,
  3118. "incrementallyLoadTextures",
  3119. modelData.incrementallyLoadTextures,
  3120. interval,
  3121. sourceUri,
  3122. entityCollection,
  3123. );
  3124. processPacketData(
  3125. Boolean,
  3126. model,
  3127. "runAnimations",
  3128. modelData.runAnimations,
  3129. interval,
  3130. sourceUri,
  3131. entityCollection,
  3132. );
  3133. processPacketData(
  3134. Boolean,
  3135. model,
  3136. "clampAnimations",
  3137. modelData.clampAnimations,
  3138. interval,
  3139. sourceUri,
  3140. entityCollection,
  3141. );
  3142. processPacketData(
  3143. ShadowMode,
  3144. model,
  3145. "shadows",
  3146. modelData.shadows,
  3147. interval,
  3148. sourceUri,
  3149. entityCollection,
  3150. );
  3151. processPacketData(
  3152. HeightReference,
  3153. model,
  3154. "heightReference",
  3155. modelData.heightReference,
  3156. interval,
  3157. sourceUri,
  3158. entityCollection,
  3159. );
  3160. processPacketData(
  3161. Color,
  3162. model,
  3163. "silhouetteColor",
  3164. modelData.silhouetteColor,
  3165. interval,
  3166. sourceUri,
  3167. entityCollection,
  3168. );
  3169. processPacketData(
  3170. Number,
  3171. model,
  3172. "silhouetteSize",
  3173. modelData.silhouetteSize,
  3174. interval,
  3175. sourceUri,
  3176. entityCollection,
  3177. );
  3178. processPacketData(
  3179. Color,
  3180. model,
  3181. "color",
  3182. modelData.color,
  3183. interval,
  3184. sourceUri,
  3185. entityCollection,
  3186. );
  3187. processPacketData(
  3188. ColorBlendMode,
  3189. model,
  3190. "colorBlendMode",
  3191. modelData.colorBlendMode,
  3192. interval,
  3193. sourceUri,
  3194. entityCollection,
  3195. );
  3196. processPacketData(
  3197. Number,
  3198. model,
  3199. "colorBlendAmount",
  3200. modelData.colorBlendAmount,
  3201. interval,
  3202. sourceUri,
  3203. entityCollection,
  3204. );
  3205. processPacketData(
  3206. DistanceDisplayCondition,
  3207. model,
  3208. "distanceDisplayCondition",
  3209. modelData.distanceDisplayCondition,
  3210. interval,
  3211. sourceUri,
  3212. entityCollection,
  3213. );
  3214. let i, len;
  3215. const nodeTransformationsData = modelData.nodeTransformations;
  3216. if (defined(nodeTransformationsData)) {
  3217. if (Array.isArray(nodeTransformationsData)) {
  3218. for (i = 0, len = nodeTransformationsData.length; i < len; ++i) {
  3219. processNodeTransformations(
  3220. model,
  3221. nodeTransformationsData[i],
  3222. interval,
  3223. sourceUri,
  3224. entityCollection,
  3225. );
  3226. }
  3227. } else {
  3228. processNodeTransformations(
  3229. model,
  3230. nodeTransformationsData,
  3231. interval,
  3232. sourceUri,
  3233. entityCollection,
  3234. );
  3235. }
  3236. }
  3237. const articulationsData = modelData.articulations;
  3238. if (defined(articulationsData)) {
  3239. if (Array.isArray(articulationsData)) {
  3240. for (i = 0, len = articulationsData.length; i < len; ++i) {
  3241. processArticulations(
  3242. model,
  3243. articulationsData[i],
  3244. interval,
  3245. sourceUri,
  3246. entityCollection,
  3247. );
  3248. }
  3249. } else {
  3250. processArticulations(
  3251. model,
  3252. articulationsData,
  3253. interval,
  3254. sourceUri,
  3255. entityCollection,
  3256. );
  3257. }
  3258. }
  3259. }
  3260. function processNodeTransformations(
  3261. model,
  3262. nodeTransformationsData,
  3263. constrainedInterval,
  3264. sourceUri,
  3265. entityCollection,
  3266. ) {
  3267. let combinedInterval = intervalFromString(nodeTransformationsData.interval);
  3268. if (defined(constrainedInterval)) {
  3269. if (defined(combinedInterval)) {
  3270. combinedInterval = TimeInterval.intersect(
  3271. combinedInterval,
  3272. constrainedInterval,
  3273. scratchTimeInterval,
  3274. );
  3275. } else {
  3276. combinedInterval = constrainedInterval;
  3277. }
  3278. }
  3279. let nodeTransformations = model.nodeTransformations;
  3280. const nodeNames = Object.keys(nodeTransformationsData);
  3281. for (let i = 0, len = nodeNames.length; i < len; ++i) {
  3282. const nodeName = nodeNames[i];
  3283. if (nodeName === "interval") {
  3284. continue;
  3285. }
  3286. const nodeTransformationData = nodeTransformationsData[nodeName];
  3287. if (!defined(nodeTransformationData)) {
  3288. continue;
  3289. }
  3290. if (!defined(nodeTransformations)) {
  3291. model.nodeTransformations = nodeTransformations = new PropertyBag();
  3292. }
  3293. if (!nodeTransformations.hasProperty(nodeName)) {
  3294. nodeTransformations.addProperty(nodeName);
  3295. }
  3296. let nodeTransformation = nodeTransformations[nodeName];
  3297. if (!defined(nodeTransformation)) {
  3298. nodeTransformations[nodeName] = nodeTransformation =
  3299. new NodeTransformationProperty();
  3300. }
  3301. processPacketData(
  3302. Cartesian3,
  3303. nodeTransformation,
  3304. "translation",
  3305. nodeTransformationData.translation,
  3306. combinedInterval,
  3307. sourceUri,
  3308. entityCollection,
  3309. );
  3310. processPacketData(
  3311. Quaternion,
  3312. nodeTransformation,
  3313. "rotation",
  3314. nodeTransformationData.rotation,
  3315. combinedInterval,
  3316. sourceUri,
  3317. entityCollection,
  3318. );
  3319. processPacketData(
  3320. Cartesian3,
  3321. nodeTransformation,
  3322. "scale",
  3323. nodeTransformationData.scale,
  3324. combinedInterval,
  3325. sourceUri,
  3326. entityCollection,
  3327. );
  3328. }
  3329. }
  3330. function processArticulations(
  3331. model,
  3332. articulationsData,
  3333. constrainedInterval,
  3334. sourceUri,
  3335. entityCollection,
  3336. ) {
  3337. let combinedInterval = intervalFromString(articulationsData.interval);
  3338. if (defined(constrainedInterval)) {
  3339. if (defined(combinedInterval)) {
  3340. combinedInterval = TimeInterval.intersect(
  3341. combinedInterval,
  3342. constrainedInterval,
  3343. scratchTimeInterval,
  3344. );
  3345. } else {
  3346. combinedInterval = constrainedInterval;
  3347. }
  3348. }
  3349. let articulations = model.articulations;
  3350. const keys = Object.keys(articulationsData);
  3351. for (let i = 0, len = keys.length; i < len; ++i) {
  3352. const key = keys[i];
  3353. if (key === "interval") {
  3354. continue;
  3355. }
  3356. const articulationStageData = articulationsData[key];
  3357. if (!defined(articulationStageData)) {
  3358. continue;
  3359. }
  3360. if (!defined(articulations)) {
  3361. model.articulations = articulations = new PropertyBag();
  3362. }
  3363. if (!articulations.hasProperty(key)) {
  3364. articulations.addProperty(key);
  3365. }
  3366. processPacketData(
  3367. Number,
  3368. articulations,
  3369. key,
  3370. articulationStageData,
  3371. combinedInterval,
  3372. sourceUri,
  3373. entityCollection,
  3374. );
  3375. }
  3376. }
  3377. function processPath(entity, packet, entityCollection, sourceUri) {
  3378. const pathData = packet.path;
  3379. if (!defined(pathData)) {
  3380. return;
  3381. }
  3382. const interval = intervalFromString(pathData.interval);
  3383. let path = entity.path;
  3384. if (!defined(path)) {
  3385. entity.path = path = new PathGraphics();
  3386. }
  3387. processPacketData(
  3388. Boolean,
  3389. path,
  3390. "show",
  3391. pathData.show,
  3392. interval,
  3393. sourceUri,
  3394. entityCollection,
  3395. );
  3396. processPacketData(
  3397. Number,
  3398. path,
  3399. "leadTime",
  3400. pathData.leadTime,
  3401. interval,
  3402. sourceUri,
  3403. entityCollection,
  3404. );
  3405. processPacketData(
  3406. Number,
  3407. path,
  3408. "trailTime",
  3409. pathData.trailTime,
  3410. interval,
  3411. sourceUri,
  3412. entityCollection,
  3413. );
  3414. processPacketData(
  3415. Number,
  3416. path,
  3417. "width",
  3418. pathData.width,
  3419. interval,
  3420. sourceUri,
  3421. entityCollection,
  3422. );
  3423. processPacketData(
  3424. Number,
  3425. path,
  3426. "resolution",
  3427. pathData.resolution,
  3428. interval,
  3429. sourceUri,
  3430. entityCollection,
  3431. );
  3432. processMaterialPacketData(
  3433. path,
  3434. "material",
  3435. pathData.material,
  3436. interval,
  3437. sourceUri,
  3438. entityCollection,
  3439. );
  3440. processPacketData(
  3441. DistanceDisplayCondition,
  3442. path,
  3443. "distanceDisplayCondition",
  3444. pathData.distanceDisplayCondition,
  3445. interval,
  3446. sourceUri,
  3447. entityCollection,
  3448. );
  3449. processPacketData(
  3450. String,
  3451. path,
  3452. "relativeTo",
  3453. pathData.relativeTo,
  3454. interval,
  3455. sourceUri,
  3456. entityCollection,
  3457. );
  3458. }
  3459. function processPoint(entity, packet, entityCollection, sourceUri) {
  3460. const pointData = packet.point;
  3461. if (!defined(pointData)) {
  3462. return;
  3463. }
  3464. const interval = intervalFromString(pointData.interval);
  3465. let point = entity.point;
  3466. if (!defined(point)) {
  3467. entity.point = point = new PointGraphics();
  3468. }
  3469. processPacketData(
  3470. Boolean,
  3471. point,
  3472. "show",
  3473. pointData.show,
  3474. interval,
  3475. sourceUri,
  3476. entityCollection,
  3477. );
  3478. processPacketData(
  3479. Number,
  3480. point,
  3481. "pixelSize",
  3482. pointData.pixelSize,
  3483. interval,
  3484. sourceUri,
  3485. entityCollection,
  3486. );
  3487. processPacketData(
  3488. HeightReference,
  3489. point,
  3490. "heightReference",
  3491. pointData.heightReference,
  3492. interval,
  3493. sourceUri,
  3494. entityCollection,
  3495. );
  3496. processPacketData(
  3497. Color,
  3498. point,
  3499. "color",
  3500. pointData.color,
  3501. interval,
  3502. sourceUri,
  3503. entityCollection,
  3504. );
  3505. processPacketData(
  3506. Color,
  3507. point,
  3508. "outlineColor",
  3509. pointData.outlineColor,
  3510. interval,
  3511. sourceUri,
  3512. entityCollection,
  3513. );
  3514. processPacketData(
  3515. Number,
  3516. point,
  3517. "outlineWidth",
  3518. pointData.outlineWidth,
  3519. interval,
  3520. sourceUri,
  3521. entityCollection,
  3522. );
  3523. processPacketData(
  3524. NearFarScalar,
  3525. point,
  3526. "scaleByDistance",
  3527. pointData.scaleByDistance,
  3528. interval,
  3529. sourceUri,
  3530. entityCollection,
  3531. );
  3532. processPacketData(
  3533. NearFarScalar,
  3534. point,
  3535. "translucencyByDistance",
  3536. pointData.translucencyByDistance,
  3537. interval,
  3538. sourceUri,
  3539. entityCollection,
  3540. );
  3541. processPacketData(
  3542. DistanceDisplayCondition,
  3543. point,
  3544. "distanceDisplayCondition",
  3545. pointData.distanceDisplayCondition,
  3546. interval,
  3547. sourceUri,
  3548. entityCollection,
  3549. );
  3550. processPacketData(
  3551. Number,
  3552. point,
  3553. "disableDepthTestDistance",
  3554. pointData.disableDepthTestDistance,
  3555. interval,
  3556. sourceUri,
  3557. entityCollection,
  3558. );
  3559. }
  3560. function PolygonHierarchyProperty(polygon) {
  3561. this.polygon = polygon;
  3562. this._definitionChanged = new Event();
  3563. }
  3564. Object.defineProperties(PolygonHierarchyProperty.prototype, {
  3565. isConstant: {
  3566. get: function () {
  3567. const positions = this.polygon._positions;
  3568. const holes = this.polygon._holes;
  3569. return (
  3570. (!defined(positions) || positions.isConstant) &&
  3571. (!defined(holes) || holes.isConstant)
  3572. );
  3573. },
  3574. },
  3575. definitionChanged: {
  3576. get: function () {
  3577. return this._definitionChanged;
  3578. },
  3579. },
  3580. });
  3581. PolygonHierarchyProperty.prototype.getValue = function (time, result) {
  3582. let positions;
  3583. if (defined(this.polygon._positions)) {
  3584. positions = this.polygon._positions.getValue(time);
  3585. }
  3586. let holes;
  3587. if (defined(this.polygon._holes)) {
  3588. holes = this.polygon._holes.getValue(time);
  3589. if (defined(holes)) {
  3590. holes = holes.map(function (holePositions) {
  3591. return new PolygonHierarchy(holePositions);
  3592. });
  3593. }
  3594. }
  3595. if (!defined(result)) {
  3596. return new PolygonHierarchy(positions, holes);
  3597. }
  3598. result.positions = positions;
  3599. result.holes = holes;
  3600. return result;
  3601. };
  3602. PolygonHierarchyProperty.prototype.equals = function (other) {
  3603. return (
  3604. this === other ||
  3605. (other instanceof PolygonHierarchyProperty &&
  3606. Property.equals(this.polygon._positions, other.polygon._positions) &&
  3607. Property.equals(this.polygon._holes, other.polygon._holes))
  3608. );
  3609. };
  3610. function processPolygon(entity, packet, entityCollection, sourceUri) {
  3611. const polygonData = packet.polygon;
  3612. if (!defined(polygonData)) {
  3613. return;
  3614. }
  3615. const interval = intervalFromString(polygonData.interval);
  3616. let polygon = entity.polygon;
  3617. if (!defined(polygon)) {
  3618. entity.polygon = polygon = new PolygonGraphics();
  3619. }
  3620. processPacketData(
  3621. Boolean,
  3622. polygon,
  3623. "show",
  3624. polygonData.show,
  3625. interval,
  3626. sourceUri,
  3627. entityCollection,
  3628. );
  3629. // adapt 'position' property producing Cartesian[]
  3630. // and 'holes' property producing Cartesian[][]
  3631. // to a single property producing PolygonHierarchy
  3632. processPositionArray(
  3633. polygon,
  3634. "_positions",
  3635. polygonData.positions,
  3636. entityCollection,
  3637. );
  3638. processPositionArrayOfArrays(
  3639. polygon,
  3640. "_holes",
  3641. polygonData.holes,
  3642. entityCollection,
  3643. );
  3644. if (defined(polygon._positions) || defined(polygon._holes)) {
  3645. polygon.hierarchy = new PolygonHierarchyProperty(polygon);
  3646. }
  3647. processPacketData(
  3648. Number,
  3649. polygon,
  3650. "height",
  3651. polygonData.height,
  3652. interval,
  3653. sourceUri,
  3654. entityCollection,
  3655. );
  3656. processPacketData(
  3657. HeightReference,
  3658. polygon,
  3659. "heightReference",
  3660. polygonData.heightReference,
  3661. interval,
  3662. sourceUri,
  3663. entityCollection,
  3664. );
  3665. processPacketData(
  3666. Number,
  3667. polygon,
  3668. "extrudedHeight",
  3669. polygonData.extrudedHeight,
  3670. interval,
  3671. sourceUri,
  3672. entityCollection,
  3673. );
  3674. processPacketData(
  3675. HeightReference,
  3676. polygon,
  3677. "extrudedHeightReference",
  3678. polygonData.extrudedHeightReference,
  3679. interval,
  3680. sourceUri,
  3681. entityCollection,
  3682. );
  3683. processPacketData(
  3684. Rotation,
  3685. polygon,
  3686. "stRotation",
  3687. polygonData.stRotation,
  3688. interval,
  3689. sourceUri,
  3690. entityCollection,
  3691. );
  3692. processPacketData(
  3693. Number,
  3694. polygon,
  3695. "granularity",
  3696. polygonData.granularity,
  3697. interval,
  3698. sourceUri,
  3699. entityCollection,
  3700. );
  3701. processPacketData(
  3702. Boolean,
  3703. polygon,
  3704. "fill",
  3705. polygonData.fill,
  3706. interval,
  3707. sourceUri,
  3708. entityCollection,
  3709. );
  3710. processMaterialPacketData(
  3711. polygon,
  3712. "material",
  3713. polygonData.material,
  3714. interval,
  3715. sourceUri,
  3716. entityCollection,
  3717. );
  3718. processPacketData(
  3719. Boolean,
  3720. polygon,
  3721. "outline",
  3722. polygonData.outline,
  3723. interval,
  3724. sourceUri,
  3725. entityCollection,
  3726. );
  3727. processPacketData(
  3728. Color,
  3729. polygon,
  3730. "outlineColor",
  3731. polygonData.outlineColor,
  3732. interval,
  3733. sourceUri,
  3734. entityCollection,
  3735. );
  3736. processPacketData(
  3737. Number,
  3738. polygon,
  3739. "outlineWidth",
  3740. polygonData.outlineWidth,
  3741. interval,
  3742. sourceUri,
  3743. entityCollection,
  3744. );
  3745. processPacketData(
  3746. Boolean,
  3747. polygon,
  3748. "perPositionHeight",
  3749. polygonData.perPositionHeight,
  3750. interval,
  3751. sourceUri,
  3752. entityCollection,
  3753. );
  3754. processPacketData(
  3755. Boolean,
  3756. polygon,
  3757. "closeTop",
  3758. polygonData.closeTop,
  3759. interval,
  3760. sourceUri,
  3761. entityCollection,
  3762. );
  3763. processPacketData(
  3764. Boolean,
  3765. polygon,
  3766. "closeBottom",
  3767. polygonData.closeBottom,
  3768. interval,
  3769. sourceUri,
  3770. entityCollection,
  3771. );
  3772. processPacketData(
  3773. ArcType,
  3774. polygon,
  3775. "arcType",
  3776. polygonData.arcType,
  3777. interval,
  3778. sourceUri,
  3779. entityCollection,
  3780. );
  3781. processPacketData(
  3782. ShadowMode,
  3783. polygon,
  3784. "shadows",
  3785. polygonData.shadows,
  3786. interval,
  3787. sourceUri,
  3788. entityCollection,
  3789. );
  3790. processPacketData(
  3791. DistanceDisplayCondition,
  3792. polygon,
  3793. "distanceDisplayCondition",
  3794. polygonData.distanceDisplayCondition,
  3795. interval,
  3796. sourceUri,
  3797. entityCollection,
  3798. );
  3799. processPacketData(
  3800. ClassificationType,
  3801. polygon,
  3802. "classificationType",
  3803. polygonData.classificationType,
  3804. interval,
  3805. sourceUri,
  3806. entityCollection,
  3807. );
  3808. processPacketData(
  3809. Number,
  3810. polygon,
  3811. "zIndex",
  3812. polygonData.zIndex,
  3813. interval,
  3814. sourceUri,
  3815. entityCollection,
  3816. );
  3817. }
  3818. function adaptFollowSurfaceToArcType(followSurface) {
  3819. return followSurface ? ArcType.GEODESIC : ArcType.NONE;
  3820. }
  3821. function processPolyline(entity, packet, entityCollection, sourceUri) {
  3822. const polylineData = packet.polyline;
  3823. if (!defined(polylineData)) {
  3824. return;
  3825. }
  3826. const interval = intervalFromString(polylineData.interval);
  3827. let polyline = entity.polyline;
  3828. if (!defined(polyline)) {
  3829. entity.polyline = polyline = new PolylineGraphics();
  3830. }
  3831. processPacketData(
  3832. Boolean,
  3833. polyline,
  3834. "show",
  3835. polylineData.show,
  3836. interval,
  3837. sourceUri,
  3838. entityCollection,
  3839. );
  3840. processPositionArray(
  3841. polyline,
  3842. "positions",
  3843. polylineData.positions,
  3844. entityCollection,
  3845. );
  3846. processPacketData(
  3847. Number,
  3848. polyline,
  3849. "width",
  3850. polylineData.width,
  3851. interval,
  3852. sourceUri,
  3853. entityCollection,
  3854. );
  3855. processPacketData(
  3856. Number,
  3857. polyline,
  3858. "granularity",
  3859. polylineData.granularity,
  3860. interval,
  3861. sourceUri,
  3862. entityCollection,
  3863. );
  3864. processMaterialPacketData(
  3865. polyline,
  3866. "material",
  3867. polylineData.material,
  3868. interval,
  3869. sourceUri,
  3870. entityCollection,
  3871. );
  3872. processMaterialPacketData(
  3873. polyline,
  3874. "depthFailMaterial",
  3875. polylineData.depthFailMaterial,
  3876. interval,
  3877. sourceUri,
  3878. entityCollection,
  3879. );
  3880. processPacketData(
  3881. ArcType,
  3882. polyline,
  3883. "arcType",
  3884. polylineData.arcType,
  3885. interval,
  3886. sourceUri,
  3887. entityCollection,
  3888. );
  3889. processPacketData(
  3890. Boolean,
  3891. polyline,
  3892. "clampToGround",
  3893. polylineData.clampToGround,
  3894. interval,
  3895. sourceUri,
  3896. entityCollection,
  3897. );
  3898. processPacketData(
  3899. ShadowMode,
  3900. polyline,
  3901. "shadows",
  3902. polylineData.shadows,
  3903. interval,
  3904. sourceUri,
  3905. entityCollection,
  3906. );
  3907. processPacketData(
  3908. DistanceDisplayCondition,
  3909. polyline,
  3910. "distanceDisplayCondition",
  3911. polylineData.distanceDisplayCondition,
  3912. interval,
  3913. sourceUri,
  3914. entityCollection,
  3915. );
  3916. processPacketData(
  3917. ClassificationType,
  3918. polyline,
  3919. "classificationType",
  3920. polylineData.classificationType,
  3921. interval,
  3922. sourceUri,
  3923. entityCollection,
  3924. );
  3925. processPacketData(
  3926. Number,
  3927. polyline,
  3928. "zIndex",
  3929. polylineData.zIndex,
  3930. interval,
  3931. sourceUri,
  3932. entityCollection,
  3933. );
  3934. // for backwards compatibility, adapt CZML followSurface to arcType.
  3935. if (defined(polylineData.followSurface) && !defined(polylineData.arcType)) {
  3936. const tempObj = {};
  3937. processPacketData(
  3938. Boolean,
  3939. tempObj,
  3940. "followSurface",
  3941. polylineData.followSurface,
  3942. interval,
  3943. sourceUri,
  3944. entityCollection,
  3945. );
  3946. polyline.arcType = createAdapterProperty(
  3947. tempObj.followSurface,
  3948. adaptFollowSurfaceToArcType,
  3949. );
  3950. }
  3951. }
  3952. function processPolylineVolume(entity, packet, entityCollection, sourceUri) {
  3953. const polylineVolumeData = packet.polylineVolume;
  3954. if (!defined(polylineVolumeData)) {
  3955. return;
  3956. }
  3957. const interval = intervalFromString(polylineVolumeData.interval);
  3958. let polylineVolume = entity.polylineVolume;
  3959. if (!defined(polylineVolume)) {
  3960. entity.polylineVolume = polylineVolume = new PolylineVolumeGraphics();
  3961. }
  3962. processPositionArray(
  3963. polylineVolume,
  3964. "positions",
  3965. polylineVolumeData.positions,
  3966. entityCollection,
  3967. );
  3968. processShape(
  3969. polylineVolume,
  3970. "shape",
  3971. polylineVolumeData.shape,
  3972. entityCollection,
  3973. );
  3974. processPacketData(
  3975. Boolean,
  3976. polylineVolume,
  3977. "show",
  3978. polylineVolumeData.show,
  3979. interval,
  3980. sourceUri,
  3981. entityCollection,
  3982. );
  3983. processPacketData(
  3984. CornerType,
  3985. polylineVolume,
  3986. "cornerType",
  3987. polylineVolumeData.cornerType,
  3988. interval,
  3989. sourceUri,
  3990. entityCollection,
  3991. );
  3992. processPacketData(
  3993. Boolean,
  3994. polylineVolume,
  3995. "fill",
  3996. polylineVolumeData.fill,
  3997. interval,
  3998. sourceUri,
  3999. entityCollection,
  4000. );
  4001. processMaterialPacketData(
  4002. polylineVolume,
  4003. "material",
  4004. polylineVolumeData.material,
  4005. interval,
  4006. sourceUri,
  4007. entityCollection,
  4008. );
  4009. processPacketData(
  4010. Boolean,
  4011. polylineVolume,
  4012. "outline",
  4013. polylineVolumeData.outline,
  4014. interval,
  4015. sourceUri,
  4016. entityCollection,
  4017. );
  4018. processPacketData(
  4019. Color,
  4020. polylineVolume,
  4021. "outlineColor",
  4022. polylineVolumeData.outlineColor,
  4023. interval,
  4024. sourceUri,
  4025. entityCollection,
  4026. );
  4027. processPacketData(
  4028. Number,
  4029. polylineVolume,
  4030. "outlineWidth",
  4031. polylineVolumeData.outlineWidth,
  4032. interval,
  4033. sourceUri,
  4034. entityCollection,
  4035. );
  4036. processPacketData(
  4037. Number,
  4038. polylineVolume,
  4039. "granularity",
  4040. polylineVolumeData.granularity,
  4041. interval,
  4042. sourceUri,
  4043. entityCollection,
  4044. );
  4045. processPacketData(
  4046. ShadowMode,
  4047. polylineVolume,
  4048. "shadows",
  4049. polylineVolumeData.shadows,
  4050. interval,
  4051. sourceUri,
  4052. entityCollection,
  4053. );
  4054. processPacketData(
  4055. DistanceDisplayCondition,
  4056. polylineVolume,
  4057. "distanceDisplayCondition",
  4058. polylineVolumeData.distanceDisplayCondition,
  4059. interval,
  4060. sourceUri,
  4061. entityCollection,
  4062. );
  4063. }
  4064. function processRectangle(entity, packet, entityCollection, sourceUri) {
  4065. const rectangleData = packet.rectangle;
  4066. if (!defined(rectangleData)) {
  4067. return;
  4068. }
  4069. const interval = intervalFromString(rectangleData.interval);
  4070. let rectangle = entity.rectangle;
  4071. if (!defined(rectangle)) {
  4072. entity.rectangle = rectangle = new RectangleGraphics();
  4073. }
  4074. processPacketData(
  4075. Boolean,
  4076. rectangle,
  4077. "show",
  4078. rectangleData.show,
  4079. interval,
  4080. sourceUri,
  4081. entityCollection,
  4082. );
  4083. processPacketData(
  4084. Rectangle,
  4085. rectangle,
  4086. "coordinates",
  4087. rectangleData.coordinates,
  4088. interval,
  4089. sourceUri,
  4090. entityCollection,
  4091. );
  4092. processPacketData(
  4093. Number,
  4094. rectangle,
  4095. "height",
  4096. rectangleData.height,
  4097. interval,
  4098. sourceUri,
  4099. entityCollection,
  4100. );
  4101. processPacketData(
  4102. HeightReference,
  4103. rectangle,
  4104. "heightReference",
  4105. rectangleData.heightReference,
  4106. interval,
  4107. sourceUri,
  4108. entityCollection,
  4109. );
  4110. processPacketData(
  4111. Number,
  4112. rectangle,
  4113. "extrudedHeight",
  4114. rectangleData.extrudedHeight,
  4115. interval,
  4116. sourceUri,
  4117. entityCollection,
  4118. );
  4119. processPacketData(
  4120. HeightReference,
  4121. rectangle,
  4122. "extrudedHeightReference",
  4123. rectangleData.extrudedHeightReference,
  4124. interval,
  4125. sourceUri,
  4126. entityCollection,
  4127. );
  4128. processPacketData(
  4129. Rotation,
  4130. rectangle,
  4131. "rotation",
  4132. rectangleData.rotation,
  4133. interval,
  4134. sourceUri,
  4135. entityCollection,
  4136. );
  4137. processPacketData(
  4138. Rotation,
  4139. rectangle,
  4140. "stRotation",
  4141. rectangleData.stRotation,
  4142. interval,
  4143. sourceUri,
  4144. entityCollection,
  4145. );
  4146. processPacketData(
  4147. Number,
  4148. rectangle,
  4149. "granularity",
  4150. rectangleData.granularity,
  4151. interval,
  4152. sourceUri,
  4153. entityCollection,
  4154. );
  4155. processPacketData(
  4156. Boolean,
  4157. rectangle,
  4158. "fill",
  4159. rectangleData.fill,
  4160. interval,
  4161. sourceUri,
  4162. entityCollection,
  4163. );
  4164. processMaterialPacketData(
  4165. rectangle,
  4166. "material",
  4167. rectangleData.material,
  4168. interval,
  4169. sourceUri,
  4170. entityCollection,
  4171. );
  4172. processPacketData(
  4173. Boolean,
  4174. rectangle,
  4175. "outline",
  4176. rectangleData.outline,
  4177. interval,
  4178. sourceUri,
  4179. entityCollection,
  4180. );
  4181. processPacketData(
  4182. Color,
  4183. rectangle,
  4184. "outlineColor",
  4185. rectangleData.outlineColor,
  4186. interval,
  4187. sourceUri,
  4188. entityCollection,
  4189. );
  4190. processPacketData(
  4191. Number,
  4192. rectangle,
  4193. "outlineWidth",
  4194. rectangleData.outlineWidth,
  4195. interval,
  4196. sourceUri,
  4197. entityCollection,
  4198. );
  4199. processPacketData(
  4200. ShadowMode,
  4201. rectangle,
  4202. "shadows",
  4203. rectangleData.shadows,
  4204. interval,
  4205. sourceUri,
  4206. entityCollection,
  4207. );
  4208. processPacketData(
  4209. DistanceDisplayCondition,
  4210. rectangle,
  4211. "distanceDisplayCondition",
  4212. rectangleData.distanceDisplayCondition,
  4213. interval,
  4214. sourceUri,
  4215. entityCollection,
  4216. );
  4217. processPacketData(
  4218. ClassificationType,
  4219. rectangle,
  4220. "classificationType",
  4221. rectangleData.classificationType,
  4222. interval,
  4223. sourceUri,
  4224. entityCollection,
  4225. );
  4226. processPacketData(
  4227. Number,
  4228. rectangle,
  4229. "zIndex",
  4230. rectangleData.zIndex,
  4231. interval,
  4232. sourceUri,
  4233. entityCollection,
  4234. );
  4235. }
  4236. function processTileset(entity, packet, entityCollection, sourceUri) {
  4237. const tilesetData = packet.tileset;
  4238. if (!defined(tilesetData)) {
  4239. return;
  4240. }
  4241. const interval = intervalFromString(tilesetData.interval);
  4242. let tileset = entity.tileset;
  4243. if (!defined(tileset)) {
  4244. entity.tileset = tileset = new Cesium3DTilesetGraphics();
  4245. }
  4246. processPacketData(
  4247. Boolean,
  4248. tileset,
  4249. "show",
  4250. tilesetData.show,
  4251. interval,
  4252. sourceUri,
  4253. entityCollection,
  4254. );
  4255. processPacketData(
  4256. Uri,
  4257. tileset,
  4258. "uri",
  4259. tilesetData.uri,
  4260. interval,
  4261. sourceUri,
  4262. entityCollection,
  4263. );
  4264. processPacketData(
  4265. Number,
  4266. tileset,
  4267. "maximumScreenSpaceError",
  4268. tilesetData.maximumScreenSpaceError,
  4269. interval,
  4270. sourceUri,
  4271. entityCollection,
  4272. );
  4273. }
  4274. function processWall(entity, packet, entityCollection, sourceUri) {
  4275. const wallData = packet.wall;
  4276. if (!defined(wallData)) {
  4277. return;
  4278. }
  4279. const interval = intervalFromString(wallData.interval);
  4280. let wall = entity.wall;
  4281. if (!defined(wall)) {
  4282. entity.wall = wall = new WallGraphics();
  4283. }
  4284. processPacketData(
  4285. Boolean,
  4286. wall,
  4287. "show",
  4288. wallData.show,
  4289. interval,
  4290. sourceUri,
  4291. entityCollection,
  4292. );
  4293. processPositionArray(wall, "positions", wallData.positions, entityCollection);
  4294. processArray(
  4295. wall,
  4296. "minimumHeights",
  4297. wallData.minimumHeights,
  4298. entityCollection,
  4299. );
  4300. processArray(
  4301. wall,
  4302. "maximumHeights",
  4303. wallData.maximumHeights,
  4304. entityCollection,
  4305. );
  4306. processPacketData(
  4307. Number,
  4308. wall,
  4309. "granularity",
  4310. wallData.granularity,
  4311. interval,
  4312. sourceUri,
  4313. entityCollection,
  4314. );
  4315. processPacketData(
  4316. Boolean,
  4317. wall,
  4318. "fill",
  4319. wallData.fill,
  4320. interval,
  4321. sourceUri,
  4322. entityCollection,
  4323. );
  4324. processMaterialPacketData(
  4325. wall,
  4326. "material",
  4327. wallData.material,
  4328. interval,
  4329. sourceUri,
  4330. entityCollection,
  4331. );
  4332. processPacketData(
  4333. Boolean,
  4334. wall,
  4335. "outline",
  4336. wallData.outline,
  4337. interval,
  4338. sourceUri,
  4339. entityCollection,
  4340. );
  4341. processPacketData(
  4342. Color,
  4343. wall,
  4344. "outlineColor",
  4345. wallData.outlineColor,
  4346. interval,
  4347. sourceUri,
  4348. entityCollection,
  4349. );
  4350. processPacketData(
  4351. Number,
  4352. wall,
  4353. "outlineWidth",
  4354. wallData.outlineWidth,
  4355. interval,
  4356. sourceUri,
  4357. entityCollection,
  4358. );
  4359. processPacketData(
  4360. ShadowMode,
  4361. wall,
  4362. "shadows",
  4363. wallData.shadows,
  4364. interval,
  4365. sourceUri,
  4366. entityCollection,
  4367. );
  4368. processPacketData(
  4369. DistanceDisplayCondition,
  4370. wall,
  4371. "distanceDisplayCondition",
  4372. wallData.distanceDisplayCondition,
  4373. interval,
  4374. sourceUri,
  4375. entityCollection,
  4376. );
  4377. }
  4378. function processCzmlPacket(
  4379. packet,
  4380. entityCollection,
  4381. updaterFunctions,
  4382. sourceUri,
  4383. dataSource,
  4384. ) {
  4385. let objectId = packet.id;
  4386. if (!defined(objectId)) {
  4387. objectId = createGuid();
  4388. }
  4389. currentId = objectId;
  4390. if (!defined(dataSource._version) && objectId !== "document") {
  4391. throw new RuntimeError(
  4392. "The first CZML packet is required to be the document object.",
  4393. );
  4394. }
  4395. if (packet["delete"] === true) {
  4396. entityCollection.removeById(objectId);
  4397. } else if (objectId === "document") {
  4398. processDocument(packet, dataSource);
  4399. } else {
  4400. const entity = entityCollection.getOrCreateEntity(objectId);
  4401. const parentId = packet.parent;
  4402. if (defined(parentId)) {
  4403. entity.parent = entityCollection.getOrCreateEntity(parentId);
  4404. }
  4405. for (let i = updaterFunctions.length - 1; i > -1; i--) {
  4406. updaterFunctions[i](entity, packet, entityCollection, sourceUri);
  4407. }
  4408. }
  4409. currentId = undefined;
  4410. }
  4411. function updateClock(dataSource) {
  4412. let clock;
  4413. const clockPacket = dataSource._documentPacket.clock;
  4414. if (!defined(clockPacket)) {
  4415. if (!defined(dataSource._clock)) {
  4416. const availability = dataSource._entityCollection.computeAvailability();
  4417. if (!availability.start.equals(Iso8601.MINIMUM_VALUE)) {
  4418. const startTime = availability.start;
  4419. const stopTime = availability.stop;
  4420. const totalSeconds = JulianDate.secondsDifference(stopTime, startTime);
  4421. const multiplier = Math.round(totalSeconds / 120.0);
  4422. clock = new DataSourceClock();
  4423. clock.startTime = JulianDate.clone(startTime);
  4424. clock.stopTime = JulianDate.clone(stopTime);
  4425. clock.clockRange = ClockRange.LOOP_STOP;
  4426. clock.multiplier = multiplier;
  4427. clock.currentTime = JulianDate.clone(startTime);
  4428. clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  4429. dataSource._clock = clock;
  4430. return true;
  4431. }
  4432. }
  4433. return false;
  4434. }
  4435. if (defined(dataSource._clock)) {
  4436. clock = dataSource._clock.clone();
  4437. } else {
  4438. clock = new DataSourceClock();
  4439. clock.startTime = Iso8601.MINIMUM_VALUE.clone();
  4440. clock.stopTime = Iso8601.MAXIMUM_VALUE.clone();
  4441. clock.currentTime = Iso8601.MINIMUM_VALUE.clone();
  4442. clock.clockRange = ClockRange.LOOP_STOP;
  4443. clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  4444. clock.multiplier = 1.0;
  4445. }
  4446. const interval = intervalFromString(clockPacket.interval);
  4447. if (defined(interval)) {
  4448. clock.startTime = interval.start;
  4449. clock.stopTime = interval.stop;
  4450. }
  4451. if (defined(clockPacket.currentTime)) {
  4452. clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime);
  4453. }
  4454. if (defined(clockPacket.range)) {
  4455. clock.clockRange = ClockRange[clockPacket.range] ?? ClockRange.LOOP_STOP;
  4456. }
  4457. if (defined(clockPacket.step)) {
  4458. clock.clockStep =
  4459. ClockStep[clockPacket.step] ?? ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  4460. }
  4461. if (defined(clockPacket.multiplier)) {
  4462. clock.multiplier = clockPacket.multiplier;
  4463. }
  4464. if (!clock.equals(dataSource._clock)) {
  4465. dataSource._clock = clock.clone(dataSource._clock);
  4466. return true;
  4467. }
  4468. return false;
  4469. }
  4470. function load(dataSource, czml, options, clear) {
  4471. //>>includeStart('debug', pragmas.debug);
  4472. if (!defined(czml)) {
  4473. throw new DeveloperError("czml is required.");
  4474. }
  4475. //>>includeEnd('debug');
  4476. options = options ?? Frozen.EMPTY_OBJECT;
  4477. let promise = czml;
  4478. let sourceUri = options.sourceUri;
  4479. // User specified credit
  4480. let credit = options.credit;
  4481. if (typeof credit === "string") {
  4482. credit = new Credit(credit);
  4483. }
  4484. dataSource._credit = credit;
  4485. // If the czml is a URL
  4486. if (typeof czml === "string" || czml instanceof Resource) {
  4487. czml = Resource.createIfNeeded(czml);
  4488. promise = czml.fetchJson();
  4489. sourceUri = sourceUri ?? czml.clone();
  4490. // Add resource credits to our list of credits to display
  4491. const resourceCredits = dataSource._resourceCredits;
  4492. const credits = czml.credits;
  4493. if (defined(credits)) {
  4494. const length = credits.length;
  4495. for (let i = 0; i < length; i++) {
  4496. resourceCredits.push(credits[i]);
  4497. }
  4498. }
  4499. }
  4500. sourceUri = Resource.createIfNeeded(sourceUri);
  4501. DataSource.setLoading(dataSource, true);
  4502. return Promise.resolve(promise)
  4503. .then(function (czml) {
  4504. return loadCzml(dataSource, czml, sourceUri, clear);
  4505. })
  4506. .catch(function (error) {
  4507. DataSource.setLoading(dataSource, false);
  4508. dataSource._error.raiseEvent(dataSource, error);
  4509. console.log(error);
  4510. return Promise.reject(error);
  4511. });
  4512. }
  4513. function loadCzml(dataSource, czml, sourceUri, clear) {
  4514. DataSource.setLoading(dataSource, true);
  4515. const entityCollection = dataSource._entityCollection;
  4516. if (clear) {
  4517. dataSource._version = undefined;
  4518. dataSource._documentPacket = new DocumentPacket();
  4519. entityCollection.removeAll();
  4520. }
  4521. CzmlDataSource._processCzml(
  4522. czml,
  4523. entityCollection,
  4524. sourceUri,
  4525. undefined,
  4526. dataSource,
  4527. );
  4528. let raiseChangedEvent = updateClock(dataSource);
  4529. const documentPacket = dataSource._documentPacket;
  4530. if (
  4531. defined(documentPacket.name) &&
  4532. dataSource._name !== documentPacket.name
  4533. ) {
  4534. dataSource._name = documentPacket.name;
  4535. raiseChangedEvent = true;
  4536. } else if (!defined(dataSource._name) && defined(sourceUri)) {
  4537. dataSource._name = getFilenameFromUri(sourceUri.getUrlComponent());
  4538. raiseChangedEvent = true;
  4539. }
  4540. DataSource.setLoading(dataSource, false);
  4541. if (raiseChangedEvent) {
  4542. dataSource._changed.raiseEvent(dataSource);
  4543. }
  4544. return dataSource;
  4545. }
  4546. function DocumentPacket() {
  4547. this.name = undefined;
  4548. this.clock = undefined;
  4549. }
  4550. /**
  4551. * @typedef {object} CzmlDataSource.LoadOptions
  4552. *
  4553. * Initialization options for the <code>load</code> method.
  4554. *
  4555. * @property {Resource|string} [sourceUri] Overrides the url to use for resolving relative links.
  4556. * @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.
  4557. */
  4558. /**
  4559. * A {@link DataSource} which processes {@link https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CZML-Guide|CZML}.
  4560. * @alias CzmlDataSource
  4561. * @constructor
  4562. *
  4563. * @param {string} [name] An optional name for the data source. This value will be overwritten if a loaded document contains a name.
  4564. *
  4565. * @demo {@link https://sandcastle.cesium.com/index.html?id=czml|Cesium Sandcastle CZML Demo}
  4566. */
  4567. function CzmlDataSource(name) {
  4568. this._name = name;
  4569. this._changed = new Event();
  4570. this._error = new Event();
  4571. this._isLoading = false;
  4572. this._loading = new Event();
  4573. this._clock = undefined;
  4574. this._documentPacket = new DocumentPacket();
  4575. this._version = undefined;
  4576. this._entityCollection = new EntityCollection(this);
  4577. this._entityCluster = new EntityCluster();
  4578. this._credit = undefined;
  4579. this._resourceCredits = [];
  4580. }
  4581. /**
  4582. * Creates a Promise to a new instance loaded with the provided CZML data.
  4583. *
  4584. * @param {Resource|string|object} czml A url or CZML object to be processed.
  4585. * @param {CzmlDataSource.LoadOptions} [options] An object specifying configuration options
  4586. *
  4587. * @returns {Promise<CzmlDataSource>} A promise that resolves to the new instance once the data is processed.
  4588. */
  4589. CzmlDataSource.load = function (czml, options) {
  4590. return new CzmlDataSource().load(czml, options);
  4591. };
  4592. Object.defineProperties(CzmlDataSource.prototype, {
  4593. /**
  4594. * Gets a human-readable name for this instance.
  4595. * @memberof CzmlDataSource.prototype
  4596. * @type {string}
  4597. */
  4598. name: {
  4599. get: function () {
  4600. return this._name;
  4601. },
  4602. },
  4603. /**
  4604. * Gets the clock settings defined by the loaded CZML. If no clock is explicitly
  4605. * defined in the CZML, the combined availability of all objects is returned. If
  4606. * only static data exists, this value is undefined.
  4607. * @memberof CzmlDataSource.prototype
  4608. * @type {DataSourceClock}
  4609. */
  4610. clock: {
  4611. get: function () {
  4612. return this._clock;
  4613. },
  4614. },
  4615. /**
  4616. * Gets the collection of {@link Entity} instances.
  4617. * @memberof CzmlDataSource.prototype
  4618. * @type {EntityCollection}
  4619. */
  4620. entities: {
  4621. get: function () {
  4622. return this._entityCollection;
  4623. },
  4624. },
  4625. /**
  4626. * Gets a value indicating if the data source is currently loading data.
  4627. * @memberof CzmlDataSource.prototype
  4628. * @type {boolean}
  4629. */
  4630. isLoading: {
  4631. get: function () {
  4632. return this._isLoading;
  4633. },
  4634. },
  4635. /**
  4636. * Gets an event that will be raised when the underlying data changes.
  4637. * @memberof CzmlDataSource.prototype
  4638. * @type {Event}
  4639. */
  4640. changedEvent: {
  4641. get: function () {
  4642. return this._changed;
  4643. },
  4644. },
  4645. /**
  4646. * Gets an event that will be raised if an error is encountered during processing.
  4647. * @memberof CzmlDataSource.prototype
  4648. * @type {Event}
  4649. */
  4650. errorEvent: {
  4651. get: function () {
  4652. return this._error;
  4653. },
  4654. },
  4655. /**
  4656. * Gets an event that will be raised when the data source either starts or stops loading.
  4657. * @memberof CzmlDataSource.prototype
  4658. * @type {Event}
  4659. */
  4660. loadingEvent: {
  4661. get: function () {
  4662. return this._loading;
  4663. },
  4664. },
  4665. /**
  4666. * Gets whether or not this data source should be displayed.
  4667. * @memberof CzmlDataSource.prototype
  4668. * @type {boolean}
  4669. */
  4670. show: {
  4671. get: function () {
  4672. return this._entityCollection.show;
  4673. },
  4674. set: function (value) {
  4675. this._entityCollection.show = value;
  4676. },
  4677. },
  4678. /**
  4679. * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.
  4680. *
  4681. * @memberof CzmlDataSource.prototype
  4682. * @type {EntityCluster}
  4683. */
  4684. clustering: {
  4685. get: function () {
  4686. return this._entityCluster;
  4687. },
  4688. set: function (value) {
  4689. //>>includeStart('debug', pragmas.debug);
  4690. if (!defined(value)) {
  4691. throw new DeveloperError("value must be defined.");
  4692. }
  4693. //>>includeEnd('debug');
  4694. this._entityCluster = value;
  4695. },
  4696. },
  4697. /**
  4698. * Gets the credit that will be displayed for the data source
  4699. * @memberof CzmlDataSource.prototype
  4700. * @type {Credit}
  4701. */
  4702. credit: {
  4703. get: function () {
  4704. return this._credit;
  4705. },
  4706. },
  4707. });
  4708. /**
  4709. * @callback CzmlDataSource.UpdaterFunction
  4710. *
  4711. * A CZML processing function that adds or updates entities in the provided
  4712. * collection based on the provided CZML packet.
  4713. *
  4714. * @param {Entity} entity
  4715. * @param {object} packet
  4716. * @param {EntityCollection} entityCollection
  4717. * @param {string} sourceUri
  4718. */
  4719. /**
  4720. * Gets the array of CZML processing functions.
  4721. * @memberof CzmlDataSource
  4722. * @type {CzmlDataSource.UpdaterFunction[]}
  4723. */
  4724. CzmlDataSource.updaters = [
  4725. processBillboard,
  4726. processBox,
  4727. processCorridor,
  4728. processCylinder,
  4729. processEllipse,
  4730. processEllipsoid,
  4731. processLabel,
  4732. processModel,
  4733. processName,
  4734. processDescription,
  4735. processPath,
  4736. processPoint,
  4737. processPolygon,
  4738. processPolyline,
  4739. processPolylineVolume,
  4740. processProperties,
  4741. processRectangle,
  4742. processPosition,
  4743. processTileset,
  4744. processViewFrom,
  4745. processWall,
  4746. processOrientation,
  4747. processAvailability,
  4748. ];
  4749. /**
  4750. * Add the provided updater to the list of updaters if not already included
  4751. * @private
  4752. * @param {CzmlDataSource.UpdaterFunction} updater
  4753. */
  4754. CzmlDataSource.registerUpdater = function (updater) {
  4755. if (!CzmlDataSource.updaters.includes(updater)) {
  4756. CzmlDataSource.updaters.push(updater);
  4757. }
  4758. };
  4759. /**
  4760. * Remove the provided updater from the list of updaters if already included
  4761. * @private
  4762. * @param {CzmlDataSource.UpdaterFunction} updater
  4763. */
  4764. CzmlDataSource.unregisterUpdater = function (updater) {
  4765. if (CzmlDataSource.updaters.includes(updater)) {
  4766. const index = CzmlDataSource.updaters.indexOf(updater);
  4767. CzmlDataSource.updaters.splice(index, 1);
  4768. }
  4769. };
  4770. /**
  4771. * Processes the provided url or CZML object without clearing any existing data.
  4772. *
  4773. * @param {Resource|string|object} czml A url or CZML object to be processed.
  4774. * @param {CzmlDataSource.LoadOptions} [options] An object specifying configuration options
  4775. *
  4776. * @returns {Promise<CzmlDataSource>} A promise that resolves to this instances once the data is processed.
  4777. */
  4778. CzmlDataSource.prototype.process = function (czml, options) {
  4779. return load(this, czml, options, false);
  4780. };
  4781. /**
  4782. * Loads the provided url or CZML object, replacing any existing data.
  4783. *
  4784. * @param {Resource|string|object} czml A url or CZML object to be processed.
  4785. * @param {CzmlDataSource.LoadOptions} [options] An object specifying configuration options
  4786. *
  4787. * @returns {Promise<CzmlDataSource>} A promise that resolves to this instances once the data is processed.
  4788. */
  4789. CzmlDataSource.prototype.load = function (czml, options) {
  4790. return load(this, czml, options, true);
  4791. };
  4792. /**
  4793. * Updates the data source to the provided time. This function is optional and
  4794. * is not required to be implemented. It is provided for data sources which
  4795. * retrieve data based on the current animation time or scene state.
  4796. * If implemented, update will be called by {@link DataSourceDisplay} once a frame.
  4797. *
  4798. * @param {JulianDate} time The simulation time.
  4799. * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.
  4800. */
  4801. CzmlDataSource.prototype.update = function (time) {
  4802. return true;
  4803. };
  4804. /**
  4805. * A helper function used by custom CZML updater functions
  4806. * which creates or updates a {@link Property} from a CZML packet.
  4807. * @function
  4808. *
  4809. * @param {Function} type The constructor function for the property being processed.
  4810. * @param {object} object The object on which the property will be added or updated.
  4811. * @param {string} propertyName The name of the property on the object.
  4812. * @param {object} packetData The CZML packet being processed.
  4813. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  4814. * @param {string} sourceUri The originating uri of the data being processed.
  4815. * @param {EntityCollection} entityCollection The collection being processsed.
  4816. */
  4817. CzmlDataSource.processPacketData = processPacketData;
  4818. /**
  4819. * A helper function used by custom CZML updater functions
  4820. * which creates or updates a {@link PositionProperty} from a CZML packet.
  4821. * @function
  4822. *
  4823. * @param {object} object The object on which the property will be added or updated.
  4824. * @param {string} propertyName The name of the property on the object.
  4825. * @param {object} packetData The CZML packet being processed.
  4826. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  4827. * @param {string} sourceUri The originating uri of the data being processed.
  4828. * @param {EntityCollection} entityCollection The collection being processsed.
  4829. */
  4830. CzmlDataSource.processPositionPacketData = processPositionPacketData;
  4831. /**
  4832. * A helper function used by custom CZML updater functions
  4833. * which creates or updates a {@link MaterialProperty} from a CZML packet.
  4834. * @function
  4835. *
  4836. * @param {object} object The object on which the property will be added or updated.
  4837. * @param {string} propertyName The name of the property on the object.
  4838. * @param {object} packetData The CZML packet being processed.
  4839. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  4840. * @param {string} sourceUri The originating uri of the data being processed.
  4841. * @param {EntityCollection} entityCollection The collection being processsed.
  4842. */
  4843. CzmlDataSource.processMaterialPacketData = processMaterialPacketData;
  4844. CzmlDataSource._processCzml = function (
  4845. czml,
  4846. entityCollection,
  4847. sourceUri,
  4848. updaterFunctions,
  4849. dataSource,
  4850. ) {
  4851. updaterFunctions = updaterFunctions ?? CzmlDataSource.updaters;
  4852. if (Array.isArray(czml)) {
  4853. for (let i = 0, len = czml.length; i < len; ++i) {
  4854. processCzmlPacket(
  4855. czml[i],
  4856. entityCollection,
  4857. updaterFunctions,
  4858. sourceUri,
  4859. dataSource,
  4860. );
  4861. }
  4862. } else {
  4863. processCzmlPacket(
  4864. czml,
  4865. entityCollection,
  4866. updaterFunctions,
  4867. sourceUri,
  4868. dataSource,
  4869. );
  4870. }
  4871. };
  4872. export default CzmlDataSource;