PathGraphics.js 6.2 KB

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