CorridorGraphics.js 14 KB

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