BoxGraphics.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 box. The center position and orientation are determined by the containing {@link Entity}.
  10. *
  11. * @alias BoxGraphics
  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 box.
  16. * @param {Property} [options.dimensions] A {@link Cartesian3} Property specifying the length, width, and height of the box.
  17. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.
  18. * @param {Property} [options.fill=true] A boolean Property specifying whether the box is filled with the provided material.
  19. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the box.
  20. * @param {Property} [options.outline=false] A boolean Property specifying whether the box is outlined.
  21. * @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  22. * @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
  23. * @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the box casts or receives shadows from each light source.
  24. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this box will be displayed.
  25. *
  26. * @demo {@link https://sandcastle.cesium.com/index.html?src=Box.html|Cesium Sandcastle Box Demo}
  27. */
  28. function BoxGraphics(options) {
  29. this._definitionChanged = new Event();
  30. this._show = undefined;
  31. this._showSubscription = undefined;
  32. this._dimensions = undefined;
  33. this._dimensionsSubscription = undefined;
  34. this._heightReference = undefined;
  35. this._heightReferenceSubscription = undefined;
  36. this._fill = undefined;
  37. this._fillSubscription = undefined;
  38. this._material = undefined;
  39. this._materialSubscription = undefined;
  40. this._outline = undefined;
  41. this._outlineSubscription = undefined;
  42. this._outlineColor = undefined;
  43. this._outlineColorSubscription = undefined;
  44. this._outlineWidth = undefined;
  45. this._outlineWidthSubscription = undefined;
  46. this._shadows = undefined;
  47. this._shadowsSubscription = undefined;
  48. this._distanceDisplayCondition = undefined;
  49. this._distanceDisplayConditionSubscription = undefined;
  50. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  51. }
  52. defineProperties(BoxGraphics.prototype, {
  53. /**
  54. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  55. * @memberof BoxGraphics.prototype
  56. * @type {Event}
  57. * @readonly
  58. */
  59. definitionChanged : {
  60. get : function() {
  61. return this._definitionChanged;
  62. }
  63. },
  64. /**
  65. * Gets or sets the boolean Property specifying the visibility of the box.
  66. * @memberof BoxGraphics.prototype
  67. * @type {Property}
  68. * @default true
  69. */
  70. show : createPropertyDescriptor('show'),
  71. /**
  72. * Gets or sets {@link Cartesian3} Property property specifying the length, width, and height of the box.
  73. * @memberof BoxGraphics.prototype
  74. * @type {Property}
  75. */
  76. dimensions : createPropertyDescriptor('dimensions'),
  77. /**
  78. * Gets or sets the Property specifying the {@link HeightReference}.
  79. * @memberof BoxGraphics.prototype
  80. * @type {Property}
  81. * @default HeightReference.NONE
  82. */
  83. heightReference : createPropertyDescriptor('heightReference'),
  84. /**
  85. * Gets or sets the boolean Property specifying whether the box is filled with the provided material.
  86. * @memberof BoxGraphics.prototype
  87. * @type {Property}
  88. * @default true
  89. */
  90. fill : createPropertyDescriptor('fill'),
  91. /**
  92. * Gets or sets the material used to fill the box.
  93. * @memberof BoxGraphics.prototype
  94. * @type {MaterialProperty}
  95. * @default Color.WHITE
  96. */
  97. material : createMaterialPropertyDescriptor('material'),
  98. /**
  99. * Gets or sets the Property specifying whether the box is outlined.
  100. * @memberof BoxGraphics.prototype
  101. * @type {Property}
  102. * @default false
  103. */
  104. outline : createPropertyDescriptor('outline'),
  105. /**
  106. * Gets or sets the Property specifying the {@link Color} of the outline.
  107. * @memberof BoxGraphics.prototype
  108. * @type {Property}
  109. * @default Color.BLACK
  110. */
  111. outlineColor : createPropertyDescriptor('outlineColor'),
  112. /**
  113. * Gets or sets the numeric Property specifying the width of the outline.
  114. * @memberof BoxGraphics.prototype
  115. * @type {Property}
  116. * @default 1.0
  117. */
  118. outlineWidth : createPropertyDescriptor('outlineWidth'),
  119. /**
  120. * Get or sets the enum Property specifying whether the box
  121. * casts or receives shadows from each light source.
  122. * @memberof BoxGraphics.prototype
  123. * @type {Property}
  124. * @default ShadowMode.DISABLED
  125. */
  126. shadows : createPropertyDescriptor('shadows'),
  127. /**
  128. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this box will be displayed.
  129. * @memberof BoxGraphics.prototype
  130. * @type {Property}
  131. */
  132. distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition')
  133. });
  134. /**
  135. * Duplicates this instance.
  136. *
  137. * @param {BoxGraphics} [result] The object onto which to store the result.
  138. * @returns {BoxGraphics} The modified result parameter or a new instance if one was not provided.
  139. */
  140. BoxGraphics.prototype.clone = function(result) {
  141. if (!defined(result)) {
  142. return new BoxGraphics(this);
  143. }
  144. result.show = this.show;
  145. result.dimensions = this.dimensions;
  146. result.heightReference = this.heightReference;
  147. result.fill = this.fill;
  148. result.material = this.material;
  149. result.outline = this.outline;
  150. result.outlineColor = this.outlineColor;
  151. result.outlineWidth = this.outlineWidth;
  152. result.shadows = this.shadows;
  153. result.distanceDisplayCondition = this.distanceDisplayCondition;
  154. return result;
  155. };
  156. /**
  157. * Assigns each unassigned property on this object to the value
  158. * of the same property on the provided source object.
  159. *
  160. * @param {BoxGraphics} source The object to be merged into this object.
  161. */
  162. BoxGraphics.prototype.merge = function(source) {
  163. //>>includeStart('debug', pragmas.debug);
  164. if (!defined(source)) {
  165. throw new DeveloperError('source is required.');
  166. }
  167. //>>includeEnd('debug');
  168. this.show = defaultValue(this.show, source.show);
  169. this.dimensions = defaultValue(this.dimensions, source.dimensions);
  170. this.heightReference = defaultValue(this.heightReference, source.heightReference);
  171. this.fill = defaultValue(this.fill, source.fill);
  172. this.material = defaultValue(this.material, source.material);
  173. this.outline = defaultValue(this.outline, source.outline);
  174. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  175. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  176. this.shadows = defaultValue(this.shadows, source.shadows);
  177. this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
  178. };
  179. export default BoxGraphics;