CzmlDataSource.js 120 KB

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