EllipsoidGraphics.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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} EllipsoidGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the EllipsoidGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the ellipsoid.
  13. * @property {Property | Cartesian3} [radii] A {@link Cartesian3} Property specifying the radii of the ellipsoid.
  14. * @property {Property | Cartesian3} [innerRadii] A {@link Cartesian3} Property specifying the inner radii of the ellipsoid.
  15. * @property {Property | number} [minimumClock=0.0] A Property specifying the minimum clock angle of the ellipsoid.
  16. * @property {Property | number} [maximumClock=2*PI] A Property specifying the maximum clock angle of the ellipsoid.
  17. * @property {Property | number} [minimumCone=0.0] A Property specifying the minimum cone angle of the ellipsoid.
  18. * @property {Property | number} [maximumCone=PI] A Property specifying the maximum cone angle of the ellipsoid.
  19. * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.
  20. * @property {Property | boolean} [fill=true] A boolean Property specifying whether the ellipsoid is filled with the provided material.
  21. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the ellipsoid.
  22. * @property {Property | boolean} [outline=false] A boolean Property specifying whether the ellipsoid is outlined.
  23. * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  24. * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.
  25. * @property {Property | number} [stackPartitions=64] A Property specifying the number of stacks.
  26. * @property {Property | number} [slicePartitions=64] A Property specifying the number of radial slices.
  27. * @property {Property | number} [subdivisions=128] A Property specifying the number of samples per outline ring, determining the granularity of the curvature.
  28. * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the ellipsoid casts or receives shadows from light sources.
  29. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this ellipsoid will be displayed.
  30. */
  31. /**
  32. * Describe an ellipsoid or sphere. The center position and orientation are determined by the containing {@link Entity}.
  33. *
  34. * @alias EllipsoidGraphics
  35. * @constructor
  36. *
  37. * @param {EllipsoidGraphics.ConstructorOptions} [options] Object describing initialization options
  38. *
  39. * @demo {@link https://sandcastle.cesium.com/index.html?src=Spheres%20and%20Ellipsoids.html|Cesium Sandcastle Spheres and Ellipsoids Demo}
  40. */
  41. function EllipsoidGraphics(options) {
  42. this._definitionChanged = new Event();
  43. this._show = undefined;
  44. this._showSubscription = undefined;
  45. this._radii = undefined;
  46. this._radiiSubscription = undefined;
  47. this._innerRadii = undefined;
  48. this._innerRadiiSubscription = undefined;
  49. this._minimumClock = undefined;
  50. this._minimumClockSubscription = undefined;
  51. this._maximumClock = undefined;
  52. this._maximumClockSubscription = undefined;
  53. this._minimumCone = undefined;
  54. this._minimumConeSubscription = undefined;
  55. this._maximumCone = undefined;
  56. this._maximumConeSubscription = undefined;
  57. this._heightReference = undefined;
  58. this._heightReferenceSubscription = undefined;
  59. this._fill = undefined;
  60. this._fillSubscription = undefined;
  61. this._material = undefined;
  62. this._materialSubscription = undefined;
  63. this._outline = undefined;
  64. this._outlineSubscription = undefined;
  65. this._outlineColor = undefined;
  66. this._outlineColorSubscription = undefined;
  67. this._outlineWidth = undefined;
  68. this._outlineWidthSubscription = undefined;
  69. this._stackPartitions = undefined;
  70. this._stackPartitionsSubscription = undefined;
  71. this._slicePartitions = undefined;
  72. this._slicePartitionsSubscription = undefined;
  73. this._subdivisions = undefined;
  74. this._subdivisionsSubscription = undefined;
  75. this._shadows = undefined;
  76. this._shadowsSubscription = undefined;
  77. this._distanceDisplayCondition = undefined;
  78. this._distanceDisplayConditionSubscription = undefined;
  79. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  80. }
  81. Object.defineProperties(EllipsoidGraphics.prototype, {
  82. /**
  83. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  84. * @memberof EllipsoidGraphics.prototype
  85. *
  86. * @type {Event}
  87. * @readonly
  88. */
  89. definitionChanged: {
  90. get: function () {
  91. return this._definitionChanged;
  92. },
  93. },
  94. /**
  95. * Gets or sets the boolean Property specifying the visibility of the ellipsoid.
  96. * @memberof EllipsoidGraphics.prototype
  97. * @type {Property|undefined}
  98. * @default true
  99. */
  100. show: createPropertyDescriptor("show"),
  101. /**
  102. * Gets or sets the {@link Cartesian3} {@link Property} specifying the radii of the ellipsoid.
  103. * @memberof EllipsoidGraphics.prototype
  104. * @type {Property|undefined}
  105. */
  106. radii: createPropertyDescriptor("radii"),
  107. /**
  108. * Gets or sets the {@link Cartesian3} {@link Property} specifying the inner radii of the ellipsoid.
  109. * @memberof EllipsoidGraphics.prototype
  110. * @type {Property|undefined}
  111. * @default radii
  112. */
  113. innerRadii: createPropertyDescriptor("innerRadii"),
  114. /**
  115. * Gets or sets the Property specifying the minimum clock angle of the ellipsoid.
  116. * @memberof EllipsoidGraphics.prototype
  117. * @type {Property|undefined}
  118. * @default 0.0
  119. */
  120. minimumClock: createPropertyDescriptor("minimumClock"),
  121. /**
  122. * Gets or sets the Property specifying the maximum clock angle of the ellipsoid.
  123. * @memberof EllipsoidGraphics.prototype
  124. * @type {Property|undefined}
  125. * @default 2*PI
  126. */
  127. maximumClock: createPropertyDescriptor("maximumClock"),
  128. /**
  129. * Gets or sets the Property specifying the minimum cone angle of the ellipsoid.
  130. * @memberof EllipsoidGraphics.prototype
  131. * @type {Property|undefined}
  132. * @default 0.0
  133. */
  134. minimumCone: createPropertyDescriptor("minimumCone"),
  135. /**
  136. * Gets or sets the Property specifying the maximum cone angle of the ellipsoid.
  137. * @memberof EllipsoidGraphics.prototype
  138. * @type {Property|undefined}
  139. * @default PI
  140. */
  141. maximumCone: createPropertyDescriptor("maximumCone"),
  142. /**
  143. * Gets or sets the Property specifying the {@link HeightReference}.
  144. * @memberof EllipsoidGraphics.prototype
  145. * @type {Property|undefined}
  146. * @default HeightReference.NONE
  147. */
  148. heightReference: createPropertyDescriptor("heightReference"),
  149. /**
  150. * Gets or sets the boolean Property specifying whether the ellipsoid is filled with the provided material.
  151. * @memberof EllipsoidGraphics.prototype
  152. * @type {Property|undefined}
  153. * @default true
  154. */
  155. fill: createPropertyDescriptor("fill"),
  156. /**
  157. * Gets or sets the Property specifying the material used to fill the ellipsoid.
  158. * @memberof EllipsoidGraphics.prototype
  159. * @type {MaterialProperty}
  160. * @default Color.WHITE
  161. */
  162. material: createMaterialPropertyDescriptor("material"),
  163. /**
  164. * Gets or sets the Property specifying whether the ellipsoid is outlined.
  165. * @memberof EllipsoidGraphics.prototype
  166. * @type {Property|undefined}
  167. * @default false
  168. */
  169. outline: createPropertyDescriptor("outline"),
  170. /**
  171. * Gets or sets the Property specifying the {@link Color} of the outline.
  172. * @memberof EllipsoidGraphics.prototype
  173. * @type {Property|undefined}
  174. * @default Color.BLACK
  175. */
  176. outlineColor: createPropertyDescriptor("outlineColor"),
  177. /**
  178. * Gets or sets the numeric Property specifying the width of the outline.
  179. * <p>
  180. * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.
  181. * </p>
  182. * @memberof EllipsoidGraphics.prototype
  183. * @type {Property|undefined}
  184. * @default 1.0
  185. */
  186. outlineWidth: createPropertyDescriptor("outlineWidth"),
  187. /**
  188. * Gets or sets the Property specifying the number of stacks.
  189. * @memberof EllipsoidGraphics.prototype
  190. * @type {Property|undefined}
  191. * @default 64
  192. */
  193. stackPartitions: createPropertyDescriptor("stackPartitions"),
  194. /**
  195. * Gets or sets the Property specifying the number of radial slices per 360 degrees.
  196. * @memberof EllipsoidGraphics.prototype
  197. * @type {Property|undefined}
  198. * @default 64
  199. */
  200. slicePartitions: createPropertyDescriptor("slicePartitions"),
  201. /**
  202. * Gets or sets the Property specifying the number of samples per outline ring, determining the granularity of the curvature.
  203. * @memberof EllipsoidGraphics.prototype
  204. * @type {Property|undefined}
  205. * @default 128
  206. */
  207. subdivisions: createPropertyDescriptor("subdivisions"),
  208. /**
  209. * Get or sets the enum Property specifying whether the ellipsoid
  210. * casts or receives shadows from light sources.
  211. * @memberof EllipsoidGraphics.prototype
  212. * @type {Property|undefined}
  213. * @default ShadowMode.DISABLED
  214. */
  215. shadows: createPropertyDescriptor("shadows"),
  216. /**
  217. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this ellipsoid will be displayed.
  218. * @memberof EllipsoidGraphics.prototype
  219. * @type {Property|undefined}
  220. */
  221. distanceDisplayCondition: createPropertyDescriptor(
  222. "distanceDisplayCondition"
  223. ),
  224. });
  225. /**
  226. * Duplicates this instance.
  227. *
  228. * @param {EllipsoidGraphics} [result] The object onto which to store the result.
  229. * @returns {EllipsoidGraphics} The modified result parameter or a new instance if one was not provided.
  230. */
  231. EllipsoidGraphics.prototype.clone = function (result) {
  232. if (!defined(result)) {
  233. return new EllipsoidGraphics(this);
  234. }
  235. result.show = this.show;
  236. result.radii = this.radii;
  237. result.innerRadii = this.innerRadii;
  238. result.minimumClock = this.minimumClock;
  239. result.maximumClock = this.maximumClock;
  240. result.minimumCone = this.minimumCone;
  241. result.maximumCone = this.maximumCone;
  242. result.heightReference = this.heightReference;
  243. result.fill = this.fill;
  244. result.material = this.material;
  245. result.outline = this.outline;
  246. result.outlineColor = this.outlineColor;
  247. result.outlineWidth = this.outlineWidth;
  248. result.stackPartitions = this.stackPartitions;
  249. result.slicePartitions = this.slicePartitions;
  250. result.subdivisions = this.subdivisions;
  251. result.shadows = this.shadows;
  252. result.distanceDisplayCondition = this.distanceDisplayCondition;
  253. return result;
  254. };
  255. /**
  256. * Assigns each unassigned property on this object to the value
  257. * of the same property on the provided source object.
  258. *
  259. * @param {EllipsoidGraphics} source The object to be merged into this object.
  260. */
  261. EllipsoidGraphics.prototype.merge = function (source) {
  262. //>>includeStart('debug', pragmas.debug);
  263. if (!defined(source)) {
  264. throw new DeveloperError("source is required.");
  265. }
  266. //>>includeEnd('debug');
  267. this.show = defaultValue(this.show, source.show);
  268. this.radii = defaultValue(this.radii, source.radii);
  269. this.innerRadii = defaultValue(this.innerRadii, source.innerRadii);
  270. this.minimumClock = defaultValue(this.minimumClock, source.minimumClock);
  271. this.maximumClock = defaultValue(this.maximumClock, source.maximumClock);
  272. this.minimumCone = defaultValue(this.minimumCone, source.minimumCone);
  273. this.maximumCone = defaultValue(this.maximumCone, source.maximumCone);
  274. this.heightReference = defaultValue(
  275. this.heightReference,
  276. source.heightReference
  277. );
  278. this.fill = defaultValue(this.fill, source.fill);
  279. this.material = defaultValue(this.material, source.material);
  280. this.outline = defaultValue(this.outline, source.outline);
  281. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  282. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  283. this.stackPartitions = defaultValue(
  284. this.stackPartitions,
  285. source.stackPartitions
  286. );
  287. this.slicePartitions = defaultValue(
  288. this.slicePartitions,
  289. source.slicePartitions
  290. );
  291. this.subdivisions = defaultValue(this.subdivisions, source.subdivisions);
  292. this.shadows = defaultValue(this.shadows, source.shadows);
  293. this.distanceDisplayCondition = defaultValue(
  294. this.distanceDisplayCondition,
  295. source.distanceDisplayCondition
  296. );
  297. };
  298. export default EllipsoidGraphics;