CustomDataSource.js 4.9 KB

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