CorridorGraphics.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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} CorridorGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the CorridorGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the corridor.
  13. * @property {Property | Cartesian3[]} [positions] A Property specifying the array of {@link Cartesian3} positions that define the centerline of the corridor.
  14. * @property {Property | number} [width] A numeric Property specifying the distance between the edges of the corridor.
  15. * @property {Property | number} [height=0] A numeric Property specifying the altitude of the corridor 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 corridor'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 | CornerType} [cornerType=CornerType.ROUNDED] A {@link CornerType} Property specifying the style of the corners.
  20. * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the distance between each latitude and longitude.
  21. * @property {Property | boolean} [fill=true] A boolean Property specifying whether the corridor is filled with the provided material.
  22. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the corridor.
  23. * @property {Property | boolean} [outline=false] A boolean Property specifying whether the corridor 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 corridor casts or receives shadows from light sources.
  27. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this corridor will be displayed.
  28. * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this corridor will classify terrain, 3D Tiles, or both when on the ground.
  29. * @property {ConstantProperty | number} [zIndex] A Property specifying the zIndex of the corridor, used for ordering. Only has an effect if height and extrudedHeight are undefined, and if the corridor is static.
  30. */
  31. /**
  32. * Describes a corridor, which is a shape defined by a centerline and width that
  33. * conforms to the curvature of the globe. It can be placed on the surface or at altitude
  34. * and can optionally be extruded into a volume.
  35. *
  36. * @alias CorridorGraphics
  37. * @constructor
  38. *
  39. * @param {CorridorGraphics.ConstructorOptions} [options] Object describing initialization options
  40. *
  41. * @see Entity
  42. * @demo {@link https://sandcastle.cesium.com/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}
  43. */
  44. function CorridorGraphics(options) {
  45. this._definitionChanged = new Event();
  46. this._show = undefined;
  47. this._showSubscription = undefined;
  48. this._positions = undefined;
  49. this._positionsSubscription = undefined;
  50. this._width = undefined;
  51. this._widthSubscription = undefined;
  52. this._height = undefined;
  53. this._heightSubscription = undefined;
  54. this._heightReference = undefined;
  55. this._heightReferenceSubscription = undefined;
  56. this._extrudedHeight = undefined;
  57. this._extrudedHeightSubscription = undefined;
  58. this._extrudedHeightReference = undefined;
  59. this._extrudedHeightReferenceSubscription = undefined;
  60. this._cornerType = undefined;
  61. this._cornerTypeSubscription = 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(CorridorGraphics.prototype, {
  85. /**
  86. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  87. * @memberof CorridorGraphics.prototype
  88. * @type {Event}
  89. * @readonly
  90. */
  91. definitionChanged: {
  92. get: function () {
  93. return this._definitionChanged;
  94. },
  95. },
  96. /**
  97. * Gets or sets the boolean Property specifying the visibility of the corridor.
  98. * @memberof CorridorGraphics.prototype
  99. * @type {Property|undefined}
  100. * @default true
  101. */
  102. show: createPropertyDescriptor("show"),
  103. /**
  104. * Gets or sets a Property specifying the array of {@link Cartesian3} positions that define the centerline of the corridor.
  105. * @memberof CorridorGraphics.prototype
  106. * @type {Property|undefined}
  107. */
  108. positions: createPropertyDescriptor("positions"),
  109. /**
  110. * Gets or sets the numeric Property specifying the width of the outline.
  111. * @memberof CorridorGraphics.prototype
  112. * @type {Property|undefined}
  113. */
  114. width: createPropertyDescriptor("width"),
  115. /**
  116. * Gets or sets the numeric Property specifying the altitude of the corridor.
  117. * @memberof CorridorGraphics.prototype
  118. * @type {Property|undefined}
  119. * @default 0.0
  120. */
  121. height: createPropertyDescriptor("height"),
  122. /**
  123. * Gets or sets the Property specifying the {@link HeightReference}.
  124. * @memberof CorridorGraphics.prototype
  125. * @type {Property|undefined}
  126. * @default HeightReference.NONE
  127. */
  128. heightReference: createPropertyDescriptor("heightReference"),
  129. /**
  130. * Gets or sets the numeric Property specifying the altitude of the corridor extrusion.
  131. * Setting this property creates a corridor shaped volume starting at height and ending
  132. * at this altitude.
  133. * @memberof CorridorGraphics.prototype
  134. * @type {Property|undefined}
  135. */
  136. extrudedHeight: createPropertyDescriptor("extrudedHeight"),
  137. /**
  138. * Gets or sets the Property specifying the extruded {@link HeightReference}.
  139. * @memberof CorridorGraphics.prototype
  140. * @type {Property|undefined}
  141. * @default HeightReference.NONE
  142. */
  143. extrudedHeightReference: createPropertyDescriptor("extrudedHeightReference"),
  144. /**
  145. * Gets or sets the {@link CornerType} Property specifying how corners are styled.
  146. * @memberof CorridorGraphics.prototype
  147. * @type {Property|undefined}
  148. * @default CornerType.ROUNDED
  149. */
  150. cornerType: createPropertyDescriptor("cornerType"),
  151. /**
  152. * Gets or sets the numeric Property specifying the sampling distance between each latitude and longitude point.
  153. * @memberof CorridorGraphics.prototype
  154. * @type {Property|undefined}
  155. * @default {CesiumMath.RADIANS_PER_DEGREE}
  156. */
  157. granularity: createPropertyDescriptor("granularity"),
  158. /**
  159. * Gets or sets the boolean Property specifying whether the corridor is filled with the provided material.
  160. * @memberof CorridorGraphics.prototype
  161. * @type {Property|undefined}
  162. * @default true
  163. */
  164. fill: createPropertyDescriptor("fill"),
  165. /**
  166. * Gets or sets the Property specifying the material used to fill the corridor.
  167. * @memberof CorridorGraphics.prototype
  168. * @type {MaterialProperty|undefined}
  169. * @default Color.WHITE
  170. */
  171. material: createMaterialPropertyDescriptor("material"),
  172. /**
  173. * Gets or sets the Property specifying whether the corridor is outlined.
  174. * @memberof CorridorGraphics.prototype
  175. * @type {Property|undefined}
  176. * @default false
  177. */
  178. outline: createPropertyDescriptor("outline"),
  179. /**
  180. * Gets or sets the Property specifying the {@link Color} of the outline.
  181. * @memberof CorridorGraphics.prototype
  182. * @type {Property|undefined}
  183. * @default Color.BLACK
  184. */
  185. outlineColor: createPropertyDescriptor("outlineColor"),
  186. /**
  187. * Gets or sets the numeric Property specifying the width of the outline.
  188. * <p>
  189. * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.
  190. * </p>
  191. * @memberof CorridorGraphics.prototype
  192. * @type {Property|undefined}
  193. * @default 1.0
  194. */
  195. outlineWidth: createPropertyDescriptor("outlineWidth"),
  196. /**
  197. * Get or sets the enum Property specifying whether the corridor
  198. * casts or receives shadows from light sources.
  199. * @memberof CorridorGraphics.prototype
  200. * @type {Property|undefined}
  201. * @default ShadowMode.DISABLED
  202. */
  203. shadows: createPropertyDescriptor("shadows"),
  204. /**
  205. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this corridor will be displayed.
  206. * @memberof CorridorGraphics.prototype
  207. * @type {Property|undefined}
  208. */
  209. distanceDisplayCondition: createPropertyDescriptor(
  210. "distanceDisplayCondition"
  211. ),
  212. /**
  213. * Gets or sets the {@link ClassificationType} Property specifying whether this corridor will classify terrain, 3D Tiles, or both when on the ground.
  214. * @memberof CorridorGraphics.prototype
  215. * @type {Property|undefined}
  216. * @default ClassificationType.BOTH
  217. */
  218. classificationType: createPropertyDescriptor("classificationType"),
  219. /**
  220. * Gets or sets the zIndex Property specifying the ordering of the corridor. Only has an effect if the coridor is static and neither height or exturdedHeight are specified.
  221. * @memberof CorridorGraphics.prototype
  222. * @type {ConstantProperty|undefined}
  223. * @default 0
  224. */
  225. zIndex: createPropertyDescriptor("zIndex"),
  226. });
  227. /**
  228. * Duplicates this instance.
  229. *
  230. * @param {CorridorGraphics} [result] The object onto which to store the result.
  231. * @returns {CorridorGraphics} The modified result parameter or a new instance if one was not provided.
  232. */
  233. CorridorGraphics.prototype.clone = function (result) {
  234. if (!defined(result)) {
  235. return new CorridorGraphics(this);
  236. }
  237. result.show = this.show;
  238. result.positions = this.positions;
  239. result.width = this.width;
  240. result.height = this.height;
  241. result.heightReference = this.heightReference;
  242. result.extrudedHeight = this.extrudedHeight;
  243. result.extrudedHeightReference = this.extrudedHeightReference;
  244. result.cornerType = this.cornerType;
  245. result.granularity = this.granularity;
  246. result.fill = this.fill;
  247. result.material = this.material;
  248. result.outline = this.outline;
  249. result.outlineColor = this.outlineColor;
  250. result.outlineWidth = this.outlineWidth;
  251. result.shadows = this.shadows;
  252. result.distanceDisplayCondition = this.distanceDisplayCondition;
  253. result.classificationType = this.classificationType;
  254. result.zIndex = this.zIndex;
  255. return result;
  256. };
  257. /**
  258. * Assigns each unassigned property on this object to the value
  259. * of the same property on the provided source object.
  260. *
  261. * @param {CorridorGraphics} source The object to be merged into this object.
  262. */
  263. CorridorGraphics.prototype.merge = function (source) {
  264. //>>includeStart('debug', pragmas.debug);
  265. if (!defined(source)) {
  266. throw new DeveloperError("source is required.");
  267. }
  268. //>>includeEnd('debug');
  269. this.show = defaultValue(this.show, source.show);
  270. this.positions = defaultValue(this.positions, source.positions);
  271. this.width = defaultValue(this.width, source.width);
  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.cornerType = defaultValue(this.cornerType, source.cornerType);
  286. this.granularity = defaultValue(this.granularity, source.granularity);
  287. this.fill = defaultValue(this.fill, source.fill);
  288. this.material = defaultValue(this.material, source.material);
  289. this.outline = defaultValue(this.outline, source.outline);
  290. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  291. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  292. this.shadows = defaultValue(this.shadows, source.shadows);
  293. this.distanceDisplayCondition = defaultValue(
  294. this.distanceDisplayCondition,
  295. source.distanceDisplayCondition
  296. );
  297. this.classificationType = defaultValue(
  298. this.classificationType,
  299. source.classificationType
  300. );
  301. this.zIndex = defaultValue(this.zIndex, source.zIndex);
  302. };
  303. export default CorridorGraphics;