BoxGraphics.js 7.6 KB

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