CzmlDataSource.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  1. /*global define*/
  2. define([
  3. '../Core/Cartesian2',
  4. '../Core/Cartesian3',
  5. '../Core/Cartographic',
  6. '../Core/ClockRange',
  7. '../Core/ClockStep',
  8. '../Core/Color',
  9. '../Core/createGuid',
  10. '../Core/defaultValue',
  11. '../Core/defined',
  12. '../Core/defineProperties',
  13. '../Core/DeveloperError',
  14. '../Core/Ellipsoid',
  15. '../Core/Event',
  16. '../Core/ExtrapolationType',
  17. '../Core/getFilenameFromUri',
  18. '../Core/HermitePolynomialApproximation',
  19. '../Core/isArray',
  20. '../Core/Iso8601',
  21. '../Core/JulianDate',
  22. '../Core/LagrangePolynomialApproximation',
  23. '../Core/LinearApproximation',
  24. '../Core/loadJson',
  25. '../Core/Math',
  26. '../Core/Quaternion',
  27. '../Core/Rectangle',
  28. '../Core/ReferenceFrame',
  29. '../Core/RuntimeError',
  30. '../Core/Spherical',
  31. '../Core/TimeInterval',
  32. '../Core/TimeIntervalCollection',
  33. '../Scene/HorizontalOrigin',
  34. '../Scene/LabelStyle',
  35. '../Scene/VerticalOrigin',
  36. '../ThirdParty/Uri',
  37. '../ThirdParty/when',
  38. './BillboardGraphics',
  39. './ColorMaterialProperty',
  40. './CompositeMaterialProperty',
  41. './CompositePositionProperty',
  42. './CompositeProperty',
  43. './ConstantPositionProperty',
  44. './ConstantProperty',
  45. './DataSource',
  46. './DataSourceClock',
  47. './EllipseGraphics',
  48. './EllipsoidGraphics',
  49. './EntityCollection',
  50. './GridMaterialProperty',
  51. './ImageMaterialProperty',
  52. './LabelGraphics',
  53. './ModelGraphics',
  54. './PathGraphics',
  55. './PointGraphics',
  56. './PolygonGraphics',
  57. './PolylineGlowMaterialProperty',
  58. './PolylineGraphics',
  59. './PolylineOutlineMaterialProperty',
  60. './PositionPropertyArray',
  61. './RectangleGraphics',
  62. './ReferenceProperty',
  63. './SampledPositionProperty',
  64. './SampledProperty',
  65. './StripeMaterialProperty',
  66. './StripeOrientation',
  67. './TimeIntervalCollectionPositionProperty',
  68. './TimeIntervalCollectionProperty',
  69. './WallGraphics'
  70. ], function(
  71. Cartesian2,
  72. Cartesian3,
  73. Cartographic,
  74. ClockRange,
  75. ClockStep,
  76. Color,
  77. createGuid,
  78. defaultValue,
  79. defined,
  80. defineProperties,
  81. DeveloperError,
  82. Ellipsoid,
  83. Event,
  84. ExtrapolationType,
  85. getFilenameFromUri,
  86. HermitePolynomialApproximation,
  87. isArray,
  88. Iso8601,
  89. JulianDate,
  90. LagrangePolynomialApproximation,
  91. LinearApproximation,
  92. loadJson,
  93. CesiumMath,
  94. Quaternion,
  95. Rectangle,
  96. ReferenceFrame,
  97. RuntimeError,
  98. Spherical,
  99. TimeInterval,
  100. TimeIntervalCollection,
  101. HorizontalOrigin,
  102. LabelStyle,
  103. VerticalOrigin,
  104. Uri,
  105. when,
  106. BillboardGraphics,
  107. ColorMaterialProperty,
  108. CompositeMaterialProperty,
  109. CompositePositionProperty,
  110. CompositeProperty,
  111. ConstantPositionProperty,
  112. ConstantProperty,
  113. DataSource,
  114. DataSourceClock,
  115. EllipseGraphics,
  116. EllipsoidGraphics,
  117. EntityCollection,
  118. GridMaterialProperty,
  119. ImageMaterialProperty,
  120. LabelGraphics,
  121. ModelGraphics,
  122. PathGraphics,
  123. PointGraphics,
  124. PolygonGraphics,
  125. PolylineGlowMaterialProperty,
  126. PolylineGraphics,
  127. PolylineOutlineMaterialProperty,
  128. PositionPropertyArray,
  129. RectangleGraphics,
  130. ReferenceProperty,
  131. SampledPositionProperty,
  132. SampledProperty,
  133. StripeMaterialProperty,
  134. StripeOrientation,
  135. TimeIntervalCollectionPositionProperty,
  136. TimeIntervalCollectionProperty,
  137. WallGraphics) {
  138. "use strict";
  139. var currentId;
  140. function makeReference(collection, referenceString) {
  141. if (referenceString[0] === '#') {
  142. referenceString = currentId + referenceString;
  143. }
  144. return ReferenceProperty.fromString(collection, referenceString);
  145. }
  146. var scratchCartesian = new Cartesian3();
  147. var scratchSpherical = new Spherical();
  148. var scratchCartographic = new Cartographic();
  149. var scratchTimeInterval = new TimeInterval();
  150. function unwrapColorInterval(czmlInterval) {
  151. var rgbaf = czmlInterval.rgbaf;
  152. if (defined(rgbaf)) {
  153. return rgbaf;
  154. }
  155. var rgba = czmlInterval.rgba;
  156. if (!defined(rgba)) {
  157. return undefined;
  158. }
  159. if (rgba.length === Color.length) {
  160. return [Color.byteToFloat(rgba[0]), Color.byteToFloat(rgba[1]), Color.byteToFloat(rgba[2]), Color.byteToFloat(rgba[3])];
  161. }
  162. var len = rgba.length;
  163. rgbaf = new Array(len);
  164. for (var i = 0; i < len; i += 5) {
  165. rgbaf[i] = rgba[i];
  166. rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]);
  167. rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]);
  168. rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]);
  169. rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]);
  170. }
  171. return rgbaf;
  172. }
  173. function unwrapImageInterval(czmlInterval, sourceUri) {
  174. var result = defaultValue(czmlInterval.image, czmlInterval);
  175. if (defined(sourceUri)) {
  176. var baseUri = new Uri(document.location.href);
  177. sourceUri = new Uri(sourceUri);
  178. result = new Uri(result).resolve(sourceUri.resolve(baseUri)).toString();
  179. }
  180. return result;
  181. }
  182. function unwrapUriInterval(czmlInterval, sourceUri) {
  183. var result = defaultValue(czmlInterval.uri, czmlInterval);
  184. if (defined(sourceUri)) {
  185. var baseUri = new Uri(document.location.href);
  186. sourceUri = new Uri(sourceUri);
  187. result = new Uri(result).resolve(sourceUri.resolve(baseUri)).toString();
  188. }
  189. return result;
  190. }
  191. function unwrapRectangleInterval(czmlInterval) {
  192. var wsenDegrees = czmlInterval.wsenDegrees;
  193. if (defined(wsenDegrees)) {
  194. var length = wsenDegrees.length;
  195. for (var i = 0; i < length; i++) {
  196. wsenDegrees[i] = CesiumMath.toRadians(wsenDegrees[i]);
  197. }
  198. return wsenDegrees;
  199. }
  200. return czmlInterval.wsen;
  201. }
  202. function unwrapCartesianInterval(czmlInterval) {
  203. if (defined(czmlInterval.cartesian)) {
  204. return czmlInterval.cartesian;
  205. }
  206. if (defined(czmlInterval.cartesianVelocity)) {
  207. return czmlInterval.cartesianVelocity;
  208. }
  209. if (defined(czmlInterval.unitCartesian)) {
  210. return czmlInterval.unitCartesian;
  211. }
  212. var i;
  213. var len;
  214. var result;
  215. var unitSpherical = czmlInterval.unitSpherical;
  216. if (defined(unitSpherical)) {
  217. len = unitSpherical.length;
  218. if (len === 2) {
  219. scratchSpherical.clock = unitSpherical[0];
  220. scratchSpherical.cone = unitSpherical[1];
  221. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  222. result = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  223. } else {
  224. var sphericalIt = 0;
  225. result = new Array((len / 3) * 4);
  226. for (i = 0; i < len; i += 4) {
  227. result[i] = unitSpherical[sphericalIt++];
  228. scratchSpherical.clock = unitSpherical[sphericalIt++];
  229. scratchSpherical.cone = unitSpherical[sphericalIt++];
  230. Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);
  231. result[i + 1] = scratchCartesian.x;
  232. result[i + 2] = scratchCartesian.y;
  233. result[i + 3] = scratchCartesian.z;
  234. }
  235. }
  236. return result;
  237. }
  238. var cartographic = czmlInterval.cartographicRadians;
  239. if (defined(cartographic)) {
  240. if (cartographic.length === 3) {
  241. scratchCartographic.longitude = cartographic[0];
  242. scratchCartographic.latitude = cartographic[1];
  243. scratchCartographic.height = cartographic[2];
  244. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  245. result = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  246. } else {
  247. len = cartographic.length;
  248. result = new Array(len);
  249. for (i = 0; i < len; i += 4) {
  250. scratchCartographic.longitude = cartographic[i + 1];
  251. scratchCartographic.latitude = cartographic[i + 2];
  252. scratchCartographic.height = cartographic[i + 3];
  253. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  254. result[i] = cartographic[i];
  255. result[i + 1] = scratchCartesian.x;
  256. result[i + 2] = scratchCartesian.y;
  257. result[i + 3] = scratchCartesian.z;
  258. }
  259. }
  260. return result;
  261. }
  262. var cartographicDegrees = czmlInterval.cartographicDegrees;
  263. if (!defined(cartographicDegrees)) {
  264. throw new RuntimeError(JSON.stringify(czmlInterval) + ' is not a valid CZML interval.');
  265. }
  266. if (cartographicDegrees.length === 3) {
  267. scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[0]);
  268. scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]);
  269. scratchCartographic.height = cartographicDegrees[2];
  270. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  271. result = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];
  272. } else {
  273. len = cartographicDegrees.length;
  274. result = new Array(len);
  275. for (i = 0; i < len; i += 4) {
  276. scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[i + 1]);
  277. scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[i + 2]);
  278. scratchCartographic.height = cartographicDegrees[i + 3];
  279. Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian);
  280. result[i] = cartographicDegrees[i];
  281. result[i + 1] = scratchCartesian.x;
  282. result[i + 2] = scratchCartesian.y;
  283. result[i + 3] = scratchCartesian.z;
  284. }
  285. }
  286. return result;
  287. }
  288. function unwrapInterval(type, czmlInterval, sourceUri) {
  289. /*jshint sub:true*/
  290. switch (type) {
  291. case Boolean:
  292. return defaultValue(czmlInterval['boolean'], czmlInterval);
  293. case Cartesian2:
  294. return czmlInterval.cartesian2;
  295. case Cartesian3:
  296. return unwrapCartesianInterval(czmlInterval);
  297. case Color:
  298. return unwrapColorInterval(czmlInterval);
  299. case StripeOrientation:
  300. return StripeOrientation[defaultValue(czmlInterval.stripeOrientation, czmlInterval)];
  301. case HorizontalOrigin:
  302. return HorizontalOrigin[defaultValue(czmlInterval.horizontalOrigin, czmlInterval)];
  303. case Image:
  304. return unwrapUriInterval(czmlInterval, sourceUri);
  305. case JulianDate:
  306. return JulianDate.fromIso8601(defaultValue(czmlInterval.date, czmlInterval));
  307. case LabelStyle:
  308. return LabelStyle[defaultValue(czmlInterval.labelStyle, czmlInterval)];
  309. case Number:
  310. return defaultValue(czmlInterval.number, czmlInterval);
  311. case String:
  312. return defaultValue(czmlInterval.string, czmlInterval);
  313. case Array:
  314. return czmlInterval.array;
  315. case Quaternion:
  316. return czmlInterval.unitQuaternion;
  317. case Rectangle:
  318. return unwrapRectangleInterval(czmlInterval);
  319. case Uri:
  320. return unwrapUriInterval(czmlInterval, sourceUri);
  321. case VerticalOrigin:
  322. return VerticalOrigin[defaultValue(czmlInterval.verticalOrigin, czmlInterval)];
  323. default:
  324. throw new DeveloperError(type);
  325. }
  326. }
  327. var interpolators = {
  328. HERMITE : HermitePolynomialApproximation,
  329. LAGRANGE : LagrangePolynomialApproximation,
  330. LINEAR : LinearApproximation
  331. };
  332. function updateInterpolationSettings(packetData, property) {
  333. var interpolationAlgorithm = packetData.interpolationAlgorithm;
  334. if (defined(interpolationAlgorithm) || defined(packetData.interpolationDegree)) {
  335. property.setInterpolationOptions({
  336. interpolationAlgorithm : interpolators[interpolationAlgorithm],
  337. interpolationDegree : packetData.interpolationDegree
  338. });
  339. }
  340. var forwardExtrapolationType = packetData.forwardExtrapolationType;
  341. if (defined(forwardExtrapolationType)) {
  342. property.forwardExtrapolationType = ExtrapolationType[forwardExtrapolationType];
  343. }
  344. var forwardExtrapolationDuration = packetData.forwardExtrapolationDuration;
  345. if (defined(forwardExtrapolationDuration)) {
  346. property.forwardExtrapolationDuration = forwardExtrapolationDuration;
  347. }
  348. var backwardExtrapolationType = packetData.backwardExtrapolationType;
  349. if (defined(backwardExtrapolationType)) {
  350. property.backwardExtrapolationType = ExtrapolationType[backwardExtrapolationType];
  351. }
  352. var backwardExtrapolationDuration = packetData.backwardExtrapolationDuration;
  353. if (defined(backwardExtrapolationDuration)) {
  354. property.backwardExtrapolationDuration = backwardExtrapolationDuration;
  355. }
  356. }
  357. function processProperty(type, object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) {
  358. var combinedInterval;
  359. var packetInterval = packetData.interval;
  360. if (defined(packetInterval)) {
  361. iso8601Scratch.iso8601 = packetInterval;
  362. combinedInterval = TimeInterval.fromIso8601(iso8601Scratch);
  363. if (defined(constrainedInterval)) {
  364. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  365. }
  366. } else if (defined(constrainedInterval)) {
  367. combinedInterval = constrainedInterval;
  368. }
  369. var packedLength;
  370. var isSampled;
  371. var unwrappedInterval;
  372. var unwrappedIntervalLength;
  373. var isReference = defined(packetData.reference);
  374. var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
  375. if (!isReference) {
  376. unwrappedInterval = unwrapInterval(type, packetData, sourceUri);
  377. packedLength = defaultValue(type.packedLength, 1);
  378. unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
  379. isSampled = !defined(packetData.array) && (typeof unwrappedInterval !== 'string') && unwrappedIntervalLength > packedLength;
  380. }
  381. //Any time a constant value is assigned, it completely blows away anything else.
  382. if (!isSampled && !hasInterval) {
  383. if (isReference) {
  384. object[propertyName] = makeReference(entityCollection, packetData.reference);
  385. } else if (defined(type.unpack)) {
  386. object[propertyName] = new ConstantProperty(type.unpack(unwrappedInterval, 0));
  387. } else {
  388. object[propertyName] = new ConstantProperty(unwrappedInterval);
  389. }
  390. return;
  391. }
  392. var property = object[propertyName];
  393. var epoch;
  394. var packetEpoch = packetData.epoch;
  395. if (defined(packetEpoch)) {
  396. epoch = JulianDate.fromIso8601(packetEpoch);
  397. }
  398. //Without an interval, any sampled value is infinite, meaning it completely
  399. //replaces any non-sampled property that may exist.
  400. if (isSampled && !hasInterval) {
  401. if (!(property instanceof SampledProperty)) {
  402. property = new SampledProperty(type);
  403. object[propertyName] = property;
  404. }
  405. property.addSamplesPackedArray(unwrappedInterval, epoch);
  406. updateInterpolationSettings(packetData, property);
  407. return;
  408. }
  409. var interval;
  410. //A constant value with an interval is normally part of a TimeIntervalCollection,
  411. //However, if the current property is not a time-interval collection, we need
  412. //to turn it into a Composite, preserving the old data with the new interval.
  413. if (!isSampled && hasInterval) {
  414. //Create a new interval for the constant value.
  415. combinedInterval = combinedInterval.clone();
  416. if (isReference) {
  417. combinedInterval.data = makeReference(entityCollection, packetData.reference);
  418. } else if (defined(type.unpack)) {
  419. combinedInterval.data = type.unpack(unwrappedInterval, 0);
  420. } else {
  421. combinedInterval.data = unwrappedInterval;
  422. }
  423. //If no property exists, simply use a new interval collection
  424. if (!defined(property)) {
  425. if (isReference) {
  426. property = new CompositeProperty();
  427. } else {
  428. property = new TimeIntervalCollectionProperty();
  429. }
  430. object[propertyName] = property;
  431. }
  432. if (!isReference && property instanceof TimeIntervalCollectionProperty) {
  433. //If we create a collection, or it already existed, use it.
  434. property.intervals.addInterval(combinedInterval);
  435. } else if (property instanceof CompositeProperty) {
  436. //If the collection was already a CompositeProperty, use it.
  437. combinedInterval.data = isReference ? combinedInterval.data : new ConstantProperty(combinedInterval.data);
  438. property.intervals.addInterval(combinedInterval);
  439. } else {
  440. //Otherwise, create a CompositeProperty but preserve the existing data.
  441. //Put the old property in an infinite interval.
  442. interval = Iso8601.MAXIMUM_INTERVAL.clone();
  443. interval.data = property;
  444. //Create the composite.
  445. property = new CompositeProperty();
  446. object[propertyName] = property;
  447. //add the old property interval
  448. property.intervals.addInterval(interval);
  449. //Change the new data to a ConstantProperty and add it.
  450. combinedInterval.data = isReference ? combinedInterval.data : new ConstantProperty(combinedInterval.data);
  451. property.intervals.addInterval(combinedInterval);
  452. }
  453. return;
  454. }
  455. //isSampled && hasInterval
  456. if (!defined(property)) {
  457. property = new CompositeProperty();
  458. object[propertyName] = property;
  459. }
  460. //create a CompositeProperty but preserve the existing data.
  461. if (!(property instanceof CompositeProperty)) {
  462. //Put the old property in an infinite interval.
  463. interval = Iso8601.MAXIMUM_INTERVAL.clone();
  464. interval.data = property;
  465. //Create the composite.
  466. property = new CompositeProperty();
  467. object[propertyName] = property;
  468. //add the old property interval
  469. property.intervals.addInterval(interval);
  470. }
  471. //Check if the interval already exists in the composite
  472. var intervals = property.intervals;
  473. interval = intervals.findInterval(combinedInterval);
  474. if (!defined(interval) || !(interval.data instanceof SampledProperty)) {
  475. //If not, create a SampledProperty for it.
  476. interval = combinedInterval.clone();
  477. interval.data = new SampledProperty(type);
  478. intervals.addInterval(interval);
  479. }
  480. interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
  481. updateInterpolationSettings(packetData, interval.data);
  482. return;
  483. }
  484. function processPacketData(type, object, propertyName, packetData, interval, sourceUri, entityCollection) {
  485. if (!defined(packetData)) {
  486. return;
  487. }
  488. if (isArray(packetData)) {
  489. for (var i = 0, len = packetData.length; i < len; i++) {
  490. processProperty(type, object, propertyName, packetData[i], interval, sourceUri, entityCollection);
  491. }
  492. } else {
  493. processProperty(type, object, propertyName, packetData, interval, sourceUri, entityCollection);
  494. }
  495. }
  496. function processPositionProperty(object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) {
  497. var combinedInterval;
  498. var packetInterval = packetData.interval;
  499. if (defined(packetInterval)) {
  500. iso8601Scratch.iso8601 = packetInterval;
  501. combinedInterval = TimeInterval.fromIso8601(iso8601Scratch);
  502. if (defined(constrainedInterval)) {
  503. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  504. }
  505. } else if (defined(constrainedInterval)) {
  506. combinedInterval = constrainedInterval;
  507. }
  508. var referenceFrame;
  509. var unwrappedInterval;
  510. var isSampled = false;
  511. var unwrappedIntervalLength;
  512. var numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0;
  513. var packedLength = Cartesian3.packedLength * (numberOfDerivatives + 1);
  514. var isReference = defined(packetData.reference);
  515. var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
  516. if (!isReference) {
  517. referenceFrame = defaultValue(ReferenceFrame[packetData.referenceFrame], undefined);
  518. unwrappedInterval = unwrapCartesianInterval(packetData);
  519. unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
  520. isSampled = unwrappedIntervalLength > packedLength;
  521. }
  522. //Any time a constant value is assigned, it completely blows away anything else.
  523. if (!isSampled && !hasInterval) {
  524. if (isReference) {
  525. object[propertyName] = makeReference(entityCollection, packetData.reference);
  526. } else {
  527. object[propertyName] = new ConstantPositionProperty(Cartesian3.unpack(unwrappedInterval), referenceFrame);
  528. }
  529. return;
  530. }
  531. var property = object[propertyName];
  532. var epoch;
  533. var packetEpoch = packetData.epoch;
  534. if (defined(packetEpoch)) {
  535. epoch = JulianDate.fromIso8601(packetEpoch);
  536. }
  537. //Without an interval, any sampled value is infinite, meaning it completely
  538. //replaces any non-sampled property that may exist.
  539. if (isSampled && !hasInterval) {
  540. if (!(property instanceof SampledPositionProperty) || (defined(referenceFrame) && property.referenceFrame !== referenceFrame)) {
  541. property = new SampledPositionProperty(referenceFrame, numberOfDerivatives);
  542. object[propertyName] = property;
  543. }
  544. property.addSamplesPackedArray(unwrappedInterval, epoch);
  545. updateInterpolationSettings(packetData, property);
  546. return;
  547. }
  548. var interval;
  549. //A constant value with an interval is normally part of a TimeIntervalCollection,
  550. //However, if the current property is not a time-interval collection, we need
  551. //to turn it into a Composite, preserving the old data with the new interval.
  552. if (!isSampled && hasInterval) {
  553. //Create a new interval for the constant value.
  554. combinedInterval = combinedInterval.clone();
  555. if (isReference) {
  556. combinedInterval.data = makeReference(entityCollection, packetData.reference);
  557. } else {
  558. combinedInterval.data = Cartesian3.unpack(unwrappedInterval);
  559. }
  560. //If no property exists, simply use a new interval collection
  561. if (!defined(property)) {
  562. if (isReference) {
  563. property = new CompositePositionProperty(referenceFrame);
  564. } else {
  565. property = new TimeIntervalCollectionPositionProperty(referenceFrame);
  566. }
  567. object[propertyName] = property;
  568. }
  569. if (!isReference && property instanceof TimeIntervalCollectionPositionProperty && (defined(referenceFrame) && property.referenceFrame === referenceFrame)) {
  570. //If we create a collection, or it already existed, use it.
  571. property.intervals.addInterval(combinedInterval);
  572. } else if (property instanceof CompositePositionProperty) {
  573. //If the collection was already a CompositePositionProperty, use it.
  574. combinedInterval.data = isReference ? combinedInterval.data : new ConstantPositionProperty(combinedInterval.data, referenceFrame);
  575. property.intervals.addInterval(combinedInterval);
  576. } else {
  577. //Otherwise, create a CompositePositionProperty but preserve the existing data.
  578. //Put the old property in an infinite interval.
  579. interval = Iso8601.MAXIMUM_INTERVAL.clone();
  580. interval.data = property;
  581. //Create the composite.
  582. property = new CompositePositionProperty(property.referenceFrame);
  583. object[propertyName] = property;
  584. //add the old property interval
  585. property.intervals.addInterval(interval);
  586. //Change the new data to a ConstantPositionProperty and add it.
  587. combinedInterval.data = isReference ? combinedInterval.data : new ConstantPositionProperty(combinedInterval.data, referenceFrame);
  588. property.intervals.addInterval(combinedInterval);
  589. }
  590. return;
  591. }
  592. //isSampled && hasInterval
  593. if (!defined(property)) {
  594. property = new CompositePositionProperty(referenceFrame);
  595. object[propertyName] = property;
  596. } else if (!(property instanceof CompositePositionProperty)) {
  597. //create a CompositeProperty but preserve the existing data.
  598. //Put the old property in an infinite interval.
  599. interval = Iso8601.MAXIMUM_INTERVAL.clone();
  600. interval.data = property;
  601. //Create the composite.
  602. property = new CompositePositionProperty(property.referenceFrame);
  603. object[propertyName] = property;
  604. //add the old property interval
  605. property.intervals.addInterval(interval);
  606. }
  607. //Check if the interval already exists in the composite
  608. var intervals = property.intervals;
  609. interval = intervals.findInterval(combinedInterval);
  610. if (!defined(interval) || !(interval.data instanceof SampledPositionProperty) || (defined(referenceFrame) && interval.data.referenceFrame !== referenceFrame)) {
  611. //If not, create a SampledPositionProperty for it.
  612. interval = combinedInterval.clone();
  613. interval.data = new SampledPositionProperty(referenceFrame, numberOfDerivatives);
  614. intervals.addInterval(interval);
  615. }
  616. interval.data.addSamplesPackedArray(unwrappedInterval, epoch);
  617. updateInterpolationSettings(packetData, interval.data);
  618. }
  619. function processPositionPacketData(object, propertyName, packetData, interval, sourceUri, entityCollection) {
  620. if (!defined(packetData)) {
  621. return;
  622. }
  623. if (isArray(packetData)) {
  624. for (var i = 0, len = packetData.length; i < len; i++) {
  625. processPositionProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection);
  626. }
  627. } else {
  628. processPositionProperty(object, propertyName, packetData, interval, sourceUri, entityCollection);
  629. }
  630. }
  631. function processMaterialProperty(object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) {
  632. var combinedInterval;
  633. var packetInterval = packetData.interval;
  634. if (defined(packetInterval)) {
  635. iso8601Scratch.iso8601 = packetInterval;
  636. combinedInterval = TimeInterval.fromIso8601(iso8601Scratch);
  637. if (defined(constrainedInterval)) {
  638. combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval);
  639. }
  640. } else if (defined(constrainedInterval)) {
  641. combinedInterval = constrainedInterval;
  642. }
  643. var property = object[propertyName];
  644. var existingMaterial;
  645. var existingInterval;
  646. if (defined(combinedInterval)) {
  647. if (!(property instanceof CompositeMaterialProperty)) {
  648. property = new CompositeMaterialProperty();
  649. object[propertyName] = property;
  650. }
  651. //See if we already have data at that interval.
  652. var thisIntervals = property.intervals;
  653. existingInterval = thisIntervals.findInterval({
  654. start : combinedInterval.start,
  655. stop : combinedInterval.stop
  656. });
  657. if (defined(existingInterval)) {
  658. //We have an interval, but we need to make sure the
  659. //new data is the same type of material as the old data.
  660. existingMaterial = existingInterval.data;
  661. } else {
  662. //If not, create it.
  663. existingInterval = combinedInterval.clone();
  664. thisIntervals.addInterval(existingInterval);
  665. }
  666. } else {
  667. existingMaterial = property;
  668. }
  669. var materialData;
  670. if (defined(packetData.solidColor)) {
  671. if (!(existingMaterial instanceof ColorMaterialProperty)) {
  672. existingMaterial = new ColorMaterialProperty();
  673. }
  674. materialData = packetData.solidColor;
  675. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, undefined, entityCollection);
  676. } else if (defined(packetData.grid)) {
  677. if (!(existingMaterial instanceof GridMaterialProperty)) {
  678. existingMaterial = new GridMaterialProperty();
  679. }
  680. materialData = packetData.grid;
  681. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  682. processPacketData(Number, existingMaterial, 'cellAlpha', materialData.cellAlpha, undefined, sourceUri, entityCollection);
  683. processPacketData(Cartesian2, existingMaterial, 'lineThickness', materialData.lineThickness, undefined, sourceUri, entityCollection);
  684. processPacketData(Cartesian2, existingMaterial, 'lineOffset', materialData.lineOffset, undefined, sourceUri, entityCollection);
  685. processPacketData(Cartesian2, existingMaterial, 'lineCount', materialData.lineCount, undefined, sourceUri, entityCollection);
  686. } else if (defined(packetData.image)) {
  687. if (!(existingMaterial instanceof ImageMaterialProperty)) {
  688. existingMaterial = new ImageMaterialProperty();
  689. }
  690. materialData = packetData.image;
  691. processPacketData(Image, existingMaterial, 'image', materialData.image, undefined, sourceUri, entityCollection);
  692. processPacketData(Cartesian2, existingMaterial, 'repeat', materialData.repeat, undefined, sourceUri, entityCollection);
  693. } else if (defined(packetData.stripe)) {
  694. if (!(existingMaterial instanceof StripeMaterialProperty)) {
  695. existingMaterial = new StripeMaterialProperty();
  696. }
  697. materialData = packetData.stripe;
  698. processPacketData(StripeOrientation, existingMaterial, 'orientation', materialData.orientation, undefined, sourceUri, entityCollection);
  699. processPacketData(Color, existingMaterial, 'evenColor', materialData.evenColor, undefined, sourceUri, entityCollection);
  700. processPacketData(Color, existingMaterial, 'oddColor', materialData.oddColor, undefined, sourceUri, entityCollection);
  701. processPacketData(Number, existingMaterial, 'offset', materialData.offset, undefined, sourceUri, entityCollection);
  702. processPacketData(Number, existingMaterial, 'repeat', materialData.repeat, undefined, sourceUri, entityCollection);
  703. } else if (defined(packetData.polylineOutline)) {
  704. if (!(existingMaterial instanceof PolylineOutlineMaterialProperty)) {
  705. existingMaterial = new PolylineOutlineMaterialProperty();
  706. }
  707. materialData = packetData.polylineOutline;
  708. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  709. processPacketData(Color, existingMaterial, 'outlineColor', materialData.outlineColor, undefined, sourceUri, entityCollection);
  710. processPacketData(Number, existingMaterial, 'outlineWidth', materialData.outlineWidth, undefined, sourceUri, entityCollection);
  711. } else if (defined(packetData.polylineGlow)) {
  712. if (!(existingMaterial instanceof PolylineGlowMaterialProperty)) {
  713. existingMaterial = new PolylineGlowMaterialProperty();
  714. }
  715. materialData = packetData.polylineGlow;
  716. processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri, entityCollection);
  717. processPacketData(Number, existingMaterial, 'glowPower', materialData.glowPower, undefined, sourceUri, entityCollection);
  718. }
  719. if (defined(existingInterval)) {
  720. existingInterval.data = existingMaterial;
  721. } else {
  722. object[propertyName] = existingMaterial;
  723. }
  724. }
  725. function processMaterialPacketData(object, propertyName, packetData, interval, sourceUri, entityCollection) {
  726. if (!defined(packetData)) {
  727. return;
  728. }
  729. if (isArray(packetData)) {
  730. for (var i = 0, len = packetData.length; i < len; i++) {
  731. processMaterialProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection);
  732. }
  733. } else {
  734. processMaterialProperty(object, propertyName, packetData, interval, sourceUri, entityCollection);
  735. }
  736. }
  737. function processName(entity, packet, entityCollection, sourceUri) {
  738. entity.name = defaultValue(packet.name, entity.name);
  739. }
  740. function processDescription(entity, packet, entityCollection, sourceUri) {
  741. var descriptionData = packet.description;
  742. if (defined(descriptionData)) {
  743. processPacketData(String, entity, 'description', descriptionData, undefined, sourceUri, entityCollection);
  744. }
  745. }
  746. function processPosition(entity, packet, entityCollection, sourceUri) {
  747. var positionData = packet.position;
  748. if (defined(positionData)) {
  749. processPositionPacketData(entity, 'position', positionData, undefined, sourceUri, entityCollection);
  750. }
  751. }
  752. function processViewFrom(entity, packet, entityCollection, sourceUri) {
  753. var viewFromData = packet.viewFrom;
  754. if (defined(viewFromData)) {
  755. processPacketData(Cartesian3, entity, 'viewFrom', viewFromData, undefined, sourceUri, entityCollection);
  756. }
  757. }
  758. function processOrientation(entity, packet, entityCollection, sourceUri) {
  759. var orientationData = packet.orientation;
  760. if (defined(orientationData)) {
  761. processPacketData(Quaternion, entity, 'orientation', orientationData, undefined, sourceUri, entityCollection);
  762. }
  763. }
  764. function processVertexData(object, positionsData, entityCollection) {
  765. var i;
  766. var len;
  767. var references = positionsData.references;
  768. if (defined(references)) {
  769. var properties = [];
  770. for (i = 0, len = references.length; i < len; i++) {
  771. properties.push(makeReference(entityCollection, references[i]));
  772. }
  773. var iso8601Interval = positionsData.interval;
  774. if (defined(iso8601Interval)) {
  775. iso8601Interval = TimeInterval.fromIso8601(iso8601Interval);
  776. if (!(object.positions instanceof CompositePositionProperty)) {
  777. object.positions = new CompositePositionProperty();
  778. iso8601Interval.data = new PositionPropertyArray(properties);
  779. object.positions.intervals.addInterval(iso8601Interval);
  780. }
  781. } else {
  782. object.positions = new PositionPropertyArray(properties);
  783. }
  784. } else {
  785. var values = [];
  786. var tmp = positionsData.cartesian;
  787. if (defined(tmp)) {
  788. for (i = 0, len = tmp.length; i < len; i += 3) {
  789. values.push(new Cartesian3(tmp[i], tmp[i + 1], tmp[i + 2]));
  790. }
  791. positionsData.array = values;
  792. } else {
  793. tmp = positionsData.cartographicRadians;
  794. if (defined(tmp)) {
  795. for (i = 0, len = tmp.length; i < len; i += 3) {
  796. scratchCartographic.longitude = tmp[i];
  797. scratchCartographic.latitude = tmp[i + 1];
  798. scratchCartographic.height = tmp[i + 2];
  799. values.push(Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic));
  800. }
  801. positionsData.array = values;
  802. } else {
  803. tmp = positionsData.cartographicDegrees;
  804. if (defined(tmp)) {
  805. for (i = 0, len = tmp.length; i < len; i += 3) {
  806. values.push(Cartesian3.fromDegrees(tmp[i], tmp[i + 1], tmp[i + 2]));
  807. }
  808. positionsData.array = values;
  809. }
  810. }
  811. }
  812. if (defined(positionsData.array)) {
  813. processPacketData(Array, object, 'positions', positionsData, undefined, undefined, entityCollection);
  814. }
  815. }
  816. }
  817. function processPositions(object, positionsData, entityCollection) {
  818. if (!defined(positionsData)) {
  819. return;
  820. }
  821. if (isArray(positionsData)) {
  822. var length = positionsData.length;
  823. for (var i = 0; i < length; i++) {
  824. processVertexData(object, positionsData[i], entityCollection);
  825. }
  826. } else {
  827. processVertexData(object, positionsData, entityCollection);
  828. }
  829. }
  830. function processAvailability(entity, packet, entityCollection, sourceUri) {
  831. var interval;
  832. var packetData = packet.availability;
  833. if (!defined(packetData)) {
  834. return;
  835. }
  836. var intervals;
  837. if (isArray(packetData)) {
  838. var length = packetData.length;
  839. for (var i = 0; i < length; i++) {
  840. if (!defined(intervals)) {
  841. intervals = new TimeIntervalCollection();
  842. }
  843. iso8601Scratch.iso8601 = packetData[i];
  844. interval = TimeInterval.fromIso8601(iso8601Scratch);
  845. intervals.addInterval(interval);
  846. }
  847. } else {
  848. iso8601Scratch.iso8601 = packetData;
  849. interval = TimeInterval.fromIso8601(iso8601Scratch);
  850. intervals = new TimeIntervalCollection();
  851. intervals.addInterval(interval);
  852. }
  853. entity.availability = intervals;
  854. }
  855. var iso8601Scratch = {
  856. iso8601 : undefined
  857. };
  858. function processBillboard(entity, packet, entityCollection, sourceUri) {
  859. var billboardData = packet.billboard;
  860. if (!defined(billboardData)) {
  861. return;
  862. }
  863. var interval;
  864. var intervalString = billboardData.interval;
  865. if (defined(intervalString)) {
  866. iso8601Scratch.iso8601 = intervalString;
  867. interval = TimeInterval.fromIso8601(iso8601Scratch);
  868. }
  869. var billboard = entity.billboard;
  870. if (!defined(billboard)) {
  871. entity.billboard = billboard = new BillboardGraphics();
  872. }
  873. processPacketData(Color, billboard, 'color', billboardData.color, interval, sourceUri, entityCollection);
  874. processPacketData(Cartesian3, billboard, 'eyeOffset', billboardData.eyeOffset, interval, sourceUri, entityCollection);
  875. processPacketData(HorizontalOrigin, billboard, 'horizontalOrigin', billboardData.horizontalOrigin, interval, sourceUri, entityCollection);
  876. processPacketData(Image, billboard, 'image', billboardData.image, interval, sourceUri, entityCollection);
  877. processPacketData(Cartesian2, billboard, 'pixelOffset', billboardData.pixelOffset, interval, sourceUri, entityCollection);
  878. processPacketData(Number, billboard, 'scale', billboardData.scale, interval, sourceUri, entityCollection);
  879. processPacketData(Number, billboard, 'rotation', billboardData.rotation, interval, sourceUri, entityCollection);
  880. processPacketData(Cartesian3, billboard, 'alignedAxis', billboardData.alignedAxis, interval, sourceUri, entityCollection);
  881. processPacketData(Boolean, billboard, 'show', billboardData.show, interval, sourceUri, entityCollection);
  882. processPacketData(VerticalOrigin, billboard, 'verticalOrigin', billboardData.verticalOrigin, interval, sourceUri, entityCollection);
  883. }
  884. function processDocument(packet, dataSource) {
  885. var version = packet.version;
  886. if (defined(version)) {
  887. if (typeof version === 'string') {
  888. var tokens = version.split('.');
  889. if (tokens.length === 2) {
  890. if (tokens[0] !== '1') {
  891. throw new RuntimeError('Cesium only supports CZML version 1.');
  892. }
  893. dataSource._version = version;
  894. }
  895. }
  896. }
  897. if (!defined(dataSource._version)) {
  898. throw new RuntimeError('CZML version information invalid. It is expected to be a property on the document object in the <Major>.<Minor> version format.');
  899. }
  900. var documentPacket = dataSource._documentPacket;
  901. if (defined(packet.name)) {
  902. documentPacket.name = packet.name;
  903. }
  904. var clockPacket = packet.clock;
  905. if (defined(clockPacket)) {
  906. var clock = documentPacket.clock;
  907. if (!defined(clock)) {
  908. documentPacket.clock = {
  909. interval : clockPacket.interval,
  910. currentTime : clockPacket.currentTime,
  911. range : clockPacket.range,
  912. step : clockPacket.step,
  913. multiplier : clockPacket.multiplier
  914. };
  915. } else {
  916. clock.interval = defaultValue(clockPacket.interval, clock.interval);
  917. clock.currentTime = defaultValue(clockPacket.currentTime, clock.currentTime);
  918. clock.range = defaultValue(clockPacket.range, clock.range);
  919. clock.step = defaultValue(clockPacket.step, clock.step);
  920. clock.multiplier = defaultValue(clockPacket.multiplier, clock.multiplier);
  921. }
  922. }
  923. }
  924. function processEllipse(entity, packet, entityCollection, sourceUri) {
  925. var ellipseData = packet.ellipse;
  926. if (!defined(ellipseData)) {
  927. return;
  928. }
  929. var interval;
  930. var intervalString = ellipseData.interval;
  931. if (defined(intervalString)) {
  932. iso8601Scratch.iso8601 = intervalString;
  933. interval = TimeInterval.fromIso8601(iso8601Scratch);
  934. }
  935. var ellipse = entity.ellipse;
  936. if (!defined(ellipse)) {
  937. entity.ellipse = ellipse = new EllipseGraphics();
  938. }
  939. processPacketData(Boolean, ellipse, 'show', ellipseData.show, interval, sourceUri, entityCollection);
  940. processPacketData(Number, ellipse, 'rotation', ellipseData.rotation, interval, sourceUri, entityCollection);
  941. processPacketData(Number, ellipse, 'semiMajorAxis', ellipseData.semiMajorAxis, interval, sourceUri, entityCollection);
  942. processPacketData(Number, ellipse, 'semiMinorAxis', ellipseData.semiMinorAxis, interval, sourceUri, entityCollection);
  943. processPacketData(Number, ellipse, 'height', ellipseData.height, interval, sourceUri, entityCollection);
  944. processPacketData(Number, ellipse, 'extrudedHeight', ellipseData.extrudedHeight, interval, sourceUri, entityCollection);
  945. processPacketData(Number, ellipse, 'granularity', ellipseData.granularity, interval, sourceUri, entityCollection);
  946. processPacketData(Number, ellipse, 'stRotation', ellipseData.stRotation, interval, sourceUri, entityCollection);
  947. processMaterialPacketData(ellipse, 'material', ellipseData.material, interval, sourceUri, entityCollection);
  948. processPacketData(Boolean, ellipse, 'fill', ellipseData.fill, interval, sourceUri, entityCollection);
  949. processPacketData(Boolean, ellipse, 'outline', ellipseData.outline, interval, sourceUri, entityCollection);
  950. processPacketData(Color, ellipse, 'outlineColor', ellipseData.outlineColor, interval, sourceUri, entityCollection);
  951. processPacketData(Number, ellipse, 'outlineWidth', ellipseData.outlineWidth, interval, sourceUri, entityCollection);
  952. processPacketData(Number, ellipse, 'numberOfVerticalLines', ellipseData.numberOfVerticalLines, interval, sourceUri, entityCollection);
  953. }
  954. function processEllipsoid(entity, packet, entityCollection, sourceUri) {
  955. var ellipsoidData = packet.ellipsoid;
  956. if (!defined(ellipsoidData)) {
  957. return;
  958. }
  959. var interval;
  960. var intervalString = ellipsoidData.interval;
  961. if (defined(intervalString)) {
  962. iso8601Scratch.iso8601 = intervalString;
  963. interval = TimeInterval.fromIso8601(iso8601Scratch);
  964. }
  965. var ellipsoid = entity.ellipsoid;
  966. if (!defined(ellipsoid)) {
  967. entity.ellipsoid = ellipsoid = new EllipsoidGraphics();
  968. }
  969. processPacketData(Boolean, ellipsoid, 'show', ellipsoidData.show, interval, sourceUri, entityCollection);
  970. processPacketData(Cartesian3, ellipsoid, 'radii', ellipsoidData.radii, interval, sourceUri, entityCollection);
  971. processMaterialPacketData(ellipsoid, 'material', ellipsoidData.material, interval, sourceUri, entityCollection);
  972. processPacketData(Boolean, ellipsoid, 'fill', ellipsoidData.fill, interval, sourceUri, entityCollection);
  973. processPacketData(Boolean, ellipsoid, 'outline', ellipsoidData.outline, interval, sourceUri, entityCollection);
  974. processPacketData(Color, ellipsoid, 'outlineColor', ellipsoidData.outlineColor, interval, sourceUri, entityCollection);
  975. processPacketData(Number, ellipsoid, 'outlineWidth', ellipsoidData.outlineWidth, interval, sourceUri, entityCollection);
  976. }
  977. function processLabel(entity, packet, entityCollection, sourceUri) {
  978. var labelData = packet.label;
  979. if (!defined(labelData)) {
  980. return;
  981. }
  982. var interval;
  983. var intervalString = labelData.interval;
  984. if (defined(intervalString)) {
  985. iso8601Scratch.iso8601 = intervalString;
  986. interval = TimeInterval.fromIso8601(iso8601Scratch);
  987. }
  988. var label = entity.label;
  989. if (!defined(label)) {
  990. entity.label = label = new LabelGraphics();
  991. }
  992. processPacketData(Color, label, 'fillColor', labelData.fillColor, interval, sourceUri, entityCollection);
  993. processPacketData(Color, label, 'outlineColor', labelData.outlineColor, interval, sourceUri, entityCollection);
  994. processPacketData(Number, label, 'outlineWidth', labelData.outlineWidth, interval, sourceUri, entityCollection);
  995. processPacketData(Cartesian3, label, 'eyeOffset', labelData.eyeOffset, interval, sourceUri, entityCollection);
  996. processPacketData(HorizontalOrigin, label, 'horizontalOrigin', labelData.horizontalOrigin, interval, sourceUri, entityCollection);
  997. processPacketData(String, label, 'text', labelData.text, interval, sourceUri, entityCollection);
  998. processPacketData(Cartesian2, label, 'pixelOffset', labelData.pixelOffset, interval, sourceUri, entityCollection);
  999. processPacketData(Number, label, 'scale', labelData.scale, interval, sourceUri, entityCollection);
  1000. processPacketData(Boolean, label, 'show', labelData.show, interval, sourceUri, entityCollection);
  1001. processPacketData(VerticalOrigin, label, 'verticalOrigin', labelData.verticalOrigin, interval, sourceUri, entityCollection);
  1002. processPacketData(String, label, 'font', labelData.font, interval, sourceUri, entityCollection);
  1003. processPacketData(LabelStyle, label, 'style', labelData.style, interval, sourceUri, entityCollection);
  1004. }
  1005. function processModel(entity, packet, entityCollection, sourceUri) {
  1006. var modelData = packet.model;
  1007. if (!defined(modelData)) {
  1008. return;
  1009. }
  1010. var interval;
  1011. var intervalString = modelData.interval;
  1012. if (defined(intervalString)) {
  1013. iso8601Scratch.iso8601 = intervalString;
  1014. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1015. }
  1016. var model = entity.model;
  1017. if (!defined(model)) {
  1018. entity.model = model = new ModelGraphics();
  1019. }
  1020. processPacketData(Boolean, model, 'show', modelData.show, interval, sourceUri, entityCollection);
  1021. processPacketData(Number, model, 'scale', modelData.scale, interval, sourceUri, entityCollection);
  1022. processPacketData(Number, model, 'minimumPixelSize', modelData.minimumPixelSize, interval, sourceUri, entityCollection);
  1023. processPacketData(Uri, model, 'uri', modelData.gltf, interval, sourceUri, entityCollection);
  1024. }
  1025. function processPath(entity, packet, entityCollection, sourceUri) {
  1026. var pathData = packet.path;
  1027. if (!defined(pathData)) {
  1028. return;
  1029. }
  1030. var interval;
  1031. var intervalString = pathData.interval;
  1032. if (defined(intervalString)) {
  1033. iso8601Scratch.iso8601 = intervalString;
  1034. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1035. }
  1036. var path = entity.path;
  1037. if (!defined(path)) {
  1038. entity.path = path = new PathGraphics();
  1039. }
  1040. processPacketData(Boolean, path, 'show', pathData.show, interval, sourceUri, entityCollection);
  1041. processPacketData(Number, path, 'width', pathData.width, interval, sourceUri, entityCollection);
  1042. processPacketData(Number, path, 'resolution', pathData.resolution, interval, sourceUri, entityCollection);
  1043. processPacketData(Number, path, 'leadTime', pathData.leadTime, interval, sourceUri, entityCollection);
  1044. processPacketData(Number, path, 'trailTime', pathData.trailTime, interval, sourceUri, entityCollection);
  1045. processMaterialPacketData(path, 'material', pathData.material, interval, sourceUri, entityCollection);
  1046. }
  1047. function processPoint(entity, packet, entityCollection, sourceUri) {
  1048. var pointData = packet.point;
  1049. if (!defined(pointData)) {
  1050. return;
  1051. }
  1052. var interval;
  1053. var intervalString = pointData.interval;
  1054. if (defined(intervalString)) {
  1055. iso8601Scratch.iso8601 = intervalString;
  1056. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1057. }
  1058. var point = entity.point;
  1059. if (!defined(point)) {
  1060. entity.point = point = new PointGraphics();
  1061. }
  1062. processPacketData(Color, point, 'color', pointData.color, interval, sourceUri, entityCollection);
  1063. processPacketData(Number, point, 'pixelSize', pointData.pixelSize, interval, sourceUri, entityCollection);
  1064. processPacketData(Color, point, 'outlineColor', pointData.outlineColor, interval, sourceUri, entityCollection);
  1065. processPacketData(Number, point, 'outlineWidth', pointData.outlineWidth, interval, sourceUri, entityCollection);
  1066. processPacketData(Boolean, point, 'show', pointData.show, interval, sourceUri, entityCollection);
  1067. }
  1068. function processPolygon(entity, packet, entityCollection, sourceUri) {
  1069. var polygonData = packet.polygon;
  1070. if (!defined(polygonData)) {
  1071. return;
  1072. }
  1073. var interval;
  1074. var intervalString = polygonData.interval;
  1075. if (defined(intervalString)) {
  1076. iso8601Scratch.iso8601 = intervalString;
  1077. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1078. }
  1079. var polygon = entity.polygon;
  1080. if (!defined(polygon)) {
  1081. entity.polygon = polygon = new PolygonGraphics();
  1082. }
  1083. processPacketData(Boolean, polygon, 'show', polygonData.show, interval, sourceUri, entityCollection);
  1084. processMaterialPacketData(polygon, 'material', polygonData.material, interval, sourceUri, entityCollection);
  1085. processPacketData(Number, polygon, 'height', polygonData.height, interval, sourceUri, entityCollection);
  1086. processPacketData(Number, polygon, 'extrudedHeight', polygonData.extrudedHeight, interval, sourceUri, entityCollection);
  1087. processPacketData(Number, polygon, 'granularity', polygonData.granularity, interval, sourceUri, entityCollection);
  1088. processPacketData(Number, polygon, 'stRotation', polygonData.stRotation, interval, sourceUri, entityCollection);
  1089. processPacketData(Boolean, polygon, 'fill', polygonData.fill, interval, sourceUri, entityCollection);
  1090. processPacketData(Boolean, polygon, 'outline', polygonData.outline, interval, sourceUri, entityCollection);
  1091. processPacketData(Color, polygon, 'outlineColor', polygonData.outlineColor, interval, sourceUri, entityCollection);
  1092. processPacketData(Number, polygon, 'outlineWidth', polygonData.outlineWidth, interval, sourceUri, entityCollection);
  1093. processPacketData(Boolean, polygon, 'perPositionHeight', polygonData.perPositionHeight, interval, sourceUri, entityCollection);
  1094. processPositions(polygon, polygonData.positions, entityCollection);
  1095. }
  1096. function processRectangle(entity, packet, entityCollection, sourceUri) {
  1097. var rectangleData = packet.rectangle;
  1098. if (!defined(rectangleData)) {
  1099. return;
  1100. }
  1101. var interval;
  1102. var intervalString = rectangleData.interval;
  1103. if (defined(intervalString)) {
  1104. iso8601Scratch.iso8601 = intervalString;
  1105. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1106. }
  1107. var rectangle = entity.rectangle;
  1108. if (!defined(rectangle)) {
  1109. entity.rectangle = rectangle = new RectangleGraphics();
  1110. }
  1111. processPacketData(Boolean, rectangle, 'show', rectangleData.show, interval, sourceUri, entityCollection);
  1112. processPacketData(Rectangle, rectangle, 'coordinates', rectangleData.coordinates, interval, sourceUri, entityCollection);
  1113. processMaterialPacketData(rectangle, 'material', rectangleData.material, interval, sourceUri, entityCollection);
  1114. processPacketData(Number, rectangle, 'height', rectangleData.height, interval, sourceUri, entityCollection);
  1115. processPacketData(Number, rectangle, 'extrudedHeight', rectangleData.extrudedHeight, interval, sourceUri, entityCollection);
  1116. processPacketData(Number, rectangle, 'granularity', rectangleData.granularity, interval, sourceUri, entityCollection);
  1117. processPacketData(Number, rectangle, 'rotation', rectangleData.rotation, interval, sourceUri, entityCollection);
  1118. processPacketData(Number, rectangle, 'stRotation', rectangleData.stRotation, interval, sourceUri, entityCollection);
  1119. processPacketData(Boolean, rectangle, 'fill', rectangleData.fill, interval, sourceUri, entityCollection);
  1120. processPacketData(Boolean, rectangle, 'outline', rectangleData.outline, interval, sourceUri, entityCollection);
  1121. processPacketData(Color, rectangle, 'outlineColor', rectangleData.outlineColor, interval, sourceUri, entityCollection);
  1122. processPacketData(Number, rectangle, 'outlineWidth', rectangleData.outlineWidth, interval, sourceUri, entityCollection);
  1123. processPacketData(Boolean, rectangle, 'closeBottom', rectangleData.closeBottom, interval, sourceUri, entityCollection);
  1124. processPacketData(Boolean, rectangle, 'closeTop', rectangleData.closeTop, interval, sourceUri, entityCollection);
  1125. }
  1126. function processWall(entity, packet, entityCollection, sourceUri) {
  1127. var wallData = packet.wall;
  1128. if (!defined(wallData)) {
  1129. return;
  1130. }
  1131. var interval;
  1132. var intervalString = wallData.interval;
  1133. if (defined(intervalString)) {
  1134. iso8601Scratch.iso8601 = intervalString;
  1135. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1136. }
  1137. var wall = entity.wall;
  1138. if (!defined(wall)) {
  1139. entity.wall = wall = new WallGraphics();
  1140. }
  1141. processPacketData(Boolean, wall, 'show', wallData.show, interval, sourceUri, entityCollection);
  1142. processMaterialPacketData(wall, 'material', wallData.material, interval, sourceUri, entityCollection);
  1143. processPacketData(Array, wall, 'minimumHeights', wallData.minimumHeights, interval, sourceUri, entityCollection);
  1144. processPacketData(Array, wall, 'maximumHeights', wallData.maximumHeights, interval, sourceUri, entityCollection);
  1145. processPacketData(Number, wall, 'granularity', wallData.granularity, interval, sourceUri, entityCollection);
  1146. processPacketData(Boolean, wall, 'fill', wallData.fill, interval, sourceUri, entityCollection);
  1147. processPacketData(Boolean, wall, 'outline', wallData.outline, interval, sourceUri, entityCollection);
  1148. processPacketData(Color, wall, 'outlineColor', wallData.outlineColor, interval, sourceUri, entityCollection);
  1149. processPacketData(Number, wall, 'outlineWidth', wallData.outlineWidth, interval, sourceUri, entityCollection);
  1150. processPositions(wall, wallData.positions, entityCollection);
  1151. }
  1152. function processPolyline(entity, packet, entityCollection, sourceUri) {
  1153. var polylineData = packet.polyline;
  1154. if (!defined(polylineData)) {
  1155. return;
  1156. }
  1157. var interval;
  1158. var intervalString = polylineData.interval;
  1159. if (defined(intervalString)) {
  1160. iso8601Scratch.iso8601 = intervalString;
  1161. interval = TimeInterval.fromIso8601(iso8601Scratch);
  1162. }
  1163. var polyline = entity.polyline;
  1164. if (!defined(polyline)) {
  1165. entity.polyline = polyline = new PolylineGraphics();
  1166. }
  1167. processPacketData(Boolean, polyline, 'show', polylineData.show, interval, sourceUri, entityCollection);
  1168. processPacketData(Number, polyline, 'width', polylineData.width, interval, sourceUri, entityCollection);
  1169. processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection);
  1170. processPacketData(Boolean, polyline, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection);
  1171. processPacketData(Number, polyline, 'granularity', polylineData.granularity, interval, sourceUri, entityCollection);
  1172. processPositions(polyline, polylineData.positions, entityCollection);
  1173. }
  1174. function processCzmlPacket(packet, entityCollection, updaterFunctions, sourceUri, dataSource) {
  1175. var objectId = packet.id;
  1176. if (!defined(objectId)) {
  1177. objectId = createGuid();
  1178. }
  1179. currentId = objectId;
  1180. if (!defined(dataSource._version) && objectId !== 'document') {
  1181. throw new RuntimeError('The first CZML packet is required to be the document object.');
  1182. }
  1183. if (packet['delete'] === true) {
  1184. entityCollection.removeById(objectId);
  1185. } else if (objectId === 'document') {
  1186. processDocument(packet, dataSource);
  1187. } else {
  1188. var entity = entityCollection.getOrCreateEntity(objectId);
  1189. var parentId = packet.parent;
  1190. if (defined(parentId)) {
  1191. entity.parent = entityCollection.getOrCreateEntity(parentId);
  1192. }
  1193. for (var i = updaterFunctions.length - 1; i > -1; i--) {
  1194. updaterFunctions[i](entity, packet, entityCollection, sourceUri);
  1195. }
  1196. }
  1197. currentId = undefined;
  1198. }
  1199. function updateClock(dataSource) {
  1200. var clock;
  1201. var clockPacket = dataSource._documentPacket.clock;
  1202. if (!defined(clockPacket)) {
  1203. if (!defined(dataSource._clock)) {
  1204. var availability = dataSource._entityCollection.computeAvailability();
  1205. if (!availability.start.equals(Iso8601.MINIMUM_VALUE)) {
  1206. var startTime = availability.start;
  1207. var stopTime = availability.stop;
  1208. var totalSeconds = JulianDate.secondsDifference(stopTime, startTime);
  1209. var multiplier = Math.round(totalSeconds / 120.0);
  1210. clock = new DataSourceClock();
  1211. clock.startTime = JulianDate.clone(startTime);
  1212. clock.stopTime = JulianDate.clone(stopTime);
  1213. clock.clockRange = ClockRange.LOOP_STOP;
  1214. clock.multiplier = multiplier;
  1215. clock.currentTime = JulianDate.clone(startTime);
  1216. clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  1217. dataSource._clock = clock;
  1218. return true;
  1219. }
  1220. }
  1221. return false;
  1222. }
  1223. if (defined(dataSource._clock)) {
  1224. clock = dataSource._clock.clone();
  1225. } else {
  1226. clock = new DataSourceClock();
  1227. clock.startTime = Iso8601.MINIMUM_VALUE.clone();
  1228. clock.stopTime = Iso8601.MAXIMUM_VALUE.clone();
  1229. clock.currentTime = Iso8601.MINIMUM_VALUE.clone();
  1230. clock.clockRange = ClockRange.LOOP_STOP;
  1231. clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
  1232. clock.multiplier = 1.0;
  1233. }
  1234. if (defined(clockPacket.interval)) {
  1235. iso8601Scratch.iso8601 = clockPacket.interval;
  1236. var interval = TimeInterval.fromIso8601(iso8601Scratch);
  1237. clock.startTime = interval.start;
  1238. clock.stopTime = interval.stop;
  1239. }
  1240. if (defined(clockPacket.currentTime)) {
  1241. clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime);
  1242. }
  1243. if (defined(clockPacket.range)) {
  1244. clock.clockRange = defaultValue(ClockRange[clockPacket.range], ClockRange.LOOP_STOP);
  1245. }
  1246. if (defined(clockPacket.step)) {
  1247. clock.clockStep = defaultValue(ClockStep[clockPacket.step], ClockStep.SYSTEM_CLOCK_MULTIPLIER);
  1248. }
  1249. if (defined(clockPacket.multiplier)) {
  1250. clock.multiplier = clockPacket.multiplier;
  1251. }
  1252. if (!clock.equals(dataSource._clock)) {
  1253. dataSource._clock = clock.clone(dataSource._clock);
  1254. return true;
  1255. }
  1256. return false;
  1257. }
  1258. function loadCzml(dataSource, czml, sourceUri, clear) {
  1259. DataSource.setLoading(dataSource, true);
  1260. var entityCollection = dataSource._entityCollection;
  1261. if (clear) {
  1262. dataSource._version = undefined;
  1263. dataSource._documentPacket = new DocumentPacket();
  1264. entityCollection.removeAll();
  1265. }
  1266. CzmlDataSource._processCzml(czml, entityCollection, sourceUri, undefined, dataSource);
  1267. var raiseChangedEvent = updateClock(dataSource);
  1268. var documentPacket = dataSource._documentPacket;
  1269. if (defined(documentPacket.name) && dataSource._name !== documentPacket.name) {
  1270. dataSource._name = documentPacket.name;
  1271. raiseChangedEvent = true;
  1272. } else if (!defined(dataSource._name) && defined(sourceUri)) {
  1273. dataSource._name = getFilenameFromUri(sourceUri);
  1274. raiseChangedEvent = true;
  1275. }
  1276. DataSource.setLoading(dataSource, false);
  1277. if (raiseChangedEvent) {
  1278. dataSource._changed.raiseEvent(dataSource);
  1279. }
  1280. }
  1281. var DocumentPacket = function() {
  1282. this.name = undefined;
  1283. this.clock = undefined;
  1284. };
  1285. /**
  1286. * A {@link DataSource} which processes CZML.
  1287. * @alias CzmlDataSource
  1288. * @constructor
  1289. *
  1290. * @param {String} [name] An optional name for the data source. This value will be overwritten if a loaded document contains a name.
  1291. *
  1292. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=CZML.html|Cesium Sandcastle CZML Demo}
  1293. */
  1294. var CzmlDataSource = function(name) {
  1295. this._name = name;
  1296. this._changed = new Event();
  1297. this._error = new Event();
  1298. this._isLoading = false;
  1299. this._loading = new Event();
  1300. this._clock = undefined;
  1301. this._documentPacket = new DocumentPacket();
  1302. this._version = undefined;
  1303. this._entityCollection = new EntityCollection();
  1304. };
  1305. defineProperties(CzmlDataSource.prototype, {
  1306. /**
  1307. * Gets a human-readable name for this instance.
  1308. * @memberof CzmlDataSource.prototype
  1309. * @type {String}
  1310. */
  1311. name : {
  1312. get : function() {
  1313. return this._name;
  1314. }
  1315. },
  1316. /**
  1317. * Gets the clock settings defined by the loaded CZML. If no clock is explicitly
  1318. * defined in the CZML, the combined availability of all objects is returned. If
  1319. * only static data exists, this value is undefined.
  1320. * @memberof CzmlDataSource.prototype
  1321. * @type {DataSourceClock}
  1322. */
  1323. clock : {
  1324. get : function() {
  1325. return this._clock;
  1326. }
  1327. },
  1328. /**
  1329. * Gets the collection of {@link Entity} instances.
  1330. * @memberof CzmlDataSource.prototype
  1331. * @type {EntityCollection}
  1332. */
  1333. entities : {
  1334. get : function() {
  1335. return this._entityCollection;
  1336. }
  1337. },
  1338. /**
  1339. * Gets a value indicating if the data source is currently loading data.
  1340. * @memberof CzmlDataSource.prototype
  1341. * @type {Boolean}
  1342. */
  1343. isLoading : {
  1344. get : function() {
  1345. return this._isLoading;
  1346. }
  1347. },
  1348. /**
  1349. * Gets an event that will be raised when the underlying data changes.
  1350. * @memberof CzmlDataSource.prototype
  1351. * @type {Event}
  1352. */
  1353. changedEvent : {
  1354. get : function() {
  1355. return this._changed;
  1356. }
  1357. },
  1358. /**
  1359. * Gets an event that will be raised if an error is encountered during processing.
  1360. * @memberof CzmlDataSource.prototype
  1361. * @type {Event}
  1362. */
  1363. errorEvent : {
  1364. get : function() {
  1365. return this._error;
  1366. }
  1367. },
  1368. /**
  1369. * Gets an event that will be raised when the data source either starts or stops loading.
  1370. * @memberof CzmlDataSource.prototype
  1371. * @type {Event}
  1372. */
  1373. loadingEvent : {
  1374. get : function() {
  1375. return this._loading;
  1376. }
  1377. }
  1378. });
  1379. /**
  1380. * Gets the array of CZML processing functions.
  1381. * @memberof CzmlDataSource
  1382. * @type Array
  1383. */
  1384. CzmlDataSource.updaters = [
  1385. processBillboard, //
  1386. processEllipse, //
  1387. processEllipsoid, //
  1388. processLabel, //
  1389. processModel, //
  1390. processName, //
  1391. processDescription, //
  1392. processPath, //
  1393. processPoint, //
  1394. processPolygon, //
  1395. processPolyline, //
  1396. processRectangle, //
  1397. processPosition, //
  1398. processViewFrom, //
  1399. processWall, //
  1400. processOrientation, //
  1401. processAvailability];
  1402. /**
  1403. * Processes the provided CZML without clearing any existing data.
  1404. *
  1405. * @param {Object} czml The CZML to be processed.
  1406. * @param {String} sourceUri The source URI of the CZML.
  1407. */
  1408. CzmlDataSource.prototype.process = function(czml, sourceUri) {
  1409. //>>includeStart('debug', pragmas.debug);
  1410. if (!defined(czml)) {
  1411. throw new DeveloperError('czml is required.');
  1412. }
  1413. //>>includeEnd('debug');
  1414. loadCzml(this, czml, sourceUri, false);
  1415. };
  1416. /**
  1417. * Replaces any existing data with the provided CZML.
  1418. *
  1419. * @param {Object} czml The CZML to be processed.
  1420. * @param {String} source The source URI of the CZML.
  1421. */
  1422. CzmlDataSource.prototype.load = function(czml, sourceUri) {
  1423. //>>includeStart('debug', pragmas.debug);
  1424. if (!defined(czml)) {
  1425. throw new DeveloperError('czml is required.');
  1426. }
  1427. //>>includeEnd('debug');
  1428. loadCzml(this, czml, sourceUri, true);
  1429. };
  1430. /**
  1431. * Asynchronously processes the CZML at the provided url without clearing any existing data.
  1432. *
  1433. * @param {Object} url The url to be processed.
  1434. * @returns {Promise} a promise that will resolve when the CZML is processed.
  1435. */
  1436. CzmlDataSource.prototype.processUrl = function(url) {
  1437. //>>includeStart('debug', pragmas.debug);
  1438. if (!defined(url)) {
  1439. throw new DeveloperError('url is required.');
  1440. }
  1441. //>>includeEnd('debug');
  1442. DataSource.setLoading(this, true);
  1443. var dataSource = this;
  1444. return when(loadJson(url), function(czml) {
  1445. loadCzml(dataSource, czml, url, false);
  1446. }).otherwise(function(error) {
  1447. DataSource.setLoading(dataSource, false);
  1448. dataSource._error.raiseEvent(dataSource, error);
  1449. return when.reject(error);
  1450. });
  1451. };
  1452. /**
  1453. * Asynchronously loads the CZML at the provided url, replacing any existing data.
  1454. *
  1455. * @param {Object} url The url to be processed.
  1456. * @returns {Promise} a promise that will resolve when the CZML is processed.
  1457. */
  1458. CzmlDataSource.prototype.loadUrl = function(url) {
  1459. //>>includeStart('debug', pragmas.debug);
  1460. if (!defined(url)) {
  1461. throw new DeveloperError('url is required.');
  1462. }
  1463. //>>includeEnd('debug');
  1464. DataSource.setLoading(this, true);
  1465. var dataSource = this;
  1466. return when(loadJson(url), function(czml) {
  1467. loadCzml(dataSource, czml, url, true);
  1468. }).otherwise(function(error) {
  1469. DataSource.setLoading(dataSource, false);
  1470. dataSource._error.raiseEvent(dataSource, error);
  1471. return when.reject(error);
  1472. });
  1473. };
  1474. /**
  1475. * A helper function used by custom CZML updater functions
  1476. * which creates or updates a {@link Property} from a CZML packet.
  1477. * @function
  1478. *
  1479. * @param {Function} type The constructor function for the property being processed.
  1480. * @param {Object} object The object on which the property will be added or updated.
  1481. * @param {String} propertyName The name of the property on the object.
  1482. * @param {Object} packetData The CZML packet being processed.
  1483. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  1484. * @param {String} sourceUri The originating uri of the data being processed.
  1485. * @param {EntityCollection} entityCollection The collection being processsed.
  1486. */
  1487. CzmlDataSource.processPacketData = processPacketData;
  1488. /**
  1489. * A helper function used by custom CZML updater functions
  1490. * which creates or updates a {@link PositionProperty} from a CZML packet.
  1491. * @function
  1492. *
  1493. * @param {Object} object The object on which the property will be added or updated.
  1494. * @param {String} propertyName The name of the property on the object.
  1495. * @param {Object} packetData The CZML packet being processed.
  1496. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  1497. * @param {String} sourceUri The originating uri of the data being processed.
  1498. * @param {EntityCollection} entityCollection The collection being processsed.
  1499. */
  1500. CzmlDataSource.processPositionPacketData = processPositionPacketData;
  1501. /**
  1502. * A helper function used by custom CZML updater functions
  1503. * which creates or updates a {@link MaterialProperty} from a CZML packet.
  1504. * @function
  1505. *
  1506. * @param {Object} object The object on which the property will be added or updated.
  1507. * @param {String} propertyName The name of the property on the object.
  1508. * @param {Object} packetData The CZML packet being processed.
  1509. * @param {TimeInterval} interval A constraining interval for which the data is valid.
  1510. * @param {String} sourceUri The originating uri of the data being processed.
  1511. * @param {EntityCollection} entityCollection The collection being processsed.
  1512. */
  1513. CzmlDataSource.processMaterialPacketData = processMaterialPacketData;
  1514. CzmlDataSource._processCzml = function(czml, entityCollection, sourceUri, updaterFunctions, dataSource) {
  1515. updaterFunctions = defined(updaterFunctions) ? updaterFunctions : CzmlDataSource.updaters;
  1516. if (isArray(czml)) {
  1517. for (var i = 0, len = czml.length; i < len; i++) {
  1518. processCzmlPacket(czml[i], entityCollection, updaterFunctions, sourceUri, dataSource);
  1519. }
  1520. } else {
  1521. processCzmlPacket(czml, entityCollection, updaterFunctions, sourceUri, dataSource);
  1522. }
  1523. };
  1524. return CzmlDataSource;
  1525. });