DataSource.js 3.4 KB

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