WallGraphics.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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} WallGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the WallGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the wall.
  13. * @property {Property | Array<Cartesian3>} [positions] A Property specifying the array of {@link Cartesian3} positions which define the top of the wall.
  14. * @property {Property | Array<number>} [minimumHeights] A Property specifying an array of heights to be used for the bottom of the wall instead of the globe surface.
  15. * @property {Property | Array<number>} [maximumHeights] A Property specifying an array of heights to be used for the top of the wall instead of the height of each position.
  16. * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude point.
  17. * @property {Property | boolean} [fill=true] A boolean Property specifying whether the wall is filled with the provided material.
  18. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the wall.
  19. * @property {Property | boolean} [outline=false] A boolean Property specifying whether the wall is outlined.
  20. * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  21. * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.
  22. * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the wall casts or receives shadows from light sources.
  23. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this wall will be displayed.
  24. */
  25. /**
  26. * Describes a two dimensional wall defined as a line strip and optional maximum and minimum heights.
  27. * The wall conforms to the curvature of the globe and can be placed along the surface or at altitude.
  28. *
  29. * @alias WallGraphics
  30. * @constructor
  31. *
  32. * @param {WallGraphics.ConstructorOptions} [options] Object describing initialization options
  33. *
  34. * @see Entity
  35. * @demo {@link https://sandcastle.cesium.com/index.html?src=Wall.html|Cesium Sandcastle Wall Demo}
  36. */
  37. function WallGraphics(options) {
  38. this._definitionChanged = new Event();
  39. this._show = undefined;
  40. this._showSubscription = undefined;
  41. this._positions = undefined;
  42. this._positionsSubscription = undefined;
  43. this._minimumHeights = undefined;
  44. this._minimumHeightsSubscription = undefined;
  45. this._maximumHeights = undefined;
  46. this._maximumHeightsSubscription = undefined;
  47. this._granularity = undefined;
  48. this._granularitySubscription = undefined;
  49. this._fill = undefined;
  50. this._fillSubscription = undefined;
  51. this._material = undefined;
  52. this._materialSubscription = undefined;
  53. this._outline = undefined;
  54. this._outlineSubscription = undefined;
  55. this._outlineColor = undefined;
  56. this._outlineColorSubscription = undefined;
  57. this._outlineWidth = undefined;
  58. this._outlineWidthSubscription = undefined;
  59. this._shadows = undefined;
  60. this._shadowsSubscription = undefined;
  61. this._distanceDisplayCondition = undefined;
  62. this._distanceDisplayConditionSubscription = undefined;
  63. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  64. }
  65. Object.defineProperties(WallGraphics.prototype, {
  66. /**
  67. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  68. * @memberof WallGraphics.prototype
  69. *
  70. * @type {Event}
  71. * @readonly
  72. */
  73. definitionChanged: {
  74. get: function () {
  75. return this._definitionChanged;
  76. },
  77. },
  78. /**
  79. * Gets or sets the boolean Property specifying the visibility of the wall.
  80. * @memberof WallGraphics.prototype
  81. * @type {Property|undefined}
  82. * @default true
  83. */
  84. show: createPropertyDescriptor("show"),
  85. /**
  86. * Gets or sets the Property specifying the array of {@link Cartesian3} positions which define the top of the wall.
  87. * @memberof WallGraphics.prototype
  88. * @type {Property|undefined}
  89. */
  90. positions: createPropertyDescriptor("positions"),
  91. /**
  92. * Gets or sets the Property specifying an array of heights to be used for the bottom of the wall instead of the surface of the globe.
  93. * If defined, the array must be the same length as {@link Wall#positions}.
  94. * @memberof WallGraphics.prototype
  95. * @type {Property|undefined}
  96. */
  97. minimumHeights: createPropertyDescriptor("minimumHeights"),
  98. /**
  99. * Gets or sets the Property specifying an array of heights to be used for the top of the wall instead of the height of each position.
  100. * If defined, the array must be the same length as {@link Wall#positions}.
  101. * @memberof WallGraphics.prototype
  102. * @type {Property|undefined}
  103. */
  104. maximumHeights: createPropertyDescriptor("maximumHeights"),
  105. /**
  106. * Gets or sets the numeric Property specifying the angular distance between points on the wall.
  107. * @memberof WallGraphics.prototype
  108. * @type {Property|undefined}
  109. * @default {CesiumMath.RADIANS_PER_DEGREE}
  110. */
  111. granularity: createPropertyDescriptor("granularity"),
  112. /**
  113. * Gets or sets the boolean Property specifying whether the wall is filled with the provided material.
  114. * @memberof WallGraphics.prototype
  115. * @type {Property|undefined}
  116. * @default true
  117. */
  118. fill: createPropertyDescriptor("fill"),
  119. /**
  120. * Gets or sets the Property specifying the material used to fill the wall.
  121. * @memberof WallGraphics.prototype
  122. * @type {MaterialProperty}
  123. * @default Color.WHITE
  124. */
  125. material: createMaterialPropertyDescriptor("material"),
  126. /**
  127. * Gets or sets the Property specifying whether the wall is outlined.
  128. * @memberof WallGraphics.prototype
  129. * @type {Property|undefined}
  130. * @default false
  131. */
  132. outline: createPropertyDescriptor("outline"),
  133. /**
  134. * Gets or sets the Property specifying the {@link Color} of the outline.
  135. * @memberof WallGraphics.prototype
  136. * @type {Property|undefined}
  137. * @default Color.BLACK
  138. */
  139. outlineColor: createPropertyDescriptor("outlineColor"),
  140. /**
  141. * Gets or sets the numeric Property specifying the width of the outline.
  142. * @memberof WallGraphics.prototype
  143. * @type {Property|undefined}
  144. * @default 1.0
  145. */
  146. outlineWidth: createPropertyDescriptor("outlineWidth"),
  147. /**
  148. * Get or sets the enum Property specifying whether the wall
  149. * casts or receives shadows from light sources.
  150. * @memberof WallGraphics.prototype
  151. * @type {Property|undefined}
  152. * @default ShadowMode.DISABLED
  153. */
  154. shadows: createPropertyDescriptor("shadows"),
  155. /**
  156. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this wall will be displayed.
  157. * @memberof WallGraphics.prototype
  158. * @type {Property|undefined}
  159. */
  160. distanceDisplayCondition: createPropertyDescriptor(
  161. "distanceDisplayCondition"
  162. ),
  163. });
  164. /**
  165. * Duplicates this instance.
  166. *
  167. * @param {WallGraphics} [result] The object onto which to store the result.
  168. * @returns {WallGraphics} The modified result parameter or a new instance if one was not provided.
  169. */
  170. WallGraphics.prototype.clone = function (result) {
  171. if (!defined(result)) {
  172. return new WallGraphics(this);
  173. }
  174. result.show = this.show;
  175. result.positions = this.positions;
  176. result.minimumHeights = this.minimumHeights;
  177. result.maximumHeights = this.maximumHeights;
  178. result.granularity = this.granularity;
  179. result.fill = this.fill;
  180. result.material = this.material;
  181. result.outline = this.outline;
  182. result.outlineColor = this.outlineColor;
  183. result.outlineWidth = this.outlineWidth;
  184. result.shadows = this.shadows;
  185. result.distanceDisplayCondition = this.distanceDisplayCondition;
  186. return result;
  187. };
  188. /**
  189. * Assigns each unassigned property on this object to the value
  190. * of the same property on the provided source object.
  191. *
  192. * @param {WallGraphics} source The object to be merged into this object.
  193. */
  194. WallGraphics.prototype.merge = function (source) {
  195. //>>includeStart('debug', pragmas.debug);
  196. if (!defined(source)) {
  197. throw new DeveloperError("source is required.");
  198. }
  199. //>>includeEnd('debug');
  200. this.show = defaultValue(this.show, source.show);
  201. this.positions = defaultValue(this.positions, source.positions);
  202. this.minimumHeights = defaultValue(
  203. this.minimumHeights,
  204. source.minimumHeights
  205. );
  206. this.maximumHeights = defaultValue(
  207. this.maximumHeights,
  208. source.maximumHeights
  209. );
  210. this.granularity = defaultValue(this.granularity, source.granularity);
  211. this.fill = defaultValue(this.fill, source.fill);
  212. this.material = defaultValue(this.material, source.material);
  213. this.outline = defaultValue(this.outline, source.outline);
  214. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  215. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  216. this.shadows = defaultValue(this.shadows, source.shadows);
  217. this.distanceDisplayCondition = defaultValue(
  218. this.distanceDisplayCondition,
  219. source.distanceDisplayCondition
  220. );
  221. };
  222. export default WallGraphics;