RectangleGraphics.js 13 KB

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