EllipseGraphics.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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} EllipseGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the EllipseGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the ellipse.
  13. * @property {Property | number} [semiMajorAxis] The numeric Property specifying the semi-major axis.
  14. * @property {Property | number} [semiMinorAxis] The numeric Property specifying the semi-minor axis.
  15. * @property {Property | number} [height=0] A numeric Property specifying the altitude of the ellipse relative to the ellipsoid surface.
  16. * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.
  17. * @property {Property | number} [extrudedHeight] A numeric Property specifying the altitude of the ellipse's extruded face relative to the ellipsoid surface.
  18. * @property {Property | HeightReference} [extrudedHeightReference=HeightReference.NONE] A Property specifying what the extrudedHeight is relative to.
  19. * @property {Property | number} [rotation=0.0] A numeric property specifying the rotation of the ellipse counter-clockwise from north.
  20. * @property {Property | number} [stRotation=0.0] A numeric property specifying the rotation of the ellipse texture counter-clockwise from north.
  21. * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between points on the ellipse.
  22. * @property {Property | boolean} [fill=true] A boolean Property specifying whether the ellipse is filled with the provided material.
  23. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the ellipse.
  24. * @property {Property | boolean} [outline=false] A boolean Property specifying whether the ellipse is outlined.
  25. * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  26. * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.
  27. * @property {Property | number} [numberOfVerticalLines=16] A numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.
  28. * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the ellipse casts or receives shadows from light sources.
  29. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this ellipse will be displayed.
  30. * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this ellipse will classify terrain, 3D Tiles, or both when on the ground.
  31. * @property {ConstantProperty | number} [zIndex=0] A property specifying the zIndex of the Ellipse. Used for ordering ground geometry. Only has an effect if the ellipse is constant and neither height or exturdedHeight are specified.
  32. */
  33. /**
  34. * Describes an ellipse defined by a center point and semi-major and semi-minor axes.
  35. * The ellipse conforms to the curvature of the globe and can be placed on the surface or
  36. * at altitude and can optionally be extruded into a volume.
  37. * The center point is determined by the containing {@link Entity}.
  38. *
  39. * @alias EllipseGraphics
  40. * @constructor
  41. *
  42. * @param {EllipseGraphics.ConstructorOptions} [options] Object describing initialization options
  43. *
  44. * @demo {@link https://sandcastle.cesium.com/index.html?src=Circles and Ellipses.html|Cesium Sandcastle Circles and Ellipses Demo}
  45. */
  46. function EllipseGraphics(options) {
  47. this._definitionChanged = new Event();
  48. this._show = undefined;
  49. this._showSubscription = undefined;
  50. this._semiMajorAxis = undefined;
  51. this._semiMajorAxisSubscription = undefined;
  52. this._semiMinorAxis = undefined;
  53. this._semiMinorAxisSubscription = undefined;
  54. this._height = undefined;
  55. this._heightSubscription = undefined;
  56. this._heightReference = undefined;
  57. this._heightReferenceSubscription = undefined;
  58. this._extrudedHeight = undefined;
  59. this._extrudedHeightSubscription = undefined;
  60. this._extrudedHeightReference = undefined;
  61. this._extrudedHeightReferenceSubscription = undefined;
  62. this._rotation = undefined;
  63. this._rotationSubscription = undefined;
  64. this._stRotation = undefined;
  65. this._stRotationSubscription = undefined;
  66. this._granularity = undefined;
  67. this._granularitySubscription = undefined;
  68. this._fill = undefined;
  69. this._fillSubscription = undefined;
  70. this._material = undefined;
  71. this._materialSubscription = undefined;
  72. this._outline = undefined;
  73. this._outlineSubscription = undefined;
  74. this._outlineColor = undefined;
  75. this._outlineColorSubscription = undefined;
  76. this._outlineWidth = undefined;
  77. this._outlineWidthSubscription = undefined;
  78. this._numberOfVerticalLines = undefined;
  79. this._numberOfVerticalLinesSubscription = undefined;
  80. this._shadows = undefined;
  81. this._shadowsSubscription = undefined;
  82. this._distanceDisplayCondition = undefined;
  83. this._distanceDisplayConditionSubscription = undefined;
  84. this._classificationType = undefined;
  85. this._classificationTypeSubscription = undefined;
  86. this._zIndex = undefined;
  87. this._zIndexSubscription = undefined;
  88. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  89. }
  90. Object.defineProperties(EllipseGraphics.prototype, {
  91. /**
  92. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  93. * @memberof EllipseGraphics.prototype
  94. *
  95. * @type {Event}
  96. * @readonly
  97. */
  98. definitionChanged: {
  99. get: function () {
  100. return this._definitionChanged;
  101. },
  102. },
  103. /**
  104. * Gets or sets the boolean Property specifying the visibility of the ellipse.
  105. * @memberof EllipseGraphics.prototype
  106. * @type {Property|undefined}
  107. * @default true
  108. */
  109. show: createPropertyDescriptor("show"),
  110. /**
  111. * Gets or sets the numeric Property specifying the semi-major axis.
  112. * @memberof EllipseGraphics.prototype
  113. * @type {Property|undefined}
  114. */
  115. semiMajorAxis: createPropertyDescriptor("semiMajorAxis"),
  116. /**
  117. * Gets or sets the numeric Property specifying the semi-minor axis.
  118. * @memberof EllipseGraphics.prototype
  119. * @type {Property|undefined}
  120. */
  121. semiMinorAxis: createPropertyDescriptor("semiMinorAxis"),
  122. /**
  123. * Gets or sets the numeric Property specifying the altitude of the ellipse.
  124. * @memberof EllipseGraphics.prototype
  125. * @type {Property|undefined}
  126. * @default 0.0
  127. */
  128. height: createPropertyDescriptor("height"),
  129. /**
  130. * Gets or sets the Property specifying the {@link HeightReference}.
  131. * @memberof EllipseGraphics.prototype
  132. * @type {Property|undefined}
  133. * @default HeightReference.NONE
  134. */
  135. heightReference: createPropertyDescriptor("heightReference"),
  136. /**
  137. * Gets or sets the numeric Property specifying the altitude of the ellipse extrusion.
  138. * Setting this property creates volume starting at height and ending at this altitude.
  139. * @memberof EllipseGraphics.prototype
  140. * @type {Property|undefined}
  141. */
  142. extrudedHeight: createPropertyDescriptor("extrudedHeight"),
  143. /**
  144. * Gets or sets the Property specifying the extruded {@link HeightReference}.
  145. * @memberof EllipseGraphics.prototype
  146. * @type {Property|undefined}
  147. * @default HeightReference.NONE
  148. */
  149. extrudedHeightReference: createPropertyDescriptor("extrudedHeightReference"),
  150. /**
  151. * Gets or sets the numeric property specifying the rotation of the ellipse counter-clockwise from north.
  152. * @memberof EllipseGraphics.prototype
  153. * @type {Property|undefined}
  154. * @default 0
  155. */
  156. rotation: createPropertyDescriptor("rotation"),
  157. /**
  158. * Gets or sets the numeric property specifying the rotation of the ellipse texture counter-clockwise from north.
  159. * @memberof EllipseGraphics.prototype
  160. * @type {Property|undefined}
  161. * @default 0
  162. */
  163. stRotation: createPropertyDescriptor("stRotation"),
  164. /**
  165. * Gets or sets the numeric Property specifying the angular distance between points on the ellipse.
  166. * @memberof EllipseGraphics.prototype
  167. * @type {Property|undefined}
  168. * @default {CesiumMath.RADIANS_PER_DEGREE}
  169. */
  170. granularity: createPropertyDescriptor("granularity"),
  171. /**
  172. * Gets or sets the boolean Property specifying whether the ellipse is filled with the provided material.
  173. * @memberof EllipseGraphics.prototype
  174. * @type {Property|undefined}
  175. * @default true
  176. */
  177. fill: createPropertyDescriptor("fill"),
  178. /**
  179. * Gets or sets the Property specifying the material used to fill the ellipse.
  180. * @memberof EllipseGraphics.prototype
  181. * @type {MaterialProperty|undefined}
  182. * @default Color.WHITE
  183. */
  184. material: createMaterialPropertyDescriptor("material"),
  185. /**
  186. * Gets or sets the Property specifying whether the ellipse is outlined.
  187. * @memberof EllipseGraphics.prototype
  188. * @type {Property|undefined}
  189. * @default false
  190. */
  191. outline: createPropertyDescriptor("outline"),
  192. /**
  193. * Gets or sets the Property specifying the {@link Color} of the outline.
  194. * @memberof EllipseGraphics.prototype
  195. * @type {Property|undefined}
  196. * @default Color.BLACK
  197. */
  198. outlineColor: createPropertyDescriptor("outlineColor"),
  199. /**
  200. * Gets or sets the numeric Property specifying the width of the outline.
  201. * <p>
  202. * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.
  203. * </p>
  204. * @memberof EllipseGraphics.prototype
  205. * @type {Property|undefined}
  206. * @default 1.0
  207. */
  208. outlineWidth: createPropertyDescriptor("outlineWidth"),
  209. /**
  210. * Gets or sets the numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.
  211. * @memberof EllipseGraphics.prototype
  212. * @type {Property|undefined}
  213. * @default 16
  214. */
  215. numberOfVerticalLines: createPropertyDescriptor("numberOfVerticalLines"),
  216. /**
  217. * Get or sets the enum Property specifying whether the ellipse
  218. * casts or receives shadows from light sources.
  219. * @memberof EllipseGraphics.prototype
  220. * @type {Property|undefined}
  221. * @default ShadowMode.DISABLED
  222. */
  223. shadows: createPropertyDescriptor("shadows"),
  224. /**
  225. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this ellipse will be displayed.
  226. * @memberof EllipseGraphics.prototype
  227. * @type {Property|undefined}
  228. */
  229. distanceDisplayCondition: createPropertyDescriptor(
  230. "distanceDisplayCondition"
  231. ),
  232. /**
  233. * Gets or sets the {@link ClassificationType} Property specifying whether this ellipse will classify terrain, 3D Tiles, or both when on the ground.
  234. * @memberof EllipseGraphics.prototype
  235. * @type {Property|undefined}
  236. * @default ClassificationType.BOTH
  237. */
  238. classificationType: createPropertyDescriptor("classificationType"),
  239. /**
  240. * Gets or sets the zIndex Property specifying the ellipse ordering. Only has an effect if the ellipse is constant and neither height or extrudedHeight are specified
  241. * @memberof EllipseGraphics.prototype
  242. * @type {ConstantProperty|undefined}
  243. * @default 0
  244. */
  245. zIndex: createPropertyDescriptor("zIndex"),
  246. });
  247. /**
  248. * Duplicates this instance.
  249. *
  250. * @param {EllipseGraphics} [result] The object onto which to store the result.
  251. * @returns {EllipseGraphics} The modified result parameter or a new instance if one was not provided.
  252. */
  253. EllipseGraphics.prototype.clone = function (result) {
  254. if (!defined(result)) {
  255. return new EllipseGraphics(this);
  256. }
  257. result.show = this.show;
  258. result.semiMajorAxis = this.semiMajorAxis;
  259. result.semiMinorAxis = this.semiMinorAxis;
  260. result.height = this.height;
  261. result.heightReference = this.heightReference;
  262. result.extrudedHeight = this.extrudedHeight;
  263. result.extrudedHeightReference = this.extrudedHeightReference;
  264. result.rotation = this.rotation;
  265. result.stRotation = this.stRotation;
  266. result.granularity = this.granularity;
  267. result.fill = this.fill;
  268. result.material = this.material;
  269. result.outline = this.outline;
  270. result.outlineColor = this.outlineColor;
  271. result.outlineWidth = this.outlineWidth;
  272. result.numberOfVerticalLines = this.numberOfVerticalLines;
  273. result.shadows = this.shadows;
  274. result.distanceDisplayCondition = this.distanceDisplayCondition;
  275. result.classificationType = this.classificationType;
  276. result.zIndex = this.zIndex;
  277. return result;
  278. };
  279. /**
  280. * Assigns each unassigned property on this object to the value
  281. * of the same property on the provided source object.
  282. *
  283. * @param {EllipseGraphics} source The object to be merged into this object.
  284. */
  285. EllipseGraphics.prototype.merge = function (source) {
  286. //>>includeStart('debug', pragmas.debug);
  287. if (!defined(source)) {
  288. throw new DeveloperError("source is required.");
  289. }
  290. //>>includeEnd('debug');
  291. this.show = defaultValue(this.show, source.show);
  292. this.semiMajorAxis = defaultValue(this.semiMajorAxis, source.semiMajorAxis);
  293. this.semiMinorAxis = defaultValue(this.semiMinorAxis, source.semiMinorAxis);
  294. this.height = defaultValue(this.height, source.height);
  295. this.heightReference = defaultValue(
  296. this.heightReference,
  297. source.heightReference
  298. );
  299. this.extrudedHeight = defaultValue(
  300. this.extrudedHeight,
  301. source.extrudedHeight
  302. );
  303. this.extrudedHeightReference = defaultValue(
  304. this.extrudedHeightReference,
  305. source.extrudedHeightReference
  306. );
  307. this.rotation = defaultValue(this.rotation, source.rotation);
  308. this.stRotation = defaultValue(this.stRotation, source.stRotation);
  309. this.granularity = defaultValue(this.granularity, source.granularity);
  310. this.fill = defaultValue(this.fill, source.fill);
  311. this.material = defaultValue(this.material, source.material);
  312. this.outline = defaultValue(this.outline, source.outline);
  313. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  314. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  315. this.numberOfVerticalLines = defaultValue(
  316. this.numberOfVerticalLines,
  317. source.numberOfVerticalLines
  318. );
  319. this.shadows = defaultValue(this.shadows, source.shadows);
  320. this.distanceDisplayCondition = defaultValue(
  321. this.distanceDisplayCondition,
  322. source.distanceDisplayCondition
  323. );
  324. this.classificationType = defaultValue(
  325. this.classificationType,
  326. source.classificationType
  327. );
  328. this.zIndex = defaultValue(this.zIndex, source.zIndex);
  329. };
  330. export default EllipseGraphics;