PathGraphics.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import defaultValue from "../Core/defaultValue.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import Event from "../Core/Event.js";
  5. import createMaterialPropertyDescriptor from "./createMaterialPropertyDescriptor.js";
  6. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  7. /**
  8. * @typedef {Object} PathGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the PathGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the path.
  13. * @property {Property | number} [leadTime] A Property specifying the number of seconds in front the object to show.
  14. * @property {Property | number} [trailTime] A Property specifying the number of seconds behind of the object to show.
  15. * @property {Property | number} [width=1.0] A numeric Property specifying the width in pixels.
  16. * @property {Property | number} [resolution=60] A numeric Property specifying the maximum number of seconds to step when sampling the position.
  17. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to draw the path.
  18. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this path will be displayed.
  19. */
  20. /**
  21. * Describes a polyline defined as the path made by an {@link Entity} as it moves over time.
  22. *
  23. * @alias PathGraphics
  24. * @constructor
  25. *
  26. * @param {PathGraphics.ConstructorOptions} [options] Object describing initialization options
  27. */
  28. function PathGraphics(options) {
  29. this._definitionChanged = new Event();
  30. this._show = undefined;
  31. this._showSubscription = undefined;
  32. this._leadTime = undefined;
  33. this._leadTimeSubscription = undefined;
  34. this._trailTime = undefined;
  35. this._trailTimeSubscription = undefined;
  36. this._width = undefined;
  37. this._widthSubscription = undefined;
  38. this._resolution = undefined;
  39. this._resolutionSubscription = undefined;
  40. this._material = undefined;
  41. this._materialSubscription = undefined;
  42. this._distanceDisplayCondition = undefined;
  43. this._distanceDisplayConditionSubscription = undefined;
  44. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  45. }
  46. Object.defineProperties(PathGraphics.prototype, {
  47. /**
  48. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  49. * @memberof PathGraphics.prototype
  50. * @type {Event}
  51. * @readonly
  52. */
  53. definitionChanged: {
  54. get: function () {
  55. return this._definitionChanged;
  56. },
  57. },
  58. /**
  59. * Gets or sets the boolean Property specifying the visibility of the path.
  60. * @memberof PathGraphics.prototype
  61. * @type {Property|undefined}
  62. * @default true
  63. */
  64. show: createPropertyDescriptor("show"),
  65. /**
  66. * Gets or sets the Property specifying the number of seconds in front of the object to show.
  67. * @memberof PathGraphics.prototype
  68. * @type {Property|undefined}
  69. */
  70. leadTime: createPropertyDescriptor("leadTime"),
  71. /**
  72. * Gets or sets the Property specifying the number of seconds behind the object to show.
  73. * @memberof PathGraphics.prototype
  74. * @type {Property|undefined}
  75. */
  76. trailTime: createPropertyDescriptor("trailTime"),
  77. /**
  78. * Gets or sets the numeric Property specifying the width in pixels.
  79. * @memberof PathGraphics.prototype
  80. * @type {Property|undefined}
  81. * @default 1.0
  82. */
  83. width: createPropertyDescriptor("width"),
  84. /**
  85. * Gets or sets the Property specifying the maximum number of seconds to step when sampling the position.
  86. * @memberof PathGraphics.prototype
  87. * @type {Property|undefined}
  88. * @default 60
  89. */
  90. resolution: createPropertyDescriptor("resolution"),
  91. /**
  92. * Gets or sets the Property specifying the material used to draw the path.
  93. * @memberof PathGraphics.prototype
  94. * @type {MaterialProperty}
  95. * @default Color.WHITE
  96. */
  97. material: createMaterialPropertyDescriptor("material"),
  98. /**
  99. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this path will be displayed.
  100. * @memberof PathGraphics.prototype
  101. * @type {Property|undefined}
  102. */
  103. distanceDisplayCondition: createPropertyDescriptor(
  104. "distanceDisplayCondition"
  105. ),
  106. });
  107. /**
  108. * Duplicates this instance.
  109. *
  110. * @param {PathGraphics} [result] The object onto which to store the result.
  111. * @returns {PathGraphics} The modified result parameter or a new instance if one was not provided.
  112. */
  113. PathGraphics.prototype.clone = function (result) {
  114. if (!defined(result)) {
  115. return new PathGraphics(this);
  116. }
  117. result.show = this.show;
  118. result.leadTime = this.leadTime;
  119. result.trailTime = this.trailTime;
  120. result.width = this.width;
  121. result.resolution = this.resolution;
  122. result.material = this.material;
  123. result.distanceDisplayCondition = this.distanceDisplayCondition;
  124. return result;
  125. };
  126. /**
  127. * Assigns each unassigned property on this object to the value
  128. * of the same property on the provided source object.
  129. *
  130. * @param {PathGraphics} source The object to be merged into this object.
  131. */
  132. PathGraphics.prototype.merge = function (source) {
  133. //>>includeStart('debug', pragmas.debug);
  134. if (!defined(source)) {
  135. throw new DeveloperError("source is required.");
  136. }
  137. //>>includeEnd('debug');
  138. this.show = defaultValue(this.show, source.show);
  139. this.leadTime = defaultValue(this.leadTime, source.leadTime);
  140. this.trailTime = defaultValue(this.trailTime, source.trailTime);
  141. this.width = defaultValue(this.width, source.width);
  142. this.resolution = defaultValue(this.resolution, source.resolution);
  143. this.material = defaultValue(this.material, source.material);
  144. this.distanceDisplayCondition = defaultValue(
  145. this.distanceDisplayCondition,
  146. source.distanceDisplayCondition
  147. );
  148. };
  149. export default PathGraphics;