TimeIntervalCollectionProperty.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import defined from "../Core/defined.js";
  2. import DeveloperError from "../Core/DeveloperError.js";
  3. import Event from "../Core/Event.js";
  4. import TimeIntervalCollection from "../Core/TimeIntervalCollection.js";
  5. import Property from "./Property.js";
  6. /**
  7. * A {@link Property} which is defined by a {@link TimeIntervalCollection}, where the
  8. * data property of each {@link TimeInterval} represents the value at time.
  9. *
  10. * @alias TimeIntervalCollectionProperty
  11. * @constructor
  12. *
  13. * @example
  14. * //Create a Cartesian2 interval property which contains data on August 1st, 2012
  15. * //and uses a different value every 6 hours.
  16. * var composite = new Cesium.TimeIntervalCollectionProperty();
  17. * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({
  18. * iso8601 : '2012-08-01T00:00:00.00Z/2012-08-01T06:00:00.00Z',
  19. * isStartIncluded : true,
  20. * isStopIncluded : false,
  21. * data : new Cesium.Cartesian2(2.0, 3.4)
  22. * }));
  23. * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({
  24. * iso8601 : '2012-08-01T06:00:00.00Z/2012-08-01T12:00:00.00Z',
  25. * isStartIncluded : true,
  26. * isStopIncluded : false,
  27. * data : new Cesium.Cartesian2(12.0, 2.7)
  28. * }));
  29. * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({
  30. * iso8601 : '2012-08-01T12:00:00.00Z/2012-08-01T18:00:00.00Z',
  31. * isStartIncluded : true,
  32. * isStopIncluded : false,
  33. * data : new Cesium.Cartesian2(5.0, 12.4)
  34. * }));
  35. * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({
  36. * iso8601 : '2012-08-01T18:00:00.00Z/2012-08-02T00:00:00.00Z',
  37. * isStartIncluded : true,
  38. * isStopIncluded : true,
  39. * data : new Cesium.Cartesian2(85.0, 4.1)
  40. * }));
  41. */
  42. function TimeIntervalCollectionProperty() {
  43. this._definitionChanged = new Event();
  44. this._intervals = new TimeIntervalCollection();
  45. this._intervals.changedEvent.addEventListener(
  46. TimeIntervalCollectionProperty.prototype._intervalsChanged,
  47. this
  48. );
  49. }
  50. Object.defineProperties(TimeIntervalCollectionProperty.prototype, {
  51. /**
  52. * Gets a value indicating if this property is constant. A property is considered
  53. * constant if getValue always returns the same result for the current definition.
  54. * @memberof TimeIntervalCollectionProperty.prototype
  55. *
  56. * @type {Boolean}
  57. * @readonly
  58. */
  59. isConstant: {
  60. get: function () {
  61. return this._intervals.isEmpty;
  62. },
  63. },
  64. /**
  65. * Gets the event that is raised whenever the definition of this property changes.
  66. * The definition is changed whenever setValue is called with data different
  67. * than the current value.
  68. * @memberof TimeIntervalCollectionProperty.prototype
  69. *
  70. * @type {Event}
  71. * @readonly
  72. */
  73. definitionChanged: {
  74. get: function () {
  75. return this._definitionChanged;
  76. },
  77. },
  78. /**
  79. * Gets the interval collection.
  80. * @memberof TimeIntervalCollectionProperty.prototype
  81. *
  82. * @type {TimeIntervalCollection}
  83. */
  84. intervals: {
  85. get: function () {
  86. return this._intervals;
  87. },
  88. },
  89. });
  90. /**
  91. * Gets the value of the property at the provided time.
  92. *
  93. * @param {JulianDate} time The time for which to retrieve the value.
  94. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  95. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  96. */
  97. TimeIntervalCollectionProperty.prototype.getValue = function (time, result) {
  98. //>>includeStart('debug', pragmas.debug);
  99. if (!defined(time)) {
  100. throw new DeveloperError("time is required");
  101. }
  102. //>>includeEnd('debug');
  103. var value = this._intervals.findDataForIntervalContainingDate(time);
  104. if (defined(value) && typeof value.clone === "function") {
  105. return value.clone(result);
  106. }
  107. return value;
  108. };
  109. /**
  110. * Compares this property to the provided property and returns
  111. * <code>true</code> if they are equal, <code>false</code> otherwise.
  112. *
  113. * @param {Property} [other] The other property.
  114. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  115. */
  116. TimeIntervalCollectionProperty.prototype.equals = function (other) {
  117. return (
  118. this === other || //
  119. (other instanceof TimeIntervalCollectionProperty && //
  120. this._intervals.equals(other._intervals, Property.equals))
  121. );
  122. };
  123. /**
  124. * @private
  125. */
  126. TimeIntervalCollectionProperty.prototype._intervalsChanged = function () {
  127. this._definitionChanged.raiseEvent(this);
  128. };
  129. export default TimeIntervalCollectionProperty;