DataSource.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*global define*/
  2. define([
  3. '../Core/defineProperties',
  4. '../Core/DeveloperError'
  5. ], function(
  6. defineProperties,
  7. DeveloperError) {
  8. "use strict";
  9. /**
  10. * Defines the interface for data sources, which turn arbitrary data into a
  11. * {@link EntityCollection} for generic consumption. This object is an interface
  12. * for documentation purposes and is not intended to be instantiated directly.
  13. * @alias DataSource
  14. * @constructor
  15. *
  16. * @see Entity
  17. * @see DataSourceDisplay
  18. */
  19. var DataSource = function() {
  20. DeveloperError.throwInstantiationError();
  21. };
  22. defineProperties(DataSource.prototype, {
  23. /**
  24. * Gets a human-readable name for this instance.
  25. * @memberof DataSource.prototype
  26. * @type {String}
  27. */
  28. name : {
  29. get : DeveloperError.throwInstantiationError
  30. },
  31. /**
  32. * Gets the preferred clock settings for this data source.
  33. * @memberof DataSource.prototype
  34. * @type {DataSourceClock}
  35. */
  36. clock : {
  37. get : DeveloperError.throwInstantiationError
  38. },
  39. /**
  40. * Gets the collection of {@link Entity} instances.
  41. * @memberof DataSource.prototype
  42. * @type {EntityCollection}
  43. */
  44. entities : {
  45. get : DeveloperError.throwInstantiationError
  46. },
  47. /**
  48. * Gets a value indicating if the data source is currently loading data.
  49. * @memberof DataSource.prototype
  50. * @type {Boolean}
  51. */
  52. isLoading : {
  53. get : DeveloperError.throwInstantiationError
  54. },
  55. /**
  56. * Gets an event that will be raised when the underlying data changes.
  57. * @memberof DataSource.prototype
  58. * @type {Event}
  59. */
  60. changedEvent : {
  61. get : DeveloperError.throwInstantiationError
  62. },
  63. /**
  64. * Gets an event that will be raised if an error is encountered during processing.
  65. * @memberof DataSource.prototype
  66. * @type {Event}
  67. */
  68. errorEvent : {
  69. get : DeveloperError.throwInstantiationError
  70. },
  71. /**
  72. * Gets an event that will be raised when the value of isLoading changes.
  73. * @memberof DataSource.prototype
  74. * @type {Event}
  75. */
  76. loadingEvent : {
  77. get : DeveloperError.throwInstantiationError
  78. }
  79. });
  80. /**
  81. * Updates the data source to the provided time. This function is optional and
  82. * is not required to be implemented. It is provided for data sources which
  83. * retrieve data based on the current animation time or scene state.
  84. * If implemented, update will be called by {@link DataSourceDisplay} once a frame.
  85. * @function
  86. *
  87. * @param {JulianDate} time The simulation time.
  88. * @returns {Boolean} True if this data source is ready to be displayed at the provided time, false otherwise.
  89. */
  90. DataSource.prototype.update = DeveloperError.throwInstantiationError;
  91. /**
  92. * @private
  93. */
  94. DataSource.setLoading = function(dataSource, isLoading) {
  95. if (dataSource._isLoading !== isLoading) {
  96. if (isLoading) {
  97. dataSource._entityCollection.suspendEvents();
  98. } else {
  99. dataSource._entityCollection.resumeEvents();
  100. }
  101. dataSource._isLoading = isLoading;
  102. dataSource._loading.raiseEvent(dataSource, isLoading);
  103. }
  104. };
  105. return DataSource;
  106. });