PlaneGraphics.js 8.2 KB

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