CzmlDataSource.js 120 KB

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