WallGraphics.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. * <p>
  143. * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.
  144. * </p>
  145. * @memberof WallGraphics.prototype
  146. * @type {Property|undefined}
  147. * @default 1.0
  148. */
  149. outlineWidth: createPropertyDescriptor("outlineWidth"),
  150. /**
  151. * Get or sets the enum Property specifying whether the wall
  152. * casts or receives shadows from light sources.
  153. * @memberof WallGraphics.prototype
  154. * @type {Property|undefined}
  155. * @default ShadowMode.DISABLED
  156. */
  157. shadows: createPropertyDescriptor("shadows"),
  158. /**
  159. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this wall will be displayed.
  160. * @memberof WallGraphics.prototype
  161. * @type {Property|undefined}
  162. */
  163. distanceDisplayCondition: createPropertyDescriptor(
  164. "distanceDisplayCondition"
  165. ),
  166. });
  167. /**
  168. * Duplicates this instance.
  169. *
  170. * @param {WallGraphics} [result] The object onto which to store the result.
  171. * @returns {WallGraphics} The modified result parameter or a new instance if one was not provided.
  172. */
  173. WallGraphics.prototype.clone = function (result) {
  174. if (!defined(result)) {
  175. return new WallGraphics(this);
  176. }
  177. result.show = this.show;
  178. result.positions = this.positions;
  179. result.minimumHeights = this.minimumHeights;
  180. result.maximumHeights = this.maximumHeights;
  181. result.granularity = this.granularity;
  182. result.fill = this.fill;
  183. result.material = this.material;
  184. result.outline = this.outline;
  185. result.outlineColor = this.outlineColor;
  186. result.outlineWidth = this.outlineWidth;
  187. result.shadows = this.shadows;
  188. result.distanceDisplayCondition = this.distanceDisplayCondition;
  189. return result;
  190. };
  191. /**
  192. * Assigns each unassigned property on this object to the value
  193. * of the same property on the provided source object.
  194. *
  195. * @param {WallGraphics} source The object to be merged into this object.
  196. */
  197. WallGraphics.prototype.merge = function (source) {
  198. //>>includeStart('debug', pragmas.debug);
  199. if (!defined(source)) {
  200. throw new DeveloperError("source is required.");
  201. }
  202. //>>includeEnd('debug');
  203. this.show = defaultValue(this.show, source.show);
  204. this.positions = defaultValue(this.positions, source.positions);
  205. this.minimumHeights = defaultValue(
  206. this.minimumHeights,
  207. source.minimumHeights
  208. );
  209. this.maximumHeights = defaultValue(
  210. this.maximumHeights,
  211. source.maximumHeights
  212. );
  213. this.granularity = defaultValue(this.granularity, source.granularity);
  214. this.fill = defaultValue(this.fill, source.fill);
  215. this.material = defaultValue(this.material, source.material);
  216. this.outline = defaultValue(this.outline, source.outline);
  217. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  218. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  219. this.shadows = defaultValue(this.shadows, source.shadows);
  220. this.distanceDisplayCondition = defaultValue(
  221. this.distanceDisplayCondition,
  222. source.distanceDisplayCondition
  223. );
  224. };
  225. export default WallGraphics;