PlaneGraphics.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} PlaneGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the PlaneGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the plane.
  13. * @property {Property | Plane} [plane] A {@link Plane} Property specifying the normal and distance for the plane.
  14. * @property {Property | Cartesian2} [dimensions] A {@link Cartesian2} Property specifying the width and height of the plane.
  15. * @property {Property | boolean} [fill=true] A boolean Property specifying whether the plane is filled with the provided material.
  16. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the plane.
  17. * @property {Property | boolean} [outline=false] A boolean Property specifying whether the plane 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 plane casts or receives shadows from light sources.
  21. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this plane will be displayed.
  22. */
  23. /**
  24. * Describes a plane. The center position and orientation are determined by the containing {@link Entity}.
  25. *
  26. * @alias PlaneGraphics
  27. * @constructor
  28. *
  29. * @param {PlaneGraphics.ConstructorOptions} [options] Object describing initialization options
  30. *
  31. * @demo {@link https://sandcastle.cesium.com/index.html?src=Plane.html|Cesium Sandcastle Plane Demo}
  32. */
  33. function PlaneGraphics(options) {
  34. this._definitionChanged = new Event();
  35. this._show = undefined;
  36. this._showSubscription = undefined;
  37. this._plane = undefined;
  38. this._planeSubscription = undefined;
  39. this._dimensions = undefined;
  40. this._dimensionsSubscription = undefined;
  41. this._fill = undefined;
  42. this._fillSubscription = undefined;
  43. this._material = undefined;
  44. this._materialSubscription = undefined;
  45. this._outline = undefined;
  46. this._outlineSubscription = undefined;
  47. this._outlineColor = undefined;
  48. this._outlineColorSubscription = undefined;
  49. this._outlineWidth = undefined;
  50. this._outlineWidthSubscription = undefined;
  51. this._shadows = undefined;
  52. this._shadowsSubscription = undefined;
  53. this._distanceDisplayCondition = undefined;
  54. this._distanceDisplayConditionSubscription = undefined;
  55. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  56. }
  57. Object.defineProperties(PlaneGraphics.prototype, {
  58. /**
  59. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  60. * @memberof PlaneGraphics.prototype
  61. * @type {Event}
  62. * @readonly
  63. */
  64. definitionChanged: {
  65. get: function () {
  66. return this._definitionChanged;
  67. },
  68. },
  69. /**
  70. * Gets or sets the boolean Property specifying the visibility of the plane.
  71. * @memberof PlaneGraphics.prototype
  72. * @type {Property|undefined}
  73. * @default true
  74. */
  75. show: createPropertyDescriptor("show"),
  76. /**
  77. * Gets or sets the {@link Plane} Property specifying the normal and distance of the plane.
  78. *
  79. * @memberof PlaneGraphics.prototype
  80. * @type {Property|undefined}
  81. */
  82. plane: createPropertyDescriptor("plane"),
  83. /**
  84. * Gets or sets the {@link Cartesian2} Property specifying the width and height of the plane.
  85. *
  86. * @memberof PlaneGraphics.prototype
  87. * @type {Property|undefined}
  88. */
  89. dimensions: createPropertyDescriptor("dimensions"),
  90. /**
  91. * Gets or sets the boolean Property specifying whether the plane is filled with the provided material.
  92. * @memberof PlaneGraphics.prototype
  93. * @type {Property|undefined}
  94. * @default true
  95. */
  96. fill: createPropertyDescriptor("fill"),
  97. /**
  98. * Gets or sets the material used to fill the plane.
  99. * @memberof PlaneGraphics.prototype
  100. * @type {MaterialProperty}
  101. * @default Color.WHITE
  102. */
  103. material: createMaterialPropertyDescriptor("material"),
  104. /**
  105. * Gets or sets the Property specifying whether the plane is outlined.
  106. * @memberof PlaneGraphics.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 PlaneGraphics.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 PlaneGraphics.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 plane
  130. * casts or receives shadows from light sources.
  131. * @memberof PlaneGraphics.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 plane will be displayed.
  138. * @memberof PlaneGraphics.prototype
  139. * @type {Property|undefined}
  140. */
  141. distanceDisplayCondition: createPropertyDescriptor(
  142. "distanceDisplayCondition"
  143. ),
  144. });
  145. /**
  146. * Duplicates this instance.
  147. *
  148. * @param {PlaneGraphics} [result] The object onto which to store the result.
  149. * @returns {PlaneGraphics} The modified result parameter or a new instance if one was not provided.
  150. */
  151. PlaneGraphics.prototype.clone = function (result) {
  152. if (!defined(result)) {
  153. return new PlaneGraphics(this);
  154. }
  155. result.show = this.show;
  156. result.plane = this.plane;
  157. result.dimensions = this.dimensions;
  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 {PlaneGraphics} source The object to be merged into this object.
  172. */
  173. PlaneGraphics.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.plane = defaultValue(this.plane, source.plane);
  181. this.dimensions = defaultValue(this.dimensions, source.dimensions);
  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 PlaneGraphics;