EllipseGraphics.js 15 KB

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