DataSource.js 4.0 KB

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