CustomDataSource.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import defined from "../Core/defined.js";
  2. import DeveloperError from "../Core/DeveloperError.js";
  3. import Event from "../Core/Event.js";
  4. import DataSource from "./DataSource.js";
  5. import EntityCluster from "./EntityCluster.js";
  6. import EntityCollection from "./EntityCollection.js";
  7. /**
  8. * A {@link DataSource} implementation which can be used to manually manage a group of entities.
  9. *
  10. * @alias CustomDataSource
  11. * @constructor
  12. *
  13. * @param {string} [name] A human-readable name for this instance.
  14. *
  15. * @example
  16. * const dataSource = new Cesium.CustomDataSource('myData');
  17. *
  18. * const entity = dataSource.entities.add({
  19. * position : Cesium.Cartesian3.fromDegrees(1, 2, 0),
  20. * billboard : {
  21. * image : 'image.png'
  22. * }
  23. * });
  24. *
  25. * viewer.dataSources.add(dataSource);
  26. */
  27. function CustomDataSource(name) {
  28. this._name = name;
  29. this._clock = undefined;
  30. this._changed = new Event();
  31. this._error = new Event();
  32. this._isLoading = false;
  33. this._loading = new Event();
  34. this._entityCollection = new EntityCollection(this);
  35. this._entityCluster = new EntityCluster();
  36. }
  37. Object.defineProperties(CustomDataSource.prototype, {
  38. /**
  39. * Gets or sets a human-readable name for this instance.
  40. * @memberof CustomDataSource.prototype
  41. * @type {string}
  42. */
  43. name: {
  44. get: function () {
  45. return this._name;
  46. },
  47. set: function (value) {
  48. if (this._name !== value) {
  49. this._name = value;
  50. this._changed.raiseEvent(this);
  51. }
  52. },
  53. },
  54. /**
  55. * Gets or sets the clock for this instance.
  56. * @memberof CustomDataSource.prototype
  57. * @type {DataSourceClock}
  58. */
  59. clock: {
  60. get: function () {
  61. return this._clock;
  62. },
  63. set: function (value) {
  64. if (this._clock !== value) {
  65. this._clock = value;
  66. this._changed.raiseEvent(this);
  67. }
  68. },
  69. },
  70. /**
  71. * Gets the collection of {@link Entity} instances.
  72. * @memberof CustomDataSource.prototype
  73. * @type {EntityCollection}
  74. */
  75. entities: {
  76. get: function () {
  77. return this._entityCollection;
  78. },
  79. },
  80. /**
  81. * Gets or sets whether the data source is currently loading data.
  82. * @memberof CustomDataSource.prototype
  83. * @type {boolean}
  84. */
  85. isLoading: {
  86. get: function () {
  87. return this._isLoading;
  88. },
  89. set: function (value) {
  90. DataSource.setLoading(this, value);
  91. },
  92. },
  93. /**
  94. * Gets an event that will be raised when the underlying data changes.
  95. * @memberof CustomDataSource.prototype
  96. * @type {Event}
  97. */
  98. changedEvent: {
  99. get: function () {
  100. return this._changed;
  101. },
  102. },
  103. /**
  104. * Gets an event that will be raised if an error is encountered during processing.
  105. * @memberof CustomDataSource.prototype
  106. * @type {Event}
  107. */
  108. errorEvent: {
  109. get: function () {
  110. return this._error;
  111. },
  112. },
  113. /**
  114. * Gets an event that will be raised when the data source either starts or stops loading.
  115. * @memberof CustomDataSource.prototype
  116. * @type {Event}
  117. */
  118. loadingEvent: {
  119. get: function () {
  120. return this._loading;
  121. },
  122. },
  123. /**
  124. * Gets whether or not this data source should be displayed.
  125. * @memberof CustomDataSource.prototype
  126. * @type {boolean}
  127. */
  128. show: {
  129. get: function () {
  130. return this._entityCollection.show;
  131. },
  132. set: function (value) {
  133. this._entityCollection.show = value;
  134. },
  135. },
  136. /**
  137. * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.
  138. *
  139. * @memberof CustomDataSource.prototype
  140. * @type {EntityCluster}
  141. */
  142. clustering: {
  143. get: function () {
  144. return this._entityCluster;
  145. },
  146. set: function (value) {
  147. //>>includeStart('debug', pragmas.debug);
  148. if (!defined(value)) {
  149. throw new DeveloperError("value must be defined.");
  150. }
  151. //>>includeEnd('debug');
  152. this._entityCluster = value;
  153. },
  154. },
  155. });
  156. /**
  157. * Updates the data source to the provided time. This function is optional and
  158. * is not required to be implemented. It is provided for data sources which
  159. * retrieve data based on the current animation time or scene state.
  160. * If implemented, update will be called by {@link DataSourceDisplay} once a frame.
  161. *
  162. * @param {JulianDate} time The simulation time.
  163. * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.
  164. */
  165. CustomDataSource.prototype.update = function (time) {
  166. return true;
  167. };
  168. export default CustomDataSource;