BoxGraphics.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. * <p>
  121. * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.
  122. * </p>
  123. * @memberof BoxGraphics.prototype
  124. * @type {Property|undefined}
  125. * @default 1.0
  126. */
  127. outlineWidth: createPropertyDescriptor("outlineWidth"),
  128. /**
  129. * Get or sets the enum Property specifying whether the box
  130. * casts or receives shadows from light sources.
  131. * @memberof BoxGraphics.prototype
  132. * @type {Property|undefined}
  133. * @default ShadowMode.DISABLED
  134. */
  135. shadows: createPropertyDescriptor("shadows"),
  136. /**
  137. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this box will be displayed.
  138. * @memberof BoxGraphics.prototype
  139. * @type {Property|undefined}
  140. */
  141. distanceDisplayCondition: createPropertyDescriptor(
  142. "distanceDisplayCondition"
  143. ),
  144. });
  145. /**
  146. * Duplicates this instance.
  147. *
  148. * @param {BoxGraphics} [result] The object onto which to store the result.
  149. * @returns {BoxGraphics} The modified result parameter or a new instance if one was not provided.
  150. */
  151. BoxGraphics.prototype.clone = function (result) {
  152. if (!defined(result)) {
  153. return new BoxGraphics(this);
  154. }
  155. result.show = this.show;
  156. result.dimensions = this.dimensions;
  157. result.heightReference = this.heightReference;
  158. result.fill = this.fill;
  159. result.material = this.material;
  160. result.outline = this.outline;
  161. result.outlineColor = this.outlineColor;
  162. result.outlineWidth = this.outlineWidth;
  163. result.shadows = this.shadows;
  164. result.distanceDisplayCondition = this.distanceDisplayCondition;
  165. return result;
  166. };
  167. /**
  168. * Assigns each unassigned property on this object to the value
  169. * of the same property on the provided source object.
  170. *
  171. * @param {BoxGraphics} source The object to be merged into this object.
  172. */
  173. BoxGraphics.prototype.merge = function (source) {
  174. //>>includeStart('debug', pragmas.debug);
  175. if (!defined(source)) {
  176. throw new DeveloperError("source is required.");
  177. }
  178. //>>includeEnd('debug');
  179. this.show = defaultValue(this.show, source.show);
  180. this.dimensions = defaultValue(this.dimensions, source.dimensions);
  181. this.heightReference = defaultValue(
  182. this.heightReference,
  183. source.heightReference
  184. );
  185. this.fill = defaultValue(this.fill, source.fill);
  186. this.material = defaultValue(this.material, source.material);
  187. this.outline = defaultValue(this.outline, source.outline);
  188. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  189. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  190. this.shadows = defaultValue(this.shadows, source.shadows);
  191. this.distanceDisplayCondition = defaultValue(
  192. this.distanceDisplayCondition,
  193. source.distanceDisplayCondition
  194. );
  195. };
  196. export default BoxGraphics;