RectangleGraphics.js 14 KB

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