CzmlDataSource.js 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400
  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 defineProperties from '../Core/defineProperties.js';
  15. import DeveloperError from '../Core/DeveloperError.js';
  16. import DistanceDisplayCondition from '../Core/DistanceDisplayCondition.js';
  17. import Ellipsoid from '../Core/Ellipsoid.js';
  18. import Event from '../Core/Event.js';
  19. import ExtrapolationType from '../Core/ExtrapolationType.js';
  20. import getFilenameFromUri from '../Core/getFilenameFromUri.js';
  21. import HermitePolynomialApproximation from '../Core/HermitePolynomialApproximation.js';
  22. import isArray from '../Core/isArray.js';
  23. import Iso8601 from '../Core/Iso8601.js';
  24. import JulianDate from '../Core/JulianDate.js';
  25. import LagrangePolynomialApproximation from '../Core/LagrangePolynomialApproximation.js';
  26. import LinearApproximation from '../Core/LinearApproximation.js';
  27. import CesiumMath from '../Core/Math.js';
  28. import NearFarScalar from '../Core/NearFarScalar.js';
  29. import PolygonHierarchy from '../Core/PolygonHierarchy.js';
  30. import Quaternion from '../Core/Quaternion.js';
  31. import Rectangle from '../Core/Rectangle.js';
  32. import ReferenceFrame from '../Core/ReferenceFrame.js';
  33. import Resource from '../Core/Resource.js';
  34. import RuntimeError from '../Core/RuntimeError.js';
  35. import Spherical from '../Core/Spherical.js';
  36. import TimeInterval from '../Core/TimeInterval.js';
  37. import TimeIntervalCollection from '../Core/TimeIntervalCollection.js';
  38. import ClassificationType from '../Scene/ClassificationType.js';
  39. import ColorBlendMode from '../Scene/ColorBlendMode.js';
  40. import HeightReference from '../Scene/HeightReference.js';
  41. import HorizontalOrigin from '../Scene/HorizontalOrigin.js';
  42. import LabelStyle from '../Scene/LabelStyle.js';
  43. import ShadowMode from '../Scene/ShadowMode.js';
  44. import VerticalOrigin from '../Scene/VerticalOrigin.js';
  45. import Uri from '../ThirdParty/Uri.js';
  46. import when from '../ThirdParty/when.js';
  47. import BillboardGraphics from './BillboardGraphics.js';
  48. import BoxGraphics from './BoxGraphics.js';
  49. import CallbackProperty from './CallbackProperty.js';
  50. import CheckerboardMaterialProperty from './CheckerboardMaterialProperty.js';
  51. import ColorMaterialProperty from './ColorMaterialProperty.js';
  52. import CompositeMaterialProperty from './CompositeMaterialProperty.js';
  53. import CompositePositionProperty from './CompositePositionProperty.js';
  54. import CompositeProperty from './CompositeProperty.js';
  55. import ConstantPositionProperty from './ConstantPositionProperty.js';
  56. import ConstantProperty from './ConstantProperty.js';
  57. import CorridorGraphics from './CorridorGraphics.js';
  58. import CylinderGraphics from './CylinderGraphics.js';
  59. import DataSource from './DataSource.js';
  60. import DataSourceClock from './DataSourceClock.js';
  61. import EllipseGraphics from './EllipseGraphics.js';
  62. import EllipsoidGraphics from './EllipsoidGraphics.js';
  63. import EntityCluster from './EntityCluster.js';
  64. import EntityCollection from './EntityCollection.js';
  65. import GridMaterialProperty from './GridMaterialProperty.js';
  66. import ImageMaterialProperty from './ImageMaterialProperty.js';
  67. import LabelGraphics from './LabelGraphics.js';
  68. import ModelGraphics from './ModelGraphics.js';
  69. import NodeTransformationProperty from './NodeTransformationProperty.js';
  70. import PathGraphics from './PathGraphics.js';
  71. import PointGraphics from './PointGraphics.js';
  72. import PolygonGraphics from './PolygonGraphics.js';
  73. import PolylineArrowMaterialProperty from './PolylineArrowMaterialProperty.js';
  74. import PolylineDashMaterialProperty from './PolylineDashMaterialProperty.js';
  75. import PolylineGlowMaterialProperty from './PolylineGlowMaterialProperty.js';
  76. import PolylineGraphics from './PolylineGraphics.js';
  77. import PolylineOutlineMaterialProperty from './PolylineOutlineMaterialProperty.js';
  78. import PositionPropertyArray from './PositionPropertyArray.js';
  79. import Property from './Property.js';
  80. import PropertyArray from './PropertyArray.js';
  81. import PropertyBag from './PropertyBag.js';
  82. import RectangleGraphics from './RectangleGraphics.js';
  83. import ReferenceProperty from './ReferenceProperty.js';
  84. import Rotation from './Rotation.js';
  85. import SampledPositionProperty from './SampledPositionProperty.js';
  86. import SampledProperty from './SampledProperty.js';
  87. import StripeMaterialProperty from './StripeMaterialProperty.js';
  88. import StripeOrientation from './StripeOrientation.js';
  89. import TimeIntervalCollectionPositionProperty from './TimeIntervalCollectionPositionProperty.js';
  90. import TimeIntervalCollectionProperty from './TimeIntervalCollectionProperty.js';
  91. import VelocityOrientationProperty from './VelocityOrientationProperty.js';
  92. import VelocityVectorProperty from './VelocityVectorProperty.js';
  93. import WallGraphics from './WallGraphics.js';
  94. // A marker type to distinguish CZML properties where we need to end up with a unit vector.
  95. // The data is still loaded into Cartesian3 objects but they are normalized.
  96. function UnitCartesian3() {}
  97. UnitCartesian3.packedLength = Cartesian3.packedLength;
  98. UnitCartesian3.unpack = Cartesian3.unpack;
  99. UnitCartesian3.pack = Cartesian3.pack;
  100. // As a side note, for the purposes of CZML, Quaternion always indicates a unit quaternion.
  101. var currentId;
  102. function createReferenceProperty(entityCollection, referenceString) {
  103. if (referenceString[0] === '#') {
  104. referenceString = currentId + referenceString;
  105. }
  106. return ReferenceProperty.fromString(entityCollection, referenceString);
  107. }
  108. function createSpecializedProperty(type, entityCollection, packetData) {
  109. if (defined(packetData.reference)) {
  110. return createReferenceProperty(entityCollection, packetData.reference);
  111. }
  112. if (defined(packetData.velocityReference)) {
  113. var referenceProperty = createReferenceProperty(entityCollection, packetData.velocityReference);
  114. switch (type) {
  115. case Cartesian3:
  116. case UnitCartesian3:
  117. return new VelocityVectorProperty(referenceProperty, type === UnitCartesian3);
  118. case Quaternion:
  119. return new VelocityOrientationProperty(referenceProperty);
  120. }
  121. }
  122. throw new RuntimeError(JSON.stringify(packetData) + ' is not valid CZML.');
  123. }
  124. function createAdapterProperty(property, adapterFunction) {
  125. return new CallbackProperty(function(time, result) {
  126. return adapterFunction(property.getValue(time, result));
  127. }, property.isConstant);
  128. }
  129. var scratchCartesian = new Cartesian3();
  130. var scratchSpherical = new Spherical();
  131. var scratchCartographic = new Cartographic();
  132. var scratchTimeInterval = new TimeInterval();
  133. var scratchQuaternion = new Quaternion();
  134. function unwrapColorInterval(czmlInterval) {
  135. var rgbaf = czmlInterval.rgbaf;
  136. if (defined(rgbaf)) {
  137. return rgbaf;
  138. }
  139. var rgba = czmlInterval.rgba;
  140. if (!defined(rgba)) {
  141. return undefined;
  142. }
  143. var length = rgba.length;
  144. if (length === Color.packedLength) {
  145. return [Color.byteToFloat(rgba[0]), Color.byteToFloat(rgba[1]), Color.byteToFloat(rgba[2]), Color.byteToFloat(rgba[3])];
  146. }
  147. rgbaf = new Array(length);
  148. for (var i = 0; i < length; i += 5) {
  149. rgbaf[i] = rgba[i];
  150. rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]);
  151. rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]);
  152. rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]);
  153. rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]);
  154. }
  155. return rgbaf;
  156. }
  157. function unwrapUriInterval(czmlInterval, sourceUri) {
  158. var uri = defaultValue(czmlInterval.uri, czmlInterval);
  159. if (defined(sourceUri)) {
  160. return sourceUri.getDerivedResource({
  161. url: uri
  162. });
  163. }
  164. return Resource.createIfNeeded(uri);
  165. }
  166. function unwrapRectangleInterval(czmlInterval) {
  167. var wsen = czmlInterval.wsen;
  168. if (defined(wsen)) {
  169. return wsen;
  170. }
  171. var wsenDegrees = czmlInterval.wsenDegrees;
  172. if (!defined(wsenDegrees)) {
  173. return undefined;
  174. }
  175. var length = wsenDegrees.length;
  176. if (length === Rectangle.packedLength) {
  177. return [CesiumMath.toRadians(wsenDegrees[0]), CesiumMath.toRadians(wsenDegrees[1]), CesiumMath.toRadians(wsenDegrees[2]), CesiumMath.toRadians(wsenDegrees[3])];
  178. }
  179. wsen = new Array(length);
  180. for (var i = 0; i < length; i += 5) {
  181. wsen[i] = wsenDegrees[i];
  182. wsen[i + 1] = CesiumMath.toRadians(wsenDegrees[i + 1]);
  183. wsen[i + 2] = CesiumMath.toRadians(wsenDegrees[i + 2]);
  184. wsen[i + 3] = CesiumMath.toRadians(wsenDegrees[i + 3]);
  185. wsen[i + 4] = CesiumMath.toRadians(wsenDegrees[i + 4]);
  186. }
  187. return wsen;
  188. }
  189. function convertUnitSphericalToCartesian(unitSpherical) {
  190. var length = unitSpherical.length;
  191. scratchSpherical.magnitude = 1.0;
  192. if (length === 2) {
  193. scratchSpherical.clock = unitSpherical[0];
  194. scratchSpherical.cone = unitSpherical[1];
  195. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  196. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  197. }
  198. var result = new Array(length / 3 * 4);
  199. for (var i = 0, j = 0; i < length; i += 3, j += 4) {
  200. result[j] = unitSpherical[i];
  201. scratchSpherical.clock = unitSpherical[i + 1];
  202. scratchSpherical.cone = unitSpherical[i + 2];
  203. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  204. result[j + 1] = scratchCartesian.x;
  205. result[j + 2] = scratchCartesian.y;
  206. result[j + 3] = scratchCartesian.z;
  207. }
  208. return result;
  209. }
  210. function convertSphericalToCartesian(spherical) {
  211. var length = spherical.length;
  212. if (length === 3) {
  213. scratchSpherical.clock = spherical[0];
  214. scratchSpherical.cone = spherical[1];
  215. scratchSpherical.magnitude = spherical[2];
  216. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  217. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  218. }
  219. var result = new Array(length);
  220. for (var i = 0; i < length; i += 4) {
  221. result[i] = spherical[i];
  222. scratchSpherical.clock = spherical[i + 1];
  223. scratchSpherical.cone = spherical[i + 2];
  224. scratchSpherical.magnitude = spherical[i + 3];
  225. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  226. result[i + 1] = scratchCartesian.x;
  227. result[i + 2] = scratchCartesian.y;
  228. result[i + 3] = scratchCartesian.z;
  229. }
  230. return result;
  231. }
  232. function convertCartographicRadiansToCartesian(cartographicRadians) {
  233. var length = cartographicRadians.length;
  234. if (length === 3) {
  235. scratchCartographic.longitude = cartographicRadians[0];
  236. scratchCartographic.latitude = cartographicRadians[1];
  237. scratchCartographic.height = cartographicRadians[2];
  238. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  239. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  240. }
  241. var result = new Array(length);
  242. for (var i = 0; i < length; i += 4) {
  243. result[i] = cartographicRadians[i];
  244. scratchCartographic.longitude = cartographicRadians[i + 1];
  245. scratchCartographic.latitude = cartographicRadians[i + 2];
  246. scratchCartographic.height = cartographicRadians[i + 3];
  247. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  248. result[i + 1] = scratchCartesian.x;
  249. result[i + 2] = scratchCartesian.y;
  250. result[i + 3] = scratchCartesian.z;
  251. }
  252. return result;
  253. }
  254. function convertCartographicDegreesToCartesian(cartographicDegrees) {
  255. var length = cartographicDegrees.length;
  256. if (length === 3) {
  257. scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[0]);
  258. scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]);
  259. scratchCartographic.height = cartographicDegrees[2];
  260. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  261. return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  262. }
  263. var result = new Array(length);
  264. for (var i = 0; i < length; i += 4) {
  265. result[i] = cartographicDegrees[i];
  266. scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[i + 1]);
  267. scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[i + 2]);
  268. scratchCartographic.height = cartographicDegrees[i + 3];
  269. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  270. result[i + 1] = scratchCartesian.x;
  271. result[i + 2] = scratchCartesian.y;
  272. result[i + 3] = scratchCartesian.z;
  273. }
  274. return result;
  275. }
  276. function unwrapCartesianInterval(czmlInterval) {
  277. var cartesian = czmlInterval.cartesian;
  278. if (defined(cartesian)) {
  279. return cartesian;
  280. }
  281. var cartesianVelocity = czmlInterval.cartesianVelocity;
  282. if (defined(cartesianVelocity)) {
  283. return cartesianVelocity;
  284. }
  285. var unitCartesian = czmlInterval.unitCartesian;
  286. if (defined(unitCartesian)) {
  287. return unitCartesian;
  288. }
  289. var unitSpherical = czmlInterval.unitSpherical;
  290. if (defined(unitSpherical)) {
  291. return convertUnitSphericalToCartesian(unitSpherical);
  292. }
  293. var spherical = czmlInterval.spherical;
  294. if (defined(spherical)) {
  295. return convertSphericalToCartesian(spherical);
  296. }
  297. var cartographicRadians = czmlInterval.cartographicRadians;
  298. if (defined(cartographicRadians)) {
  299. return convertCartographicRadiansToCartesian(cartographicRadians);
  300. }
  301. var cartographicDegrees = czmlInterval.cartographicDegrees;
  302. if (defined(cartographicDegrees)) {
  303. return convertCartographicDegreesToCartesian(cartographicDegrees);
  304. }
  305. throw new RuntimeError(JSON.stringify(czmlInterval) + ' is not a valid CZML interval.');
  306. }
  307. function normalizePackedCartesianArray(array, startingIndex) {
  308. Cartesian3.unpack(array, startingIndex, scratchCartesian);
  309. Cartesian3.normalize(scratchCartesian, scratchCartesian);
  310. Cartesian3.pack(scratchCartesian, array, startingIndex);
  311. }
  312. function unwrapUnitCartesianInterval(czmlInterval) {
  313. var cartesian = unwrapCartesianInterval(czmlInterval);
  314. if (cartesian.length === 3) {
  315. normalizePackedCartesianArray(cartesian, 0);
  316. return cartesian;
  317. }
  318. for (var i = 1; i < cartesian.length; i += 4) {
  319. normalizePackedCartesianArray(cartesian, i);
  320. }
  321. return cartesian;
  322. }
  323. function normalizePackedQuaternionArray(array, startingIndex) {
  324. Quaternion.unpack(array, startingIndex, scratchQuaternion);
  325. Quaternion.normalize(scratchQuaternion, scratchQuaternion);
  326. Quaternion.pack(scratchQuaternion, array, startingIndex);
  327. }
  328. function unwrapQuaternionInterval(czmlInterval) {
  329. var unitQuaternion = czmlInterval.unitQuaternion;
  330. if (defined(unitQuaternion)) {
  331. if (unitQuaternion.length === 4) {
  332. normalizePackedQuaternionArray(unitQuaternion, 0);
  333. return unitQuaternion;
  334. }
  335. for (var i = 1; i < unitQuaternion.length; i += 5) {
  336. normalizePackedQuaternionArray(unitQuaternion, i);
  337. }
  338. }
  339. return unitQuaternion;
  340. }
  341. function getPropertyType(czmlInterval) {
  342. // The associations in this function need to be kept in sync with the
  343. // associations in unwrapInterval.
  344. // Intentionally omitted due to conficts in CZML property names:
  345. // * Image (conflicts with Uri)
  346. // * Rotation (conflicts with Number)
  347. //
  348. // cartesianVelocity is also omitted due to incomplete support for
  349. // derivative information in CZML properties.
  350. // (Currently cartesianVelocity is hacked directly into the position processing code)
  351. if (typeof czmlInterval === 'boolean') {
  352. return Boolean;
  353. } else if (typeof czmlInterval === 'number') {
  354. return Number;
  355. } else if (typeof czmlInterval === 'string') {
  356. return String;
  357. } else if (czmlInterval.hasOwnProperty('array')) {
  358. return Array;
  359. } else if (czmlInterval.hasOwnProperty('boolean')) {
  360. return Boolean;
  361. } else if (czmlInterval.hasOwnProperty('boundingRectangle')) {
  362. return BoundingRectangle;
  363. } else if (czmlInterval.hasOwnProperty('cartesian2')) {
  364. return Cartesian2;
  365. } else if (czmlInterval.hasOwnProperty('cartesian') ||
  366. czmlInterval.hasOwnProperty('spherical') ||
  367. czmlInterval.hasOwnProperty('cartographicRadians') ||
  368. czmlInterval.hasOwnProperty('cartographicDegrees')) {
  369. return Cartesian3;
  370. } else if (czmlInterval.hasOwnProperty('unitCartesian') ||
  371. czmlInterval.hasOwnProperty('unitSpherical')) {
  372. return UnitCartesian3;
  373. } else if (czmlInterval.hasOwnProperty('rgba') ||
  374. czmlInterval.hasOwnProperty('rgbaf')) {
  375. return Color;
  376. } else if (czmlInterval.hasOwnProperty('arcType')) {
  377. return ArcType;
  378. } else if (czmlInterval.hasOwnProperty('classificationType')) {
  379. return ClassificationType;
  380. } else if (czmlInterval.hasOwnProperty('colorBlendMode')) {
  381. return ColorBlendMode;
  382. } else if (czmlInterval.hasOwnProperty('cornerType')) {
  383. return CornerType;
  384. } else if (czmlInterval.hasOwnProperty('heightReference')) {
  385. return HeightReference;
  386. } else if (czmlInterval.hasOwnProperty('horizontalOrigin')) {
  387. return HorizontalOrigin;
  388. } else if (czmlInterval.hasOwnProperty('date')) {
  389. return JulianDate;
  390. } else if (czmlInterval.hasOwnProperty('labelStyle')) {
  391. return LabelStyle;
  392. } else if (czmlInterval.hasOwnProperty('number')) {
  393. return Number;
  394. } else if (czmlInterval.hasOwnProperty('nearFarScalar')) {
  395. return NearFarScalar;
  396. } else if (czmlInterval.hasOwnProperty('distanceDisplayCondition')) {
  397. return DistanceDisplayCondition;
  398. } else if (czmlInterval.hasOwnProperty('object') ||
  399. czmlInterval.hasOwnProperty('value')) {
  400. return Object;
  401. } else if (czmlInterval.hasOwnProperty('unitQuaternion')) {
  402. return Quaternion;
  403. } else if (czmlInterval.hasOwnProperty('shadowMode')) {
  404. return ShadowMode;
  405. } else if (czmlInterval.hasOwnProperty('string')) {
  406. return String;
  407. } else if (czmlInterval.hasOwnProperty('stripeOrientation')) {
  408. return StripeOrientation;
  409. } else if (czmlInterval.hasOwnProperty('wsen') ||
  410. czmlInterval.hasOwnProperty('wsenDegrees')) {
  411. return Rectangle;
  412. } else if (czmlInterval.hasOwnProperty('uri')) {
  413. return Uri;
  414. } else if (czmlInterval.hasOwnProperty('verticalOrigin')) {
  415. return VerticalOrigin;
  416. }
  417. // fallback case
  418. return Object;
  419. }
  420. function unwrapInterval(type, czmlInterval, sourceUri) {
  421. // The associations in this function need to be kept in sync with the
  422. // associations in getPropertyType
  423. switch (type) {
  424. case ArcType:
  425. return ArcType[defaultValue(czmlInterval.arcType, czmlInterval)];
  426. case Array:
  427. return czmlInterval.array;
  428. case Boolean:
  429. return defaultValue(czmlInterval['boolean'], czmlInterval);
  430. case BoundingRectangle:
  431. return czmlInterval.boundingRectangle;
  432. case Cartesian2:
  433. return czmlInterval.cartesian2;
  434. case Cartesian3:
  435. return unwrapCartesianInterval(czmlInterval);
  436. case UnitCartesian3:
  437. return unwrapUnitCartesianInterval(czmlInterval);
  438. case Color:
  439. return unwrapColorInterval(czmlInterval);
  440. case ClassificationType:
  441. return ClassificationType[defaultValue(czmlInterval.classificationType, czmlInterval)];
  442. case ColorBlendMode:
  443. return ColorBlendMode[defaultValue(czmlInterval.colorBlendMode, czmlInterval)];
  444. case CornerType:
  445. return CornerType[defaultValue(czmlInterval.cornerType, czmlInterval)];
  446. case HeightReference:
  447. return HeightReference[defaultValue(czmlInterval.heightReference, czmlInterval)];
  448. case HorizontalOrigin:
  449. return HorizontalOrigin[defaultValue(czmlInterval.horizontalOrigin, czmlInterval)];
  450. case Image:
  451. return unwrapUriInterval(czmlInterval, sourceUri);
  452. case JulianDate:
  453. return JulianDate.fromIso8601(defaultValue(czmlInterval.date, czmlInterval));
  454. case LabelStyle:
  455. return LabelStyle[defaultValue(czmlInterval.labelStyle, czmlInterval)];
  456. case Number:
  457. return defaultValue(czmlInterval.number, czmlInterval);
  458. case NearFarScalar:
  459. return czmlInterval.nearFarScalar;
  460. case DistanceDisplayCondition:
  461. return czmlInterval.distanceDisplayCondition;
  462. case Object:
  463. return defaultValue(defaultValue(czmlInterval.object, czmlInterval.value), czmlInterval);
  464. case Quaternion:
  465. return unwrapQuaternionInterval(czmlInterval);
  466. case Rotation:
  467. return defaultValue(czmlInterval.number, czmlInterval);
  468. case ShadowMode:
  469. return ShadowMode[defaultValue(defaultValue(czmlInterval.shadowMode, czmlInterval.shadows), czmlInterval)];
  470. case String:
  471. return defaultValue(czmlInterval.string, czmlInterval);
  472. case StripeOrientation:
  473. return StripeOrientation[defaultValue(czmlInterval.stripeOrientation, czmlInterval)];
  474. case Rectangle:
  475. return unwrapRectangleInterval(czmlInterval);
  476. case Uri:
  477. return unwrapUriInterval(czmlInterval, sourceUri);
  478. case VerticalOrigin:
  479. return VerticalOrigin[defaultValue(czmlInterval.verticalOrigin, czmlInterval)];
  480. default:
  481. throw new RuntimeError(type);
  482. }
  483. }
  484. var interpolators = {
  485. HERMITE : HermitePolynomialApproximation,
  486. LAGRANGE : LagrangePolynomialApproximation,
  487. LINEAR : LinearApproximation
  488. };
  489. function updateInterpolationSettings(packetData, property) {
  490. var interpolationAlgorithm = packetData.interpolationAlgorithm;
  491. var interpolationDegree = packetData.interpolationDegree;
  492. if (defined(interpolationAlgorithm) || defined(interpolationDegree)) {
  493. property.setInterpolationOptions({
  494. interpolationAlgorithm : interpolators[interpolationAlgorithm],
  495. interpolationDegree : interpolationDegree
  496. });
  497. }
  498. var forwardExtrapolationType = packetData.forwardExtrapolationType;
  499. if (defined(forwardExtrapolationType)) {
  500. property.forwardExtrapolationType = ExtrapolationType[forwardExtrapolationType];
  501. }
  502. var forwardExtrapolationDuration = packetData.forwardExtrapolationDuration;
  503. if (defined(forwardExtrapolationDuration)) {
  504. property.forwardExtrapolationDuration = forwardExtrapolationDuration;
  505. }
  506. var backwardExtrapolationType = packetData.backwardExtrapolationType;
  507. if (defined(backwardExtrapolationType)) {
  508. property.backwardExtrapolationType = ExtrapolationType[backwardExtrapolationType];
  509. }
  510. var backwardExtrapolationDuration = packetData.backwardExtrapolationDuration;
  511. if (defined(backwardExtrapolationDuration)) {
  512. property.backwardExtrapolationDuration = backwardExtrapolationDuration;
  513. }
  514. }
  515. var iso8601Scratch = {
  516. iso8601 : undefined
  517. };
  518. function intervalFromString(intervalString) {
  519. if (!defined(intervalString)) {
  520. return undefined;
  521. }
  522. iso8601Scratch.iso8601 = intervalString;
  523. return TimeInterval.fromIso8601(iso8601Scratch);
  524. }
  525. function wrapPropertyInInfiniteInterval(property) {
  526. var interval = Iso8601.MAXIMUM_INTERVAL.clone();
  527. interval.data = property;
  528. return interval;
  529. }
  530. function convertPropertyToComposite(property) {
  531. // Create the composite and add the old property, wrapped in an infinite interval.
  532. var composite = new CompositeProperty();
  533. composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
  534. return composite;
  535. }
  536. function convertPositionPropertyToComposite(property) {
  537. // Create the composite and add the old property, wrapped in an infinite interval.
  538. var composite = new CompositePositionProperty(property.referenceFrame);
  539. composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
  540. return composite;
  541. }
  542. function processProperty(type, object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) {
  543. var combinedInterval = intervalFromString(packetData.interval);
  544. if (defined(constrainedInterval)) {
  545. if (defined(combinedInterval)) {
  546. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  547. } else {
  548. combinedInterval = constrainedInterval;
  549. }
  550. }
  551. var packedLength;
  552. var unwrappedInterval;
  553. var unwrappedIntervalLength;
  554. // CZML properties can be defined in many ways. Most ways represent a structure for
  555. // encoding a single value (number, string, cartesian, etc.) Regardless of the value type,
  556. // if it encodes a single value it will get loaded into a ConstantProperty eventually.
  557. // Alternatively, there are ways of defining a property that require specialized
  558. // client-side representation. Currently, these are ReferenceProperty,
  559. // and client-side velocity computation properties such as VelocityVectorProperty.
  560. var isValue = !defined(packetData.reference) && !defined(packetData.velocityReference);
  561. var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
  562. if (packetData.delete === true) {
  563. // If deleting this property for all time, we can simply set to undefined and return.
  564. if (!hasInterval) {
  565. object[propertyName] = undefined;
  566. return;
  567. }
  568. // Deleting depends on the type of property we have.
  569. return removePropertyData(object[propertyName], combinedInterval);
  570. }
  571. var isSampled = false;
  572. if (isValue) {
  573. unwrappedInterval = unwrapInterval(type, packetData, sourceUri);
  574. if (!defined(unwrappedInterval)) {
  575. // not a known value type, bail
  576. return;
  577. }
  578. packedLength = defaultValue(type.packedLength, 1);
  579. unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
  580. isSampled = !defined(packetData.array) && (typeof unwrappedInterval !== 'string') && (unwrappedIntervalLength > packedLength) && (type !== Object);
  581. }
  582. // Rotation is a special case because it represents a native type (Number)
  583. // and therefore does not need to be unpacked when loaded as a constant value.
  584. var needsUnpacking = typeof type.unpack === 'function' && type !== Rotation;
  585. // Any time a constant value is assigned, it completely blows away anything else.
  586. if (!isSampled && !hasInterval) {
  587. if (isValue) {
  588. object[propertyName] = new ConstantProperty(needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval);
  589. } else {
  590. object[propertyName] = createSpecializedProperty(type, entityCollection, packetData);
  591. }
  592. return;
  593. }
  594. var property = object[propertyName];
  595. var epoch;
  596. var packetEpoch = packetData.epoch;
  597. if (defined(packetEpoch)) {
  598. epoch = JulianDate.fromIso8601(packetEpoch);
  599. }
  600. // Without an interval, any sampled value is infinite, meaning it completely
  601. // replaces any non-sampled property that may exist.
  602. if (isSampled && !hasInterval) {
  603. if (!(property instanceof SampledProperty)) {
  604. object[propertyName] = property = new SampledProperty(type);
  605. }
  606. property.addSamplesPackedArray(unwrappedInterval, epoch);
  607. updateInterpolationSettings(packetData, property);
  608. return;
  609. }
  610. var interval;
  611. // A constant value with an interval is normally part of a TimeIntervalCollection,
  612. // However, if the current property is not a time-interval collection, we need
  613. // to turn it into a Composite, preserving the old data with the new interval.
  614. if (!isSampled && hasInterval) {
  615. // Create a new interval for the constant value.
  616. combinedInterval = combinedInterval.clone();
  617. if (isValue) {
  618. combinedInterval.data = needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval;
  619. } else {
  620. combinedInterval.data = createSpecializedProperty(type, entityCollection, packetData);
  621. }
  622. // If no property exists, simply use a new interval collection
  623. if (!defined(property)) {
  624. object[propertyName] = property = isValue ? new TimeIntervalCollectionProperty() : new CompositeProperty();
  625. }
  626. if (isValue && property instanceof TimeIntervalCollectionProperty) {
  627. // If we created a collection, or it already was one, use it.
  628. property.intervals.addInterval(combinedInterval);
  629. } else if (property instanceof CompositeProperty) {
  630. // If the collection was already a CompositeProperty, use it.
  631. if (isValue) {
  632. combinedInterval.data = new ConstantProperty(combinedInterval.data);
  633. }
  634. property.intervals.addInterval(combinedInterval);
  635. } else {
  636. // Otherwise, create a CompositeProperty but preserve the existing data.
  637. object[propertyName] = property = convertPropertyToComposite(property);
  638. // Change the new data to a ConstantProperty and add it.
  639. if (isValue) {
  640. combinedInterval.data = new ConstantProperty(combinedInterval.data);
  641. }
  642. property.intervals.addInterval(combinedInterval);
  643. }
  644. return;
  645. }
  646. // isSampled && hasInterval
  647. if (!defined(property)) {
  648. object[propertyName] = property = new CompositeProperty();
  649. }
  650. // Create a CompositeProperty but preserve the existing data.
  651. if (!(property instanceof CompositeProperty)) {
  652. object[propertyName] = property = convertPropertyToComposite(property);
  653. }
  654. // Check if the interval already exists in the composite.
  655. var intervals = property.intervals;
  656. interval = intervals.findInterval(combinedInterval);
  657. if (!defined(interval) || !(interval.data instanceof SampledProperty)) {
  658. // If not, create a SampledProperty for it.
  659. interval = combinedInterval.clone();
  660. interval.data = new SampledProperty(type);
  661. intervals.addInterval(interval);
  662. }
  663. interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
  664. updateInterpolationSettings(packetData, interval.data);
  665. }
  666. function removePropertyData(property, interval) {
  667. if (property instanceof SampledProperty) {
  668. property.removeSamples(interval);
  669. return;
  670. } else if (property instanceof TimeIntervalCollectionProperty) {
  671. property.intervals.removeInterval(interval);
  672. return;
  673. } else if (property instanceof CompositeProperty) {
  674. var intervals = property.intervals;
  675. for (var i = 0; i < intervals.length; ++i) {
  676. var intersection = TimeInterval.intersect(intervals.get(i), interval, scratchTimeInterval);
  677. if (!intersection.isEmpty) {
  678. // remove data from the contained properties
  679. removePropertyData(intersection.data, interval);
  680. }
  681. }
  682. // remove the intervals from the composite
  683. intervals.removeInterval(interval);
  684. return;
  685. }
  686. }
  687. function processPacketData(type, object, propertyName, packetData, interval, sourceUri, entityCollection) {
  688. if (!defined(packetData)) {
  689. return;
  690. }
  691. if (isArray(packetData)) {
  692. for (var i = 0, len = packetData.length; i < len; ++i) {
  693. processProperty(type, object, propertyName, packetData[i], interval, sourceUri, entityCollection);
  694. }
  695. } else {
  696. processProperty(type, object, propertyName, packetData, interval, sourceUri, entityCollection);
  697. }
  698. }
  699. function processPositionProperty(object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) {
  700. var combinedInterval = intervalFromString(packetData.interval);
  701. if (defined(constrainedInterval)) {
  702. if (defined(combinedInterval)) {
  703. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  704. } else {
  705. combinedInterval = constrainedInterval;
  706. }
  707. }
  708. var numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0;
  709. var packedLength = Cartesian3.packedLength * (numberOfDerivatives + 1);
  710. var unwrappedInterval;
  711. var unwrappedIntervalLength;
  712. var isValue = !defined(packetData.reference);
  713. var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
  714. if (packetData.delete === true) {
  715. // If deleting this property for all time, we can simply set to undefined and return.
  716. if (!hasInterval) {
  717. object[propertyName] = undefined;
  718. return;
  719. }
  720. // Deleting depends on the type of property we have.
  721. return removePositionPropertyData(object[propertyName], combinedInterval);
  722. }
  723. var referenceFrame;
  724. var isSampled = false;
  725. if (isValue) {
  726. if (defined(packetData.referenceFrame)) {
  727. referenceFrame = ReferenceFrame[packetData.referenceFrame];
  728. }
  729. referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);
  730. unwrappedInterval = unwrapCartesianInterval(packetData);
  731. unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
  732. isSampled = unwrappedIntervalLength > packedLength;
  733. }
  734. // Any time a constant value is assigned, it completely blows away anything else.
  735. if (!isSampled && !hasInterval) {
  736. if (isValue) {
  737. object[propertyName] = new ConstantPositionProperty(Cartesian3.unpack(unwrappedInterval), referenceFrame);
  738. } else {
  739. object[propertyName] = createReferenceProperty(entityCollection, packetData.reference);
  740. }
  741. return;
  742. }
  743. var property = object[propertyName];
  744. var epoch;
  745. var packetEpoch = packetData.epoch;
  746. if (defined(packetEpoch)) {
  747. epoch = JulianDate.fromIso8601(packetEpoch);
  748. }
  749. // Without an interval, any sampled value is infinite, meaning it completely
  750. // replaces any non-sampled property that may exist.
  751. if (isSampled && !hasInterval) {
  752. if (!(property instanceof SampledPositionProperty) || (defined(referenceFrame) && property.referenceFrame !== referenceFrame)) {
  753. object[propertyName] = property = new SampledPositionProperty(referenceFrame, numberOfDerivatives);
  754. }
  755. property.addSamplesPackedArray(unwrappedInterval, epoch);
  756. updateInterpolationSettings(packetData, property);
  757. return;
  758. }
  759. var interval;
  760. // A constant value with an interval is normally part of a TimeIntervalCollection,
  761. // However, if the current property is not a time-interval collection, we need
  762. // to turn it into a Composite, preserving the old data with the new interval.
  763. if (!isSampled && hasInterval) {
  764. // Create a new interval for the constant value.
  765. combinedInterval = combinedInterval.clone();
  766. if (isValue) {
  767. combinedInterval.data = Cartesian3.unpack(unwrappedInterval);
  768. } else {
  769. combinedInterval.data = createReferenceProperty(entityCollection, packetData.reference);
  770. }
  771. // If no property exists, simply use a new interval collection
  772. if (!defined(property)) {
  773. if (isValue) {
  774. property = new TimeIntervalCollectionPositionProperty(referenceFrame);
  775. } else {
  776. property = new CompositePositionProperty(referenceFrame);
  777. }
  778. object[propertyName] = property;
  779. }
  780. if (isValue && property instanceof TimeIntervalCollectionPositionProperty && (defined(referenceFrame) && property.referenceFrame === referenceFrame)) {
  781. // If we create a collection, or it already existed, use it.
  782. property.intervals.addInterval(combinedInterval);
  783. } else if (property instanceof CompositePositionProperty) {
  784. // If the collection was already a CompositePositionProperty, use it.
  785. if (isValue) {
  786. combinedInterval.data = new ConstantPositionProperty(combinedInterval.data, referenceFrame);
  787. }
  788. property.intervals.addInterval(combinedInterval);
  789. } else {
  790. // Otherwise, create a CompositePositionProperty but preserve the existing data.
  791. object[propertyName] = property = convertPositionPropertyToComposite(property);
  792. // Change the new data to a ConstantPositionProperty and add it.
  793. if (isValue) {
  794. combinedInterval.data = new ConstantPositionProperty(combinedInterval.data, referenceFrame);
  795. }
  796. property.intervals.addInterval(combinedInterval);
  797. }
  798. return;
  799. }
  800. // isSampled && hasInterval
  801. if (!defined(property)) {
  802. object[propertyName] = property = new CompositePositionProperty(referenceFrame);
  803. } else if (!(property instanceof CompositePositionProperty)) {
  804. // Create a CompositeProperty but preserve the existing data.
  805. object[propertyName] = property = convertPositionPropertyToComposite(property);
  806. }
  807. // Check if the interval already exists in the composite.
  808. var intervals = property.intervals;
  809. interval = intervals.findInterval(combinedInterval);
  810. if (!defined(interval) || !(interval.data instanceof SampledPositionProperty) || (defined(referenceFrame) && interval.data.referenceFrame !== referenceFrame)) {
  811. // If not, create a SampledPositionProperty for it.
  812. interval = combinedInterval.clone();
  813. interval.data = new SampledPositionProperty(referenceFrame, numberOfDerivatives);
  814. intervals.addInterval(interval);
  815. }
  816. interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
  817. updateInterpolationSettings(packetData, interval.data);
  818. }
  819. function removePositionPropertyData(property, interval) {
  820. if (property instanceof SampledPositionProperty) {
  821. property.removeSamples(interval);
  822. return;
  823. } else if (property instanceof TimeIntervalCollectionPositionProperty) {
  824. property.intervals.removeInterval(interval);
  825. return;
  826. } else if (property instanceof CompositePositionProperty) {
  827. var intervals = property.intervals;
  828. for (var i = 0; i < intervals.length; ++i) {
  829. var intersection = TimeInterval.intersect(intervals.get(i), interval, scratchTimeInterval);
  830. if (!intersection.isEmpty) {
  831. // remove data from the contained properties
  832. removePositionPropertyData(intersection.data, interval);
  833. }
  834. }
  835. // remove the intervals from the composite
  836. intervals.removeInterval(interval);
  837. return;
  838. }
  839. }
  840. function processPositionPacketData(object, propertyName, packetData, interval, sourceUri, entityCollection) {
  841. if (!defined(packetData)) {
  842. return;
  843. }
  844. if (isArray(packetData)) {
  845. for (var i = 0, len = packetData.length; i < len; ++i) {
  846. processPositionProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection);
  847. }
  848. } else {
  849. processPositionProperty(object, propertyName, packetData, interval, sourceUri, entityCollection);
  850. }
  851. }
  852. function processMaterialProperty(object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) {
  853. var combinedInterval = intervalFromString(packetData.interval);
  854. if (defined(constrainedInterval)) {
  855. if (defined(combinedInterval)) {
  856. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  857. } else {
  858. combinedInterval = constrainedInterval;
  859. }
  860. }
  861. var property = object[propertyName];
  862. var existingMaterial;
  863. var existingInterval;
  864. if (defined(combinedInterval)) {
  865. if (!(property instanceof CompositeMaterialProperty)) {
  866. property = new CompositeMaterialProperty();
  867. object[propertyName] = property;
  868. }
  869. //See if we already have data at that interval.
  870. var thisIntervals = property.intervals;
  871. existingInterval = thisIntervals.findInterval({
  872. start : combinedInterval.start,
  873. stop : combinedInterval.stop
  874. });
  875. if (defined(existingInterval)) {
  876. //We have an interval, but we need to make sure the
  877. //new data is the same type of material as the old data.
  878. existingMaterial = existingInterval.data;
  879. } else {
  880. //If not, create it.
  881. existingInterval = combinedInterval.clone();
  882. thisIntervals.addInterval(existingInterval);
  883. }
  884. } else {
  885. existingMaterial = property;
  886. }
  887. var materialData;
  888. if (defined(packetData.solidColor)) {
  889. if (!(existingMaterial instanceof ColorMaterialProperty)) {
  890. existingMaterial = new ColorMaterialProperty();
  891. }
  892. materialData = packetData.solidColor;
  893. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, undefined, entityCollection);
  894. } else if (defined(packetData.grid)) {
  895. if (!(existingMaterial instanceof GridMaterialProperty)) {
  896. existingMaterial = new GridMaterialProperty();
  897. }
  898. materialData = packetData.grid;
  899. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  900. processPacketData(Number, existingMaterial, 'cellAlpha', materialData.cellAlpha, undefined, sourceUri, entityCollection);
  901. processPacketData(Cartesian2, existingMaterial, 'lineCount', materialData.lineCount, undefined, sourceUri, entityCollection);
  902. processPacketData(Cartesian2, existingMaterial, 'lineThickness', materialData.lineThickness, undefined, sourceUri, entityCollection);
  903. processPacketData(Cartesian2, existingMaterial, 'lineOffset', materialData.lineOffset, undefined, sourceUri, entityCollection);
  904. } else if (defined(packetData.image)) {
  905. if (!(existingMaterial instanceof ImageMaterialProperty)) {
  906. existingMaterial = new ImageMaterialProperty();
  907. }
  908. materialData = packetData.image;
  909. processPacketData(Image, existingMaterial, 'image', materialData.image, undefined, sourceUri, entityCollection);
  910. processPacketData(Cartesian2, existingMaterial, 'repeat', materialData.repeat, undefined, sourceUri, entityCollection);
  911. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  912. processPacketData(Boolean, existingMaterial, 'transparent', materialData.transparent, undefined, sourceUri, entityCollection);
  913. } else if (defined(packetData.stripe)) {
  914. if (!(existingMaterial instanceof StripeMaterialProperty)) {
  915. existingMaterial = new StripeMaterialProperty();
  916. }
  917. materialData = packetData.stripe;
  918. processPacketData(StripeOrientation, existingMaterial, 'orientation', materialData.orientation, undefined, sourceUri, entityCollection);
  919. processPacketData(Color, existingMaterial, 'evenColor', materialData.evenColor, undefined, sourceUri, entityCollection);
  920. processPacketData(Color, existingMaterial, 'oddColor', materialData.oddColor, undefined, sourceUri, entityCollection);
  921. processPacketData(Number, existingMaterial, 'offset', materialData.offset, undefined, sourceUri, entityCollection);
  922. processPacketData(Number, existingMaterial, 'repeat', materialData.repeat, undefined, sourceUri, entityCollection);
  923. } else if (defined(packetData.polylineOutline)) {
  924. if (!(existingMaterial instanceof PolylineOutlineMaterialProperty)) {
  925. existingMaterial = new PolylineOutlineMaterialProperty();
  926. }
  927. materialData = packetData.polylineOutline;
  928. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  929. processPacketData(Color, existingMaterial, 'outlineColor', materialData.outlineColor, undefined, sourceUri, entityCollection);
  930. processPacketData(Number, existingMaterial, 'outlineWidth', materialData.outlineWidth, undefined, sourceUri, entityCollection);
  931. } else if (defined(packetData.polylineGlow)) {
  932. if (!(existingMaterial instanceof PolylineGlowMaterialProperty)) {
  933. existingMaterial = new PolylineGlowMaterialProperty();
  934. }
  935. materialData = packetData.polylineGlow;
  936. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  937. processPacketData(Number, existingMaterial, 'glowPower', materialData.glowPower, undefined, sourceUri, entityCollection);
  938. processPacketData(Number, existingMaterial, 'taperPower', materialData.taperPower, undefined, sourceUri, entityCollection);
  939. } else if (defined(packetData.polylineArrow)) {
  940. if (!(existingMaterial instanceof PolylineArrowMaterialProperty)) {
  941. existingMaterial = new PolylineArrowMaterialProperty();
  942. }
  943. materialData = packetData.polylineArrow;
  944. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, undefined, entityCollection);
  945. } else if (defined(packetData.polylineDash)) {
  946. if (!(existingMaterial instanceof PolylineDashMaterialProperty)) {
  947. existingMaterial = new PolylineDashMaterialProperty();
  948. }
  949. materialData = packetData.polylineDash;
  950. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, undefined, entityCollection);
  951. processPacketData(Color, existingMaterial, 'gapColor', materialData.gapColor, undefined, undefined, entityCollection);
  952. processPacketData(Number, existingMaterial, 'dashLength', materialData.dashLength, undefined, sourceUri, entityCollection);
  953. processPacketData(Number, existingMaterial, 'dashPattern', materialData.dashPattern, undefined, sourceUri, entityCollection);
  954. } else if (defined(packetData.checkerboard)) {
  955. if (!(existingMaterial instanceof CheckerboardMaterialProperty)) {
  956. existingMaterial = new CheckerboardMaterialProperty();
  957. }
  958. materialData = packetData.checkerboard;
  959. processPacketData(Color, existingMaterial, 'evenColor', materialData.evenColor, undefined, sourceUri, entityCollection);
  960. processPacketData(Color, existingMaterial, 'oddColor', materialData.oddColor, undefined, sourceUri, entityCollection);
  961. processPacketData(Cartesian2, existingMaterial, 'repeat', materialData.repeat, undefined, sourceUri, entityCollection);
  962. }
  963. if (defined(existingInterval)) {
  964. existingInterval.data = existingMaterial;
  965. } else {
  966. object[propertyName] = existingMaterial;
  967. }
  968. }
  969. function processMaterialPacketData(object, propertyName, packetData, interval, sourceUri, entityCollection) {
  970. if (!defined(packetData)) {
  971. return;
  972. }
  973. if (isArray(packetData)) {
  974. for (var i = 0, len = packetData.length; i < len; ++i) {
  975. processMaterialProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection);
  976. }
  977. } else {
  978. processMaterialProperty(object, propertyName, packetData, interval, sourceUri, entityCollection);
  979. }
  980. }
  981. function processName(entity, packet, entityCollection, sourceUri) {
  982. var nameData = packet.name;
  983. if (defined(nameData)) {
  984. entity.name = packet.name;
  985. }
  986. }
  987. function processDescription(entity, packet, entityCollection, sourceUri) {
  988. var descriptionData = packet.description;
  989. if (defined(descriptionData)) {
  990. processPacketData(String, entity, 'description', descriptionData, undefined, sourceUri, entityCollection);
  991. }
  992. }
  993. function processPosition(entity, packet, entityCollection, sourceUri) {
  994. var positionData = packet.position;
  995. if (defined(positionData)) {
  996. processPositionPacketData(entity, 'position', positionData, undefined, sourceUri, entityCollection);
  997. }
  998. }
  999. function processViewFrom(entity, packet, entityCollection, sourceUri) {
  1000. var viewFromData = packet.viewFrom;
  1001. if (defined(viewFromData)) {
  1002. processPacketData(Cartesian3, entity, 'viewFrom', viewFromData, undefined, sourceUri, entityCollection);
  1003. }
  1004. }
  1005. function processOrientation(entity, packet, entityCollection, sourceUri) {
  1006. var orientationData = packet.orientation;
  1007. if (defined(orientationData)) {
  1008. processPacketData(Quaternion, entity, 'orientation', orientationData, undefined, sourceUri, entityCollection);
  1009. }
  1010. }
  1011. function processProperties(entity, packet, entityCollection, sourceUri) {
  1012. var propertiesData = packet.properties;
  1013. if (defined(propertiesData)) {
  1014. if (!defined(entity.properties)) {
  1015. entity.properties = new PropertyBag();
  1016. }
  1017. // We cannot simply call processPacketData(entity, 'properties', propertyData, undefined, sourceUri, entityCollection)
  1018. // because each property of "properties" may vary separately.
  1019. // The properties will be accessible as entity.properties.myprop.getValue(time).
  1020. for (var key in propertiesData) {
  1021. if (propertiesData.hasOwnProperty(key)) {
  1022. if (!entity.properties.hasProperty(key)) {
  1023. entity.properties.addProperty(key);
  1024. }
  1025. var propertyData = propertiesData[key];
  1026. if (isArray(propertyData)) {
  1027. for (var i = 0, len = propertyData.length; i < len; ++i) {
  1028. processProperty(getPropertyType(propertyData[i]), entity.properties, key, propertyData[i], undefined, sourceUri, entityCollection);
  1029. }
  1030. } else {
  1031. processProperty(getPropertyType(propertyData), entity.properties, key, propertyData, undefined, sourceUri, entityCollection);
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. function processReferencesArrayPacketData(object, propertyName, references, interval, entityCollection, PropertyArrayType, CompositePropertyArrayType) {
  1038. var properties = references.map(function(reference) {
  1039. return createReferenceProperty(entityCollection, reference);
  1040. });
  1041. if (defined(interval)) {
  1042. interval = intervalFromString(interval);
  1043. var property = object[propertyName];
  1044. if (!(property instanceof CompositePropertyArrayType)) {
  1045. // If the property was not already a CompositeProperty,
  1046. // create a CompositeProperty but preserve the existing data.
  1047. // Create the composite and add the old property, wrapped in an infinite interval.
  1048. var composite = new CompositePropertyArrayType();
  1049. composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));
  1050. object[propertyName] = property = composite;
  1051. }
  1052. interval.data = new PropertyArrayType(properties);
  1053. property.intervals.addInterval(interval);
  1054. } else {
  1055. object[propertyName] = new PropertyArrayType(properties);
  1056. }
  1057. }
  1058. function processArrayPacketData(object, propertyName, packetData, entityCollection) {
  1059. var references = packetData.references;
  1060. if (defined(references)) {
  1061. processReferencesArrayPacketData(object, propertyName, references, packetData.interval, entityCollection, PropertyArray, CompositeProperty);
  1062. } else {
  1063. processPacketData(Array, object, propertyName, packetData, undefined, undefined, entityCollection);
  1064. }
  1065. }
  1066. function processArray(object, propertyName, packetData, entityCollection) {
  1067. if (!defined(packetData)) {
  1068. return;
  1069. }
  1070. if (isArray(packetData)) {
  1071. for (var i = 0, length = packetData.length; i < length; ++i) {
  1072. processArrayPacketData(object, propertyName, packetData[i], entityCollection);
  1073. }
  1074. } else {
  1075. processArrayPacketData(object, propertyName, packetData, entityCollection);
  1076. }
  1077. }
  1078. function processPositionArrayPacketData(object, propertyName, packetData, entityCollection) {
  1079. var references = packetData.references;
  1080. if (defined(references)) {
  1081. processReferencesArrayPacketData(object, propertyName, references, packetData.interval, entityCollection, PositionPropertyArray, CompositePositionProperty);
  1082. } else {
  1083. if (defined(packetData.cartesian)) {
  1084. packetData.array = Cartesian3.unpackArray(packetData.cartesian);
  1085. } else if (defined(packetData.cartographicRadians)) {
  1086. packetData.array = Cartesian3.fromRadiansArrayHeights(packetData.cartographicRadians);
  1087. } else if (defined(packetData.cartographicDegrees)) {
  1088. packetData.array = Cartesian3.fromDegreesArrayHeights(packetData.cartographicDegrees);
  1089. }
  1090. if (defined(packetData.array)) {
  1091. processPacketData(Array, object, propertyName, packetData, undefined, undefined, entityCollection);
  1092. }
  1093. }
  1094. }
  1095. function processPositionArray(object, propertyName, packetData, entityCollection) {
  1096. if (!defined(packetData)) {
  1097. return;
  1098. }
  1099. if (isArray(packetData)) {
  1100. for (var i = 0, length = packetData.length; i < length; ++i) {
  1101. processPositionArrayPacketData(object, propertyName, packetData[i], entityCollection);
  1102. }
  1103. } else {
  1104. processPositionArrayPacketData(object, propertyName, packetData, entityCollection);
  1105. }
  1106. }
  1107. function unpackCartesianArray(array) {
  1108. return Cartesian3.unpackArray(array);
  1109. }
  1110. function unpackCartographicRadiansArray(array) {
  1111. return Cartesian3.fromRadiansArrayHeights(array);
  1112. }
  1113. function unpackCartographicDegreesArray(array) {
  1114. return Cartesian3.fromDegreesArrayHeights(array);
  1115. }
  1116. function processPositionArrayOfArraysPacketData(object, propertyName, packetData, entityCollection) {
  1117. var references = packetData.references;
  1118. if (defined(references)) {
  1119. var properties = references.map(function(referenceArray) {
  1120. var tempObj = {};
  1121. processReferencesArrayPacketData(tempObj, 'positions', referenceArray, packetData.interval, entityCollection, PositionPropertyArray, CompositePositionProperty);
  1122. return tempObj.positions;
  1123. });
  1124. object[propertyName] = new PositionPropertyArray(properties);
  1125. } else {
  1126. if (defined(packetData.cartesian)) {
  1127. packetData.array = packetData.cartesian.map(unpackCartesianArray);
  1128. } else if (defined(packetData.cartographicRadians)) {
  1129. packetData.array = packetData.cartographicRadians.map(unpackCartographicRadiansArray);
  1130. } else if (defined(packetData.cartographicDegrees)) {
  1131. packetData.array = packetData.cartographicDegrees.map(unpackCartographicDegreesArray);
  1132. }
  1133. if (defined(packetData.array)) {
  1134. processPacketData(Array, object, propertyName, packetData, undefined, undefined, entityCollection);
  1135. }
  1136. }
  1137. }
  1138. function processPositionArrayOfArrays(object, propertyName, packetData, entityCollection) {
  1139. if (!defined(packetData)) {
  1140. return;
  1141. }
  1142. if (isArray(packetData)) {
  1143. for (var i = 0, length = packetData.length; i < length; ++i) {
  1144. processPositionArrayOfArraysPacketData(object, propertyName, packetData[i], entityCollection);
  1145. }
  1146. } else {
  1147. processPositionArrayOfArraysPacketData(object, propertyName, packetData, entityCollection);
  1148. }
  1149. }
  1150. function processAvailability(entity, packet, entityCollection, sourceUri) {
  1151. var packetData = packet.availability;
  1152. if (!defined(packetData)) {
  1153. return;
  1154. }
  1155. var intervals;
  1156. if (isArray(packetData)) {
  1157. for (var i = 0, len = packetData.length; i < len; ++i) {
  1158. if (!defined(intervals)) {
  1159. intervals = new TimeIntervalCollection();
  1160. }
  1161. intervals.addInterval(intervalFromString(packetData[i]));
  1162. }
  1163. } else {
  1164. intervals = new TimeIntervalCollection();
  1165. intervals.addInterval(intervalFromString(packetData));
  1166. }
  1167. entity.availability = intervals;
  1168. }
  1169. function processAlignedAxis(billboard, packetData, interval, sourceUri, entityCollection) {
  1170. if (!defined(packetData)) {
  1171. return;
  1172. }
  1173. processPacketData(UnitCartesian3, billboard, 'alignedAxis', packetData, interval, sourceUri, entityCollection);
  1174. }
  1175. function processBillboard(entity, packet, entityCollection, sourceUri) {
  1176. var billboardData = packet.billboard;
  1177. if (!defined(billboardData)) {
  1178. return;
  1179. }
  1180. var interval = intervalFromString(billboardData.interval);
  1181. var billboard = entity.billboard;
  1182. if (!defined(billboard)) {
  1183. entity.billboard = billboard = new BillboardGraphics();
  1184. }
  1185. processPacketData(Boolean, billboard, 'show', billboardData.show, interval, sourceUri, entityCollection);
  1186. processPacketData(Image, billboard, 'image', billboardData.image, interval, sourceUri, entityCollection);
  1187. processPacketData(Number, billboard, 'scale', billboardData.scale, interval, sourceUri, entityCollection);
  1188. processPacketData(Cartesian2, billboard, 'pixelOffset', billboardData.pixelOffset, interval, sourceUri, entityCollection);
  1189. processPacketData(Cartesian3, billboard, 'eyeOffset', billboardData.eyeOffset, interval, sourceUri, entityCollection);
  1190. processPacketData(HorizontalOrigin, billboard, 'horizontalOrigin', billboardData.horizontalOrigin, interval, sourceUri, entityCollection);
  1191. processPacketData(VerticalOrigin, billboard, 'verticalOrigin', billboardData.verticalOrigin, interval, sourceUri, entityCollection);
  1192. processPacketData(HeightReference, billboard, 'heightReference', billboardData.heightReference, interval, sourceUri, entityCollection);
  1193. processPacketData(Color, billboard, 'color', billboardData.color, interval, sourceUri, entityCollection);
  1194. processPacketData(Rotation, billboard, 'rotation', billboardData.rotation, interval, sourceUri, entityCollection);
  1195. processAlignedAxis(billboard, billboardData.alignedAxis, interval, sourceUri, entityCollection);
  1196. processPacketData(Boolean, billboard, 'sizeInMeters', billboardData.sizeInMeters, interval, sourceUri, entityCollection);
  1197. processPacketData(Number, billboard, 'width', billboardData.width, interval, sourceUri, entityCollection);
  1198. processPacketData(Number, billboard, 'height', billboardData.height, interval, sourceUri, entityCollection);
  1199. processPacketData(NearFarScalar, billboard, 'scaleByDistance', billboardData.scaleByDistance, interval, sourceUri, entityCollection);
  1200. processPacketData(NearFarScalar, billboard, 'translucencyByDistance', billboardData.translucencyByDistance, interval, sourceUri, entityCollection);
  1201. processPacketData(NearFarScalar, billboard, 'pixelOffsetScaleByDistance', billboardData.pixelOffsetScaleByDistance, interval, sourceUri, entityCollection);
  1202. processPacketData(BoundingRectangle, billboard, 'imageSubRegion', billboardData.imageSubRegion, interval, sourceUri, entityCollection);
  1203. processPacketData(DistanceDisplayCondition, billboard, 'distanceDisplayCondition', billboardData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1204. processPacketData(Number, billboard, 'disableDepthTestDistance', billboardData.disableDepthTestDistance, interval, sourceUri, entityCollection);
  1205. }
  1206. function processBox(entity, packet, entityCollection, sourceUri) {
  1207. var boxData = packet.box;
  1208. if (!defined(boxData)) {
  1209. return;
  1210. }
  1211. var interval = intervalFromString(boxData.interval);
  1212. var box = entity.box;
  1213. if (!defined(box)) {
  1214. entity.box = box = new BoxGraphics();
  1215. }
  1216. processPacketData(Boolean, box, 'show', boxData.show, interval, sourceUri, entityCollection);
  1217. processPacketData(Cartesian3, box, 'dimensions', boxData.dimensions, interval, sourceUri, entityCollection);
  1218. processPacketData(HeightReference, box, 'heightReference', boxData.heightReference, interval, sourceUri, entityCollection);
  1219. processPacketData(Boolean, box, 'fill', boxData.fill, interval, sourceUri, entityCollection);
  1220. processMaterialPacketData(box, 'material', boxData.material, interval, sourceUri, entityCollection);
  1221. processPacketData(Boolean, box, 'outline', boxData.outline, interval, sourceUri, entityCollection);
  1222. processPacketData(Color, box, 'outlineColor', boxData.outlineColor, interval, sourceUri, entityCollection);
  1223. processPacketData(Number, box, 'outlineWidth', boxData.outlineWidth, interval, sourceUri, entityCollection);
  1224. processPacketData(ShadowMode, box, 'shadows', boxData.shadows, interval, sourceUri, entityCollection);
  1225. processPacketData(DistanceDisplayCondition, box, 'distanceDisplayCondition', boxData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1226. }
  1227. function processCorridor(entity, packet, entityCollection, sourceUri) {
  1228. var corridorData = packet.corridor;
  1229. if (!defined(corridorData)) {
  1230. return;
  1231. }
  1232. var interval = intervalFromString(corridorData.interval);
  1233. var corridor = entity.corridor;
  1234. if (!defined(corridor)) {
  1235. entity.corridor = corridor = new CorridorGraphics();
  1236. }
  1237. processPacketData(Boolean, corridor, 'show', corridorData.show, interval, sourceUri, entityCollection);
  1238. processPositionArray(corridor, 'positions', corridorData.positions, entityCollection);
  1239. processPacketData(Number, corridor, 'width', corridorData.width, interval, sourceUri, entityCollection);
  1240. processPacketData(Number, corridor, 'height', corridorData.height, interval, sourceUri, entityCollection);
  1241. processPacketData(HeightReference, corridor, 'heightReference', corridorData.heightReference, interval, sourceUri, entityCollection);
  1242. processPacketData(Number, corridor, 'extrudedHeight', corridorData.extrudedHeight, interval, sourceUri, entityCollection);
  1243. processPacketData(HeightReference, corridor, 'extrudedHeightReference', corridorData.extrudedHeightReference, interval, sourceUri, entityCollection);
  1244. processPacketData(CornerType, corridor, 'cornerType', corridorData.cornerType, interval, sourceUri, entityCollection);
  1245. processPacketData(Number, corridor, 'granularity', corridorData.granularity, interval, sourceUri, entityCollection);
  1246. processPacketData(Boolean, corridor, 'fill', corridorData.fill, interval, sourceUri, entityCollection);
  1247. processMaterialPacketData(corridor, 'material', corridorData.material, interval, sourceUri, entityCollection);
  1248. processPacketData(Boolean, corridor, 'outline', corridorData.outline, interval, sourceUri, entityCollection);
  1249. processPacketData(Color, corridor, 'outlineColor', corridorData.outlineColor, interval, sourceUri, entityCollection);
  1250. processPacketData(Number, corridor, 'outlineWidth', corridorData.outlineWidth, interval, sourceUri, entityCollection);
  1251. processPacketData(ShadowMode, corridor, 'shadows', corridorData.shadows, interval, sourceUri, entityCollection);
  1252. processPacketData(DistanceDisplayCondition, corridor, 'distanceDisplayCondition', corridorData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1253. processPacketData(ClassificationType, corridor, 'classificationType', corridorData.classificationType, interval, sourceUri, entityCollection);
  1254. processPacketData(Number, corridor, 'zIndex', corridorData.zIndex, interval, sourceUri, entityCollection);
  1255. }
  1256. function processCylinder(entity, packet, entityCollection, sourceUri) {
  1257. var cylinderData = packet.cylinder;
  1258. if (!defined(cylinderData)) {
  1259. return;
  1260. }
  1261. var interval = intervalFromString(cylinderData.interval);
  1262. var cylinder = entity.cylinder;
  1263. if (!defined(cylinder)) {
  1264. entity.cylinder = cylinder = new CylinderGraphics();
  1265. }
  1266. processPacketData(Boolean, cylinder, 'show', cylinderData.show, interval, sourceUri, entityCollection);
  1267. processPacketData(Number, cylinder, 'length', cylinderData.length, interval, sourceUri, entityCollection);
  1268. processPacketData(Number, cylinder, 'topRadius', cylinderData.topRadius, interval, sourceUri, entityCollection);
  1269. processPacketData(Number, cylinder, 'bottomRadius', cylinderData.bottomRadius, interval, sourceUri, entityCollection);
  1270. processPacketData(HeightReference, cylinder, 'heightReference', cylinderData.heightReference, interval, sourceUri, entityCollection);
  1271. processPacketData(Boolean, cylinder, 'fill', cylinderData.fill, interval, sourceUri, entityCollection);
  1272. processMaterialPacketData(cylinder, 'material', cylinderData.material, interval, sourceUri, entityCollection);
  1273. processPacketData(Boolean, cylinder, 'outline', cylinderData.outline, interval, sourceUri, entityCollection);
  1274. processPacketData(Color, cylinder, 'outlineColor', cylinderData.outlineColor, interval, sourceUri, entityCollection);
  1275. processPacketData(Number, cylinder, 'outlineWidth', cylinderData.outlineWidth, interval, sourceUri, entityCollection);
  1276. processPacketData(Number, cylinder, 'numberOfVerticalLines', cylinderData.numberOfVerticalLines, interval, sourceUri, entityCollection);
  1277. processPacketData(Number, cylinder, 'slices', cylinderData.slices, interval, sourceUri, entityCollection);
  1278. processPacketData(ShadowMode, cylinder, 'shadows', cylinderData.shadows, interval, sourceUri, entityCollection);
  1279. processPacketData(DistanceDisplayCondition, cylinder, 'distanceDisplayCondition', cylinderData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1280. }
  1281. function processDocument(packet, dataSource) {
  1282. var version = packet.version;
  1283. if (defined(version)) {
  1284. if (typeof version === 'string') {
  1285. var tokens = version.split('.');
  1286. if (tokens.length === 2) {
  1287. if (tokens[0] !== '1') {
  1288. throw new RuntimeError('Cesium only supports CZML version 1.');
  1289. }
  1290. dataSource._version = version;
  1291. }
  1292. }
  1293. }
  1294. if (!defined(dataSource._version)) {
  1295. throw new RuntimeError('CZML version information invalid. It is expected to be a property on the document object in the <Major>.<Minor> version format.');
  1296. }
  1297. var documentPacket = dataSource._documentPacket;
  1298. if (defined(packet.name)) {
  1299. documentPacket.name = packet.name;
  1300. }
  1301. var clockPacket = packet.clock;
  1302. if (defined(clockPacket)) {
  1303. var clock = documentPacket.clock;
  1304. if (!defined(clock)) {
  1305. documentPacket.clock = {
  1306. interval : clockPacket.interval,
  1307. currentTime : clockPacket.currentTime,
  1308. range : clockPacket.range,
  1309. step : clockPacket.step,
  1310. multiplier : clockPacket.multiplier
  1311. };
  1312. } else {
  1313. clock.interval = defaultValue(clockPacket.interval, clock.interval);
  1314. clock.currentTime = defaultValue(clockPacket.currentTime, clock.currentTime);
  1315. clock.range = defaultValue(clockPacket.range, clock.range);
  1316. clock.step = defaultValue(clockPacket.step, clock.step);
  1317. clock.multiplier = defaultValue(clockPacket.multiplier, clock.multiplier);
  1318. }
  1319. }
  1320. }
  1321. function processEllipse(entity, packet, entityCollection, sourceUri) {
  1322. var ellipseData = packet.ellipse;
  1323. if (!defined(ellipseData)) {
  1324. return;
  1325. }
  1326. var interval = intervalFromString(ellipseData.interval);
  1327. var ellipse = entity.ellipse;
  1328. if (!defined(ellipse)) {
  1329. entity.ellipse = ellipse = new EllipseGraphics();
  1330. }
  1331. processPacketData(Boolean, ellipse, 'show', ellipseData.show, interval, sourceUri, entityCollection);
  1332. processPacketData(Number, ellipse, 'semiMajorAxis', ellipseData.semiMajorAxis, interval, sourceUri, entityCollection);
  1333. processPacketData(Number, ellipse, 'semiMinorAxis', ellipseData.semiMinorAxis, interval, sourceUri, entityCollection);
  1334. processPacketData(Number, ellipse, 'height', ellipseData.height, interval, sourceUri, entityCollection);
  1335. processPacketData(HeightReference, ellipse, 'heightReference', ellipseData.heightReference, interval, sourceUri, entityCollection);
  1336. processPacketData(Number, ellipse, 'extrudedHeight', ellipseData.extrudedHeight, interval, sourceUri, entityCollection);
  1337. processPacketData(HeightReference, ellipse, 'extrudedHeightReference', ellipseData.extrudedHeightReference, interval, sourceUri, entityCollection);
  1338. processPacketData(Rotation, ellipse, 'rotation', ellipseData.rotation, interval, sourceUri, entityCollection);
  1339. processPacketData(Rotation, ellipse, 'stRotation', ellipseData.stRotation, interval, sourceUri, entityCollection);
  1340. processPacketData(Number, ellipse, 'granularity', ellipseData.granularity, interval, sourceUri, entityCollection);
  1341. processPacketData(Boolean, ellipse, 'fill', ellipseData.fill, interval, sourceUri, entityCollection);
  1342. processMaterialPacketData(ellipse, 'material', ellipseData.material, interval, sourceUri, entityCollection);
  1343. processPacketData(Boolean, ellipse, 'outline', ellipseData.outline, interval, sourceUri, entityCollection);
  1344. processPacketData(Color, ellipse, 'outlineColor', ellipseData.outlineColor, interval, sourceUri, entityCollection);
  1345. processPacketData(Number, ellipse, 'outlineWidth', ellipseData.outlineWidth, interval, sourceUri, entityCollection);
  1346. processPacketData(Number, ellipse, 'numberOfVerticalLines', ellipseData.numberOfVerticalLines, interval, sourceUri, entityCollection);
  1347. processPacketData(ShadowMode, ellipse, 'shadows', ellipseData.shadows, interval, sourceUri, entityCollection);
  1348. processPacketData(DistanceDisplayCondition, ellipse, 'distanceDisplayCondition', ellipseData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1349. processPacketData(ClassificationType, ellipse, 'classificationType', ellipseData.classificationType, interval, sourceUri, entityCollection);
  1350. processPacketData(Number, ellipse, 'zIndex', ellipseData.zIndex, interval, sourceUri, entityCollection);
  1351. }
  1352. function processEllipsoid(entity, packet, entityCollection, sourceUri) {
  1353. var ellipsoidData = packet.ellipsoid;
  1354. if (!defined(ellipsoidData)) {
  1355. return;
  1356. }
  1357. var interval = intervalFromString(ellipsoidData.interval);
  1358. var ellipsoid = entity.ellipsoid;
  1359. if (!defined(ellipsoid)) {
  1360. entity.ellipsoid = ellipsoid = new EllipsoidGraphics();
  1361. }
  1362. processPacketData(Boolean, ellipsoid, 'show', ellipsoidData.show, interval, sourceUri, entityCollection);
  1363. processPacketData(Cartesian3, ellipsoid, 'radii', ellipsoidData.radii, interval, sourceUri, entityCollection);
  1364. processPacketData(Cartesian3, ellipsoid, 'innerRadii', ellipsoidData.innerRadii, interval, sourceUri, entityCollection);
  1365. processPacketData(Number, ellipsoid, 'minimumClock', ellipsoidData.minimumClock, interval, sourceUri, entityCollection);
  1366. processPacketData(Number, ellipsoid, 'maximumClock', ellipsoidData.maximumClock, interval, sourceUri, entityCollection);
  1367. processPacketData(Number, ellipsoid, 'minimumCone', ellipsoidData.minimumCone, interval, sourceUri, entityCollection);
  1368. processPacketData(Number, ellipsoid, 'maximumCone', ellipsoidData.maximumCone, interval, sourceUri, entityCollection);
  1369. processPacketData(HeightReference, ellipsoid, 'heightReference', ellipsoidData.heightReference, interval, sourceUri, entityCollection);
  1370. processPacketData(Boolean, ellipsoid, 'fill', ellipsoidData.fill, interval, sourceUri, entityCollection);
  1371. processMaterialPacketData(ellipsoid, 'material', ellipsoidData.material, interval, sourceUri, entityCollection);
  1372. processPacketData(Boolean, ellipsoid, 'outline', ellipsoidData.outline, interval, sourceUri, entityCollection);
  1373. processPacketData(Color, ellipsoid, 'outlineColor', ellipsoidData.outlineColor, interval, sourceUri, entityCollection);
  1374. processPacketData(Number, ellipsoid, 'outlineWidth', ellipsoidData.outlineWidth, interval, sourceUri, entityCollection);
  1375. processPacketData(Number, ellipsoid, 'stackPartitions', ellipsoidData.stackPartitions, interval, sourceUri, entityCollection);
  1376. processPacketData(Number, ellipsoid, 'slicePartitions', ellipsoidData.slicePartitions, interval, sourceUri, entityCollection);
  1377. processPacketData(Number, ellipsoid, 'subdivisions', ellipsoidData.subdivisions, interval, sourceUri, entityCollection);
  1378. processPacketData(ShadowMode, ellipsoid, 'shadows', ellipsoidData.shadows, interval, sourceUri, entityCollection);
  1379. processPacketData(DistanceDisplayCondition, ellipsoid, 'distanceDisplayCondition', ellipsoidData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1380. }
  1381. function processLabel(entity, packet, entityCollection, sourceUri) {
  1382. var labelData = packet.label;
  1383. if (!defined(labelData)) {
  1384. return;
  1385. }
  1386. var interval = intervalFromString(labelData.interval);
  1387. var label = entity.label;
  1388. if (!defined(label)) {
  1389. entity.label = label = new LabelGraphics();
  1390. }
  1391. processPacketData(Boolean, label, 'show', labelData.show, interval, sourceUri, entityCollection);
  1392. processPacketData(String, label, 'text', labelData.text, interval, sourceUri, entityCollection);
  1393. processPacketData(String, label, 'font', labelData.font, interval, sourceUri, entityCollection);
  1394. processPacketData(LabelStyle, label, 'style', labelData.style, interval, sourceUri, entityCollection);
  1395. processPacketData(Number, label, 'scale', labelData.scale, interval, sourceUri, entityCollection);
  1396. processPacketData(Boolean, label, 'showBackground', labelData.showBackground, interval, sourceUri, entityCollection);
  1397. processPacketData(Color, label, 'backgroundColor', labelData.backgroundColor, interval, sourceUri, entityCollection);
  1398. processPacketData(Cartesian2, label, 'backgroundPadding', labelData.backgroundPadding, interval, sourceUri, entityCollection);
  1399. processPacketData(Cartesian2, label, 'pixelOffset', labelData.pixelOffset, interval, sourceUri, entityCollection);
  1400. processPacketData(Cartesian3, label, 'eyeOffset', labelData.eyeOffset, interval, sourceUri, entityCollection);
  1401. processPacketData(HorizontalOrigin, label, 'horizontalOrigin', labelData.horizontalOrigin, interval, sourceUri, entityCollection);
  1402. processPacketData(VerticalOrigin, label, 'verticalOrigin', labelData.verticalOrigin, interval, sourceUri, entityCollection);
  1403. processPacketData(HeightReference, label, 'heightReference', labelData.heightReference, interval, sourceUri, entityCollection);
  1404. processPacketData(Color, label, 'fillColor', labelData.fillColor, interval, sourceUri, entityCollection);
  1405. processPacketData(Color, label, 'outlineColor', labelData.outlineColor, interval, sourceUri, entityCollection);
  1406. processPacketData(Number, label, 'outlineWidth', labelData.outlineWidth, interval, sourceUri, entityCollection);
  1407. processPacketData(NearFarScalar, label, 'translucencyByDistance', labelData.translucencyByDistance, interval, sourceUri, entityCollection);
  1408. processPacketData(NearFarScalar, label, 'pixelOffsetScaleByDistance', labelData.pixelOffsetScaleByDistance, interval, sourceUri, entityCollection);
  1409. processPacketData(NearFarScalar, label, 'scaleByDistance', labelData.scaleByDistance, interval, sourceUri, entityCollection);
  1410. processPacketData(DistanceDisplayCondition, label, 'distanceDisplayCondition', labelData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1411. processPacketData(Number, label, 'disableDepthTestDistance', labelData.disableDepthTestDistance, interval, sourceUri, entityCollection);
  1412. }
  1413. function processModel(entity, packet, entityCollection, sourceUri) {
  1414. var modelData = packet.model;
  1415. if (!defined(modelData)) {
  1416. return;
  1417. }
  1418. var interval = intervalFromString(modelData.interval);
  1419. var model = entity.model;
  1420. if (!defined(model)) {
  1421. entity.model = model = new ModelGraphics();
  1422. }
  1423. processPacketData(Boolean, model, 'show', modelData.show, interval, sourceUri, entityCollection);
  1424. processPacketData(Uri, model, 'uri', modelData.gltf, interval, sourceUri, entityCollection);
  1425. processPacketData(Number, model, 'scale', modelData.scale, interval, sourceUri, entityCollection);
  1426. processPacketData(Number, model, 'minimumPixelSize', modelData.minimumPixelSize, interval, sourceUri, entityCollection);
  1427. processPacketData(Number, model, 'maximumScale', modelData.maximumScale, interval, sourceUri, entityCollection);
  1428. processPacketData(Boolean, model, 'incrementallyLoadTextures', modelData.incrementallyLoadTextures, interval, sourceUri, entityCollection);
  1429. processPacketData(Boolean, model, 'runAnimations', modelData.runAnimations, interval, sourceUri, entityCollection);
  1430. processPacketData(Boolean, model, 'clampAnimations', modelData.clampAnimations, interval, sourceUri, entityCollection);
  1431. processPacketData(ShadowMode, model, 'shadows', modelData.shadows, interval, sourceUri, entityCollection);
  1432. processPacketData(HeightReference, model, 'heightReference', modelData.heightReference, interval, sourceUri, entityCollection);
  1433. processPacketData(Color, model, 'silhouetteColor', modelData.silhouetteColor, interval, sourceUri, entityCollection);
  1434. processPacketData(Number, model, 'silhouetteSize', modelData.silhouetteSize, interval, sourceUri, entityCollection);
  1435. processPacketData(Color, model, 'color', modelData.color, interval, sourceUri, entityCollection);
  1436. processPacketData(ColorBlendMode, model, 'colorBlendMode', modelData.colorBlendMode, interval, sourceUri, entityCollection);
  1437. processPacketData(Number, model, 'colorBlendAmount', modelData.colorBlendAmount, interval, sourceUri, entityCollection);
  1438. processPacketData(DistanceDisplayCondition, model, 'distanceDisplayCondition', modelData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1439. var i, len;
  1440. var nodeTransformationsData = modelData.nodeTransformations;
  1441. if (defined(nodeTransformationsData)) {
  1442. if (isArray(nodeTransformationsData)) {
  1443. for (i = 0, len = nodeTransformationsData.length; i < len; ++i) {
  1444. processNodeTransformations(model, nodeTransformationsData[i], interval, sourceUri, entityCollection);
  1445. }
  1446. } else {
  1447. processNodeTransformations(model, nodeTransformationsData, interval, sourceUri, entityCollection);
  1448. }
  1449. }
  1450. var articulationsData = modelData.articulations;
  1451. if (defined(articulationsData)) {
  1452. if (isArray(articulationsData)) {
  1453. for (i = 0, len = articulationsData.length; i < len; ++i) {
  1454. processArticulations(model, articulationsData[i], interval, sourceUri, entityCollection);
  1455. }
  1456. } else {
  1457. processArticulations(model, articulationsData, interval, sourceUri, entityCollection);
  1458. }
  1459. }
  1460. }
  1461. function processNodeTransformations(model, nodeTransformationsData, constrainedInterval, sourceUri, entityCollection) {
  1462. var combinedInterval = intervalFromString(nodeTransformationsData.interval);
  1463. if (defined(constrainedInterval)) {
  1464. if (defined(combinedInterval)) {
  1465. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  1466. } else {
  1467. combinedInterval = constrainedInterval;
  1468. }
  1469. }
  1470. var nodeTransformations = model.nodeTransformations;
  1471. var nodeNames = Object.keys(nodeTransformationsData);
  1472. for (var i = 0, len = nodeNames.length; i < len; ++i) {
  1473. var nodeName = nodeNames[i];
  1474. if (nodeName === 'interval') {
  1475. continue;
  1476. }
  1477. var nodeTransformationData = nodeTransformationsData[nodeName];
  1478. if (!defined(nodeTransformationData)) {
  1479. continue;
  1480. }
  1481. if (!defined(nodeTransformations)) {
  1482. model.nodeTransformations = nodeTransformations = new PropertyBag();
  1483. }
  1484. if (!nodeTransformations.hasProperty(nodeName)) {
  1485. nodeTransformations.addProperty(nodeName);
  1486. }
  1487. var nodeTransformation = nodeTransformations[nodeName];
  1488. if (!defined(nodeTransformation)) {
  1489. nodeTransformations[nodeName] = nodeTransformation = new NodeTransformationProperty();
  1490. }
  1491. processPacketData(Cartesian3, nodeTransformation, 'translation', nodeTransformationData.translation, combinedInterval, sourceUri, entityCollection);
  1492. processPacketData(Quaternion, nodeTransformation, 'rotation', nodeTransformationData.rotation, combinedInterval, sourceUri, entityCollection);
  1493. processPacketData(Cartesian3, nodeTransformation, 'scale', nodeTransformationData.scale, combinedInterval, sourceUri, entityCollection);
  1494. }
  1495. }
  1496. function processArticulations(model, articulationsData, constrainedInterval, sourceUri, entityCollection) {
  1497. var combinedInterval = intervalFromString(articulationsData.interval);
  1498. if (defined(constrainedInterval)) {
  1499. if (defined(combinedInterval)) {
  1500. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  1501. } else {
  1502. combinedInterval = constrainedInterval;
  1503. }
  1504. }
  1505. var articulations = model.articulations;
  1506. var keys = Object.keys(articulationsData);
  1507. for (var i = 0, len = keys.length; i < len; ++i) {
  1508. var key = keys[i];
  1509. if (key === 'interval') {
  1510. continue;
  1511. }
  1512. var articulationStageData = articulationsData[key];
  1513. if (!defined(articulationStageData)) {
  1514. continue;
  1515. }
  1516. if (!defined(articulations)) {
  1517. model.articulations = articulations = new PropertyBag();
  1518. }
  1519. if (!articulations.hasProperty(key)) {
  1520. articulations.addProperty(key);
  1521. }
  1522. processPacketData(Number, articulations, key, articulationStageData, combinedInterval, sourceUri, entityCollection);
  1523. }
  1524. }
  1525. function processPath(entity, packet, entityCollection, sourceUri) {
  1526. var pathData = packet.path;
  1527. if (!defined(pathData)) {
  1528. return;
  1529. }
  1530. var interval = intervalFromString(pathData.interval);
  1531. var path = entity.path;
  1532. if (!defined(path)) {
  1533. entity.path = path = new PathGraphics();
  1534. }
  1535. processPacketData(Boolean, path, 'show', pathData.show, interval, sourceUri, entityCollection);
  1536. processPacketData(Number, path, 'leadTime', pathData.leadTime, interval, sourceUri, entityCollection);
  1537. processPacketData(Number, path, 'trailTime', pathData.trailTime, interval, sourceUri, entityCollection);
  1538. processPacketData(Number, path, 'width', pathData.width, interval, sourceUri, entityCollection);
  1539. processPacketData(Number, path, 'resolution', pathData.resolution, interval, sourceUri, entityCollection);
  1540. processMaterialPacketData(path, 'material', pathData.material, interval, sourceUri, entityCollection);
  1541. processPacketData(DistanceDisplayCondition, path, 'distanceDisplayCondition', pathData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1542. }
  1543. function processPoint(entity, packet, entityCollection, sourceUri) {
  1544. var pointData = packet.point;
  1545. if (!defined(pointData)) {
  1546. return;
  1547. }
  1548. var interval = intervalFromString(pointData.interval);
  1549. var point = entity.point;
  1550. if (!defined(point)) {
  1551. entity.point = point = new PointGraphics();
  1552. }
  1553. processPacketData(Boolean, point, 'show', pointData.show, interval, sourceUri, entityCollection);
  1554. processPacketData(Number, point, 'pixelSize', pointData.pixelSize, interval, sourceUri, entityCollection);
  1555. processPacketData(HeightReference, point, 'heightReference', pointData.heightReference, interval, sourceUri, entityCollection);
  1556. processPacketData(Color, point, 'color', pointData.color, interval, sourceUri, entityCollection);
  1557. processPacketData(Color, point, 'outlineColor', pointData.outlineColor, interval, sourceUri, entityCollection);
  1558. processPacketData(Number, point, 'outlineWidth', pointData.outlineWidth, interval, sourceUri, entityCollection);
  1559. processPacketData(NearFarScalar, point, 'scaleByDistance', pointData.scaleByDistance, interval, sourceUri, entityCollection);
  1560. processPacketData(NearFarScalar, point, 'translucencyByDistance', pointData.translucencyByDistance, interval, sourceUri, entityCollection);
  1561. processPacketData(DistanceDisplayCondition, point, 'distanceDisplayCondition', pointData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1562. processPacketData(Number, point, 'disableDepthTestDistance', pointData.disableDepthTestDistance, interval, sourceUri, entityCollection);
  1563. }
  1564. function PolygonHierarchyProperty(polygon) {
  1565. this.polygon = polygon;
  1566. this._definitionChanged = new Event();
  1567. }
  1568. defineProperties(PolygonHierarchyProperty.prototype, {
  1569. isConstant : {
  1570. get : function() {
  1571. var positions = this.polygon._positions;
  1572. var holes = this.polygon._holes;
  1573. return (!defined(positions) || positions.isConstant) &&
  1574. (!defined(holes) || holes.isConstant);
  1575. }
  1576. },
  1577. definitionChanged : {
  1578. get : function() {
  1579. return this._definitionChanged;
  1580. }
  1581. }
  1582. });
  1583. PolygonHierarchyProperty.prototype.getValue = function(time, result) {
  1584. var positions;
  1585. if (defined(this.polygon._positions)) {
  1586. positions = this.polygon._positions.getValue(time);
  1587. }
  1588. var holes;
  1589. if (defined(this.polygon._holes)) {
  1590. holes = this.polygon._holes.getValue(time);
  1591. if (defined(holes)) {
  1592. holes = holes.map(function(holePositions) {
  1593. return new PolygonHierarchy(holePositions);
  1594. });
  1595. }
  1596. }
  1597. if (!defined(result)) {
  1598. return new PolygonHierarchy(positions, holes);
  1599. }
  1600. result.positions = positions;
  1601. result.holes = holes;
  1602. return result;
  1603. };
  1604. PolygonHierarchyProperty.prototype.equals = function(other) {
  1605. return this === other ||
  1606. (other instanceof PolygonHierarchyProperty &&
  1607. Property.equals(this.polygon._positions, other.polygon._positions) &&
  1608. Property.equals(this.polygon._holes, other.polygon._holes));
  1609. };
  1610. function processPolygon(entity, packet, entityCollection, sourceUri) {
  1611. var polygonData = packet.polygon;
  1612. if (!defined(polygonData)) {
  1613. return;
  1614. }
  1615. var interval = intervalFromString(polygonData.interval);
  1616. var polygon = entity.polygon;
  1617. if (!defined(polygon)) {
  1618. entity.polygon = polygon = new PolygonGraphics();
  1619. }
  1620. processPacketData(Boolean, polygon, 'show', polygonData.show, interval, sourceUri, entityCollection);
  1621. // adapt 'position' property producing Cartesian[]
  1622. // and 'holes' property producing Cartesian[][]
  1623. // to a single property producing PolygonHierarchy
  1624. processPositionArray(polygon, '_positions', polygonData.positions, entityCollection);
  1625. processPositionArrayOfArrays(polygon, '_holes', polygonData.holes, entityCollection);
  1626. if (defined(polygon._positions) || defined(polygon._holes)) {
  1627. polygon.hierarchy = new PolygonHierarchyProperty(polygon);
  1628. }
  1629. processPacketData(Number, polygon, 'height', polygonData.height, interval, sourceUri, entityCollection);
  1630. processPacketData(HeightReference, polygon, 'heightReference', polygonData.heightReference, interval, sourceUri, entityCollection);
  1631. processPacketData(Number, polygon, 'extrudedHeight', polygonData.extrudedHeight, interval, sourceUri, entityCollection);
  1632. processPacketData(HeightReference, polygon, 'extrudedHeightReference', polygonData.extrudedHeightReference, interval, sourceUri, entityCollection);
  1633. processPacketData(Rotation, polygon, 'stRotation', polygonData.stRotation, interval, sourceUri, entityCollection);
  1634. processPacketData(Number, polygon, 'granularity', polygonData.granularity, interval, sourceUri, entityCollection);
  1635. processPacketData(Boolean, polygon, 'fill', polygonData.fill, interval, sourceUri, entityCollection);
  1636. processMaterialPacketData(polygon, 'material', polygonData.material, interval, sourceUri, entityCollection);
  1637. processPacketData(Boolean, polygon, 'outline', polygonData.outline, interval, sourceUri, entityCollection);
  1638. processPacketData(Color, polygon, 'outlineColor', polygonData.outlineColor, interval, sourceUri, entityCollection);
  1639. processPacketData(Number, polygon, 'outlineWidth', polygonData.outlineWidth, interval, sourceUri, entityCollection);
  1640. processPacketData(Boolean, polygon, 'perPositionHeight', polygonData.perPositionHeight, interval, sourceUri, entityCollection);
  1641. processPacketData(Boolean, polygon, 'closeTop', polygonData.closeTop, interval, sourceUri, entityCollection);
  1642. processPacketData(Boolean, polygon, 'closeBottom', polygonData.closeBottom, interval, sourceUri, entityCollection);
  1643. processPacketData(ArcType, polygon, 'arcType', polygonData.arcType, interval, sourceUri, entityCollection);
  1644. processPacketData(ShadowMode, polygon, 'shadows', polygonData.shadows, interval, sourceUri, entityCollection);
  1645. processPacketData(DistanceDisplayCondition, polygon, 'distanceDisplayCondition', polygonData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1646. processPacketData(ClassificationType, polygon, 'classificationType', polygonData.classificationType, interval, sourceUri, entityCollection);
  1647. processPacketData(Number, polygon, 'zIndex', polygonData.zIndex, interval, sourceUri, entityCollection);
  1648. }
  1649. function adaptFollowSurfaceToArcType(followSurface) {
  1650. return followSurface ? ArcType.GEODESIC : ArcType.NONE;
  1651. }
  1652. function processPolyline(entity, packet, entityCollection, sourceUri) {
  1653. var polylineData = packet.polyline;
  1654. if (!defined(polylineData)) {
  1655. return;
  1656. }
  1657. var interval = intervalFromString(polylineData.interval);
  1658. var polyline = entity.polyline;
  1659. if (!defined(polyline)) {
  1660. entity.polyline = polyline = new PolylineGraphics();
  1661. }
  1662. processPacketData(Boolean, polyline, 'show', polylineData.show, interval, sourceUri, entityCollection);
  1663. processPositionArray(polyline, 'positions', polylineData.positions, entityCollection);
  1664. processPacketData(Number, polyline, 'width', polylineData.width, interval, sourceUri, entityCollection);
  1665. processPacketData(Number, polyline, 'granularity', polylineData.granularity, interval, sourceUri, entityCollection);
  1666. processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection);
  1667. processMaterialPacketData(polyline, 'depthFailMaterial', polylineData.depthFailMaterial, interval, sourceUri, entityCollection);
  1668. processPacketData(ArcType, polyline, 'arcType', polylineData.arcType, interval, sourceUri, entityCollection);
  1669. processPacketData(Boolean, polyline, 'clampToGround', polylineData.clampToGround, interval, sourceUri, entityCollection);
  1670. processPacketData(ShadowMode, polyline, 'shadows', polylineData.shadows, interval, sourceUri, entityCollection);
  1671. processPacketData(DistanceDisplayCondition, polyline, 'distanceDisplayCondition', polylineData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1672. processPacketData(ClassificationType, polyline, 'classificationType', polylineData.classificationType, interval, sourceUri, entityCollection);
  1673. processPacketData(Number, polyline, 'zIndex', polylineData.zIndex, interval, sourceUri, entityCollection);
  1674. // for backwards compatibility, adapt CZML followSurface to arcType.
  1675. if (defined(polylineData.followSurface) && !defined(polylineData.arcType)) {
  1676. var tempObj = {};
  1677. processPacketData(Boolean, tempObj, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection);
  1678. polyline.arcType = createAdapterProperty(tempObj.followSurface, adaptFollowSurfaceToArcType);
  1679. }
  1680. }
  1681. function processRectangle(entity, packet, entityCollection, sourceUri) {
  1682. var rectangleData = packet.rectangle;
  1683. if (!defined(rectangleData)) {
  1684. return;
  1685. }
  1686. var interval = intervalFromString(rectangleData.interval);
  1687. var rectangle = entity.rectangle;
  1688. if (!defined(rectangle)) {
  1689. entity.rectangle = rectangle = new RectangleGraphics();
  1690. }
  1691. processPacketData(Boolean, rectangle, 'show', rectangleData.show, interval, sourceUri, entityCollection);
  1692. processPacketData(Rectangle, rectangle, 'coordinates', rectangleData.coordinates, interval, sourceUri, entityCollection);
  1693. processPacketData(Number, rectangle, 'height', rectangleData.height, interval, sourceUri, entityCollection);
  1694. processPacketData(HeightReference, rectangle, 'heightReference', rectangleData.heightReference, interval, sourceUri, entityCollection);
  1695. processPacketData(Number, rectangle, 'extrudedHeight', rectangleData.extrudedHeight, interval, sourceUri, entityCollection);
  1696. processPacketData(HeightReference, rectangle, 'extrudedHeightReference', rectangleData.extrudedHeightReference, interval, sourceUri, entityCollection);
  1697. processPacketData(Rotation, rectangle, 'rotation', rectangleData.rotation, interval, sourceUri, entityCollection);
  1698. processPacketData(Rotation, rectangle, 'stRotation', rectangleData.stRotation, interval, sourceUri, entityCollection);
  1699. processPacketData(Number, rectangle, 'granularity', rectangleData.granularity, interval, sourceUri, entityCollection);
  1700. processPacketData(Boolean, rectangle, 'fill', rectangleData.fill, interval, sourceUri, entityCollection);
  1701. processMaterialPacketData(rectangle, 'material', rectangleData.material, interval, sourceUri, entityCollection);
  1702. processPacketData(Boolean, rectangle, 'outline', rectangleData.outline, interval, sourceUri, entityCollection);
  1703. processPacketData(Color, rectangle, 'outlineColor', rectangleData.outlineColor, interval, sourceUri, entityCollection);
  1704. processPacketData(Number, rectangle, 'outlineWidth', rectangleData.outlineWidth, interval, sourceUri, entityCollection);
  1705. processPacketData(ShadowMode, rectangle, 'shadows', rectangleData.shadows, interval, sourceUri, entityCollection);
  1706. processPacketData(DistanceDisplayCondition, rectangle, 'distanceDisplayCondition', rectangleData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1707. processPacketData(ClassificationType, rectangle, 'classificationType', rectangleData.classificationType, interval, sourceUri, entityCollection);
  1708. processPacketData(Number, rectangle, 'zIndex', rectangleData.zIndex, interval, sourceUri, entityCollection);
  1709. }
  1710. function processWall(entity, packet, entityCollection, sourceUri) {
  1711. var wallData = packet.wall;
  1712. if (!defined(wallData)) {
  1713. return;
  1714. }
  1715. var interval = intervalFromString(wallData.interval);
  1716. var wall = entity.wall;
  1717. if (!defined(wall)) {
  1718. entity.wall = wall = new WallGraphics();
  1719. }
  1720. processPacketData(Boolean, wall, 'show', wallData.show, interval, sourceUri, entityCollection);
  1721. processPositionArray(wall, 'positions', wallData.positions, entityCollection);
  1722. processArray(wall, 'minimumHeights', wallData.minimumHeights, entityCollection);
  1723. processArray(wall, 'maximumHeights', wallData.maximumHeights, entityCollection);
  1724. processPacketData(Number, wall, 'granularity', wallData.granularity, interval, sourceUri, entityCollection);
  1725. processPacketData(Boolean, wall, 'fill', wallData.fill, interval, sourceUri, entityCollection);
  1726. processMaterialPacketData(wall, 'material', wallData.material, interval, sourceUri, entityCollection);
  1727. processPacketData(Boolean, wall, 'outline', wallData.outline, interval, sourceUri, entityCollection);
  1728. processPacketData(Color, wall, 'outlineColor', wallData.outlineColor, interval, sourceUri, entityCollection);
  1729. processPacketData(Number, wall, 'outlineWidth', wallData.outlineWidth, interval, sourceUri, entityCollection);
  1730. processPacketData(ShadowMode, wall, 'shadows', wallData.shadows, interval, sourceUri, entityCollection);
  1731. processPacketData(DistanceDisplayCondition, wall, 'distanceDisplayCondition', wallData.distanceDisplayCondition, interval, sourceUri, entityCollection);
  1732. }
  1733. function processCzmlPacket(packet, entityCollection, updaterFunctions, sourceUri, dataSource) {
  1734. var objectId = packet.id;
  1735. if (!defined(objectId)) {
  1736. objectId = createGuid();
  1737. }
  1738. currentId = objectId;
  1739. if (!defined(dataSource._version) && objectId !== 'document') {
  1740. throw new RuntimeError('The first CZML packet is required to be the document object.');
  1741. }
  1742. if (packet['delete'] === true) {
  1743. entityCollection.removeById(objectId);
  1744. } else if (objectId === 'document') {
  1745. processDocument(packet, dataSource);
  1746. } else {
  1747. var entity = entityCollection.getOrCreateEntity(objectId);
  1748. var parentId = packet.parent;
  1749. if (defined(parentId)) {
  1750. entity.parent = entityCollection.getOrCreateEntity(parentId);
  1751. }
  1752. for (var i = updaterFunctions.length - 1; i > -1; i--) {
  1753. updaterFunctions[i](entity, packet, entityCollection, sourceUri);
  1754. }
  1755. }
  1756. currentId = undefined;
  1757. }
  1758. function updateClock(dataSource) {
  1759. var clock;
  1760. var clockPacket = dataSource._documentPacket.clock;
  1761. if (!defined(clockPacket)) {
  1762. if (!defined(dataSource._clock)) {
  1763. var availability = dataSource._entityCollection.computeAvailability();
  1764. if (!availability.start.equals(Iso8601.MINIMUM_VALUE)) {
  1765. var startTime = availability.start;
  1766. var stopTime = availability.stop;
  1767. var totalSeconds = JulianDate.secondsDifference(stopTime, startTime);
  1768. var multiplier = Math.round(totalSeconds / 120.0);
  1769. clock = new DataSourceClock();
  1770. clock.startTime = JulianDate.clone(startTime);
  1771. clock.stopTime = JulianDate.clone(stopTime);
  1772. clock.clockRange = ClockRange.LOOP_STOP;
  1773. clock.multiplier = multiplier;
  1774. clock.currentTime = JulianDate.clone(startTime);
  1775. clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  1776. dataSource._clock = clock;
  1777. return true;
  1778. }
  1779. }
  1780. return false;
  1781. }
  1782. if (defined(dataSource._clock)) {
  1783. clock = dataSource._clock.clone();
  1784. } else {
  1785. clock = new DataSourceClock();
  1786. clock.startTime = Iso8601.MINIMUM_VALUE.clone();
  1787. clock.stopTime = Iso8601.MAXIMUM_VALUE.clone();
  1788. clock.currentTime = Iso8601.MINIMUM_VALUE.clone();
  1789. clock.clockRange = ClockRange.LOOP_STOP;
  1790. clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  1791. clock.multiplier = 1.0;
  1792. }
  1793. var interval = intervalFromString(clockPacket.interval);
  1794. if (defined(interval)) {
  1795. clock.startTime = interval.start;
  1796. clock.stopTime = interval.stop;
  1797. }
  1798. if (defined(clockPacket.currentTime)) {
  1799. clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime);
  1800. }
  1801. if (defined(clockPacket.range)) {
  1802. clock.clockRange = defaultValue(ClockRange[clockPacket.range], ClockRange.LOOP_STOP);
  1803. }
  1804. if (defined(clockPacket.step)) {
  1805. clock.clockStep = defaultValue(ClockStep[clockPacket.step], ClockStep.SYSTEM_CLOCK_MULTIPLIER);
  1806. }
  1807. if (defined(clockPacket.multiplier)) {
  1808. clock.multiplier = clockPacket.multiplier;
  1809. }
  1810. if (!clock.equals(dataSource._clock)) {
  1811. dataSource._clock = clock.clone(dataSource._clock);
  1812. return true;
  1813. }
  1814. return false;
  1815. }
  1816. function load(dataSource, czml, options, clear) {
  1817. //>>includeStart('debug', pragmas.debug);
  1818. if (!defined(czml)) {
  1819. throw new DeveloperError('czml is required.');
  1820. }
  1821. //>>includeEnd('debug');
  1822. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  1823. var promise = czml;
  1824. var sourceUri = options.sourceUri;
  1825. // User specified credit
  1826. var credit = options.credit;
  1827. if (typeof credit === 'string') {
  1828. credit = new Credit(credit);
  1829. }
  1830. dataSource._credit = credit;
  1831. // If the czml is a URL
  1832. if (typeof czml === 'string' || (czml instanceof Resource)) {
  1833. czml = Resource.createIfNeeded(czml);
  1834. promise = czml.fetchJson();
  1835. sourceUri = defaultValue(sourceUri, czml.clone());
  1836. // Add resource credits to our list of credits to display
  1837. var resourceCredits = dataSource._resourceCredits;
  1838. var credits = czml.credits;
  1839. if (defined(credits)) {
  1840. var length = credits.length;
  1841. for (var i = 0; i < length; i++) {
  1842. resourceCredits.push(credits[i]);
  1843. }
  1844. }
  1845. }
  1846. sourceUri = Resource.createIfNeeded(sourceUri);
  1847. DataSource.setLoading(dataSource, true);
  1848. return when(promise, function(czml) {
  1849. return loadCzml(dataSource, czml, sourceUri, clear);
  1850. }).otherwise(function(error) {
  1851. DataSource.setLoading(dataSource, false);
  1852. dataSource._error.raiseEvent(dataSource, error);
  1853. console.log(error);
  1854. return when.reject(error);
  1855. });
  1856. }
  1857. function loadCzml(dataSource, czml, sourceUri, clear) {
  1858. DataSource.setLoading(dataSource, true);
  1859. var entityCollection = dataSource._entityCollection;
  1860. if (clear) {
  1861. dataSource._version = undefined;
  1862. dataSource._documentPacket = new DocumentPacket();
  1863. entityCollection.removeAll();
  1864. }
  1865. CzmlDataSource._processCzml(czml, entityCollection, sourceUri, undefined, dataSource);
  1866. var raiseChangedEvent = updateClock(dataSource);
  1867. var documentPacket = dataSource._documentPacket;
  1868. if (defined(documentPacket.name) && dataSource._name !== documentPacket.name) {
  1869. dataSource._name = documentPacket.name;
  1870. raiseChangedEvent = true;
  1871. } else if (!defined(dataSource._name) && defined(sourceUri)) {
  1872. dataSource._name = getFilenameFromUri(sourceUri.getUrlComponent());
  1873. raiseChangedEvent = true;
  1874. }
  1875. DataSource.setLoading(dataSource, false);
  1876. if (raiseChangedEvent) {
  1877. dataSource._changed.raiseEvent(dataSource);
  1878. }
  1879. return dataSource;
  1880. }
  1881. function DocumentPacket() {
  1882. this.name = undefined;
  1883. this.clock = undefined;
  1884. }
  1885. /**
  1886. * A {@link DataSource} which processes {@link https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CZML-Guide|CZML}.
  1887. * @alias CzmlDataSource
  1888. * @constructor
  1889. *
  1890. * @param {String} [name] An optional name for the data source. This value will be overwritten if a loaded document contains a name.
  1891. *
  1892. * @demo {@link https://sandcastle.cesium.com/index.html?src=CZML.html|Cesium Sandcastle CZML Demo}
  1893. */
  1894. function CzmlDataSource(name) {
  1895. this._name = name;
  1896. this._changed = new Event();
  1897. this._error = new Event();
  1898. this._isLoading = false;
  1899. this._loading = new Event();
  1900. this._clock = undefined;
  1901. this._documentPacket = new DocumentPacket();
  1902. this._version = undefined;
  1903. this._entityCollection = new EntityCollection(this);
  1904. this._entityCluster = new EntityCluster();
  1905. this._credit = undefined;
  1906. this._resourceCredits = [];
  1907. }
  1908. /**
  1909. * Creates a Promise to a new instance loaded with the provided CZML data.
  1910. *
  1911. * @param {Resource|String|Object} czml A url or CZML object to be processed.
  1912. * @param {Object} [options] An object with the following properties:
  1913. * @param {Resource|String} [options.sourceUri] Overrides the url to use for resolving relative links.
  1914. * @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
  1915. * @returns {Promise.<CzmlDataSource>} A promise that resolves to the new instance once the data is processed.
  1916. */
  1917. CzmlDataSource.load = function(czml, options) {
  1918. return new CzmlDataSource().load(czml, options);
  1919. };
  1920. defineProperties(CzmlDataSource.prototype, {
  1921. /**
  1922. * Gets a human-readable name for this instance.
  1923. * @memberof CzmlDataSource.prototype
  1924. * @type {String}
  1925. */
  1926. name : {
  1927. get : function() {
  1928. return this._name;
  1929. }
  1930. },
  1931. /**
  1932. * Gets the clock settings defined by the loaded CZML. If no clock is explicitly
  1933. * defined in the CZML, the combined availability of all objects is returned. If
  1934. * only static data exists, this value is undefined.
  1935. * @memberof CzmlDataSource.prototype
  1936. * @type {DataSourceClock}
  1937. */
  1938. clock : {
  1939. get : function() {
  1940. return this._clock;
  1941. }
  1942. },
  1943. /**
  1944. * Gets the collection of {@link Entity} instances.
  1945. * @memberof CzmlDataSource.prototype
  1946. * @type {EntityCollection}
  1947. */
  1948. entities : {
  1949. get : function() {
  1950. return this._entityCollection;
  1951. }
  1952. },
  1953. /**
  1954. * Gets a value indicating if the data source is currently loading data.
  1955. * @memberof CzmlDataSource.prototype
  1956. * @type {Boolean}
  1957. */
  1958. isLoading : {
  1959. get : function() {
  1960. return this._isLoading;
  1961. }
  1962. },
  1963. /**
  1964. * Gets an event that will be raised when the underlying data changes.
  1965. * @memberof CzmlDataSource.prototype
  1966. * @type {Event}
  1967. */
  1968. changedEvent : {
  1969. get : function() {
  1970. return this._changed;
  1971. }
  1972. },
  1973. /**
  1974. * Gets an event that will be raised if an error is encountered during processing.
  1975. * @memberof CzmlDataSource.prototype
  1976. * @type {Event}
  1977. */
  1978. errorEvent : {
  1979. get : function() {
  1980. return this._error;
  1981. }
  1982. },
  1983. /**
  1984. * Gets an event that will be raised when the data source either starts or stops loading.
  1985. * @memberof CzmlDataSource.prototype
  1986. * @type {Event}
  1987. */
  1988. loadingEvent : {
  1989. get : function() {
  1990. return this._loading;
  1991. }
  1992. },
  1993. /**
  1994. * Gets whether or not this data source should be displayed.
  1995. * @memberof CzmlDataSource.prototype
  1996. * @type {Boolean}
  1997. */
  1998. show : {
  1999. get : function() {
  2000. return this._entityCollection.show;
  2001. },
  2002. set : function(value) {
  2003. this._entityCollection.show = value;
  2004. }
  2005. },
  2006. /**
  2007. * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.
  2008. *
  2009. * @memberof CzmlDataSource.prototype
  2010. * @type {EntityCluster}
  2011. */
  2012. clustering : {
  2013. get : function() {
  2014. return this._entityCluster;
  2015. },
  2016. set : function(value) {
  2017. //>>includeStart('debug', pragmas.debug);
  2018. if (!defined(value)) {
  2019. throw new DeveloperError('value must be defined.');
  2020. }
  2021. //>>includeEnd('debug');
  2022. this._entityCluster = value;
  2023. }
  2024. },
  2025. /**
  2026. * Gets the credit that will be displayed for the data source
  2027. * @memberof CzmlDataSource.prototype
  2028. * @type {Credit}
  2029. */
  2030. credit : {
  2031. get : function() {
  2032. return this._credit;
  2033. }
  2034. }
  2035. });
  2036. /**
  2037. * Gets the array of CZML processing functions.
  2038. * @memberof CzmlDataSource
  2039. * @type Array
  2040. */
  2041. CzmlDataSource.updaters = [
  2042. processBillboard, //
  2043. processBox, //
  2044. processCorridor, //
  2045. processCylinder, //
  2046. processEllipse, //
  2047. processEllipsoid, //
  2048. processLabel, //
  2049. processModel, //
  2050. processName, //
  2051. processDescription, //
  2052. processPath, //
  2053. processPoint, //
  2054. processPolygon, //
  2055. processPolyline, //
  2056. processProperties, //
  2057. processRectangle, //
  2058. processPosition, //
  2059. processViewFrom, //
  2060. processWall, //
  2061. processOrientation, //
  2062. processAvailability];
  2063. /**
  2064. * Processes the provided url or CZML object without clearing any existing data.
  2065. *
  2066. * @param {Resource|String|Object} czml A url or CZML object to be processed.
  2067. * @param {Object} [options] An object with the following properties:
  2068. * @param {String} [options.sourceUri] Overrides the url to use for resolving relative links.
  2069. * @returns {Promise.<CzmlDataSource>} A promise that resolves to this instances once the data is processed.
  2070. */
  2071. CzmlDataSource.prototype.process = function(czml, options) {
  2072. return load(this, czml, options, false);
  2073. };
  2074. /**
  2075. * Loads the provided url or CZML object, replacing any existing data.
  2076. *
  2077. * @param {Resource|String|Object} czml A url or CZML object to be processed.
  2078. * @param {Object} [options] An object with the following properties:
  2079. * @param {String} [options.sourceUri] Overrides the url to use for resolving relative links.
  2080. * @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
  2081. * @returns {Promise.<CzmlDataSource>} A promise that resolves to this instances once the data is processed.
  2082. */
  2083. CzmlDataSource.prototype.load = function(czml, options) {
  2084. return load(this, czml, options, true);
  2085. };
  2086. /**
  2087. * A helper function used by custom CZML updater functions
  2088. * which creates or updates a {@link Property} from a CZML packet.
  2089. * @function
  2090. *
  2091. * @param {Function} type The constructor function for the property being processed.
  2092. * @param {Object} object The object on which the property will be added or updated.
  2093. * @param {String} propertyName The name of the property on the object.
  2094. * @param {Object} packetData The CZML packet being processed.
  2095. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  2096. * @param {String} sourceUri The originating uri of the data being processed.
  2097. * @param {EntityCollection} entityCollection The collection being processsed.
  2098. */
  2099. CzmlDataSource.processPacketData = processPacketData;
  2100. /**
  2101. * A helper function used by custom CZML updater functions
  2102. * which creates or updates a {@link PositionProperty} from a CZML packet.
  2103. * @function
  2104. *
  2105. * @param {Object} object The object on which the property will be added or updated.
  2106. * @param {String} propertyName The name of the property on the object.
  2107. * @param {Object} packetData The CZML packet being processed.
  2108. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  2109. * @param {String} sourceUri The originating uri of the data being processed.
  2110. * @param {EntityCollection} entityCollection The collection being processsed.
  2111. */
  2112. CzmlDataSource.processPositionPacketData = processPositionPacketData;
  2113. /**
  2114. * A helper function used by custom CZML updater functions
  2115. * which creates or updates a {@link MaterialProperty} from a CZML packet.
  2116. * @function
  2117. *
  2118. * @param {Object} object The object on which the property will be added or updated.
  2119. * @param {String} propertyName The name of the property on the object.
  2120. * @param {Object} packetData The CZML packet being processed.
  2121. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  2122. * @param {String} sourceUri The originating uri of the data being processed.
  2123. * @param {EntityCollection} entityCollection The collection being processsed.
  2124. */
  2125. CzmlDataSource.processMaterialPacketData = processMaterialPacketData;
  2126. CzmlDataSource._processCzml = function(czml, entityCollection, sourceUri, updaterFunctions, dataSource) {
  2127. updaterFunctions = defaultValue(updaterFunctions, CzmlDataSource.updaters);
  2128. if (isArray(czml)) {
  2129. for (var i = 0, len = czml.length; i < len; ++i) {
  2130. processCzmlPacket(czml[i], entityCollection, updaterFunctions, sourceUri, dataSource);
  2131. }
  2132. } else {
  2133. processCzmlPacket(czml, entityCollection, updaterFunctions, sourceUri, dataSource);
  2134. }
  2135. };
  2136. export default CzmlDataSource;