PolylineGraphics.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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} PolylineGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the PolylineGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the polyline.
  13. * @property {Property | Cartesian3[]} [positions] A Property specifying the array of {@link Cartesian3} positions that define the line strip.
  14. * @property {Property | number} [width=1.0] A numeric Property specifying the width in pixels.
  15. * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude if arcType is not ArcType.NONE.
  16. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to draw the polyline.
  17. * @property {MaterialProperty | Color} [depthFailMaterial] A property specifying the material used to draw the polyline when it is below the terrain.
  18. * @property {Property | ArcType} [arcType=ArcType.GEODESIC] The type of line the polyline segments must follow.
  19. * @property {Property | boolean} [clampToGround=false] A boolean Property specifying whether the Polyline should be clamped to the ground.
  20. * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the polyline casts or receives shadows from light sources.
  21. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this polyline will be displayed.
  22. * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this polyline will classify terrain, 3D Tiles, or both when on the ground.
  23. * @property {Property | number} [zIndex=0] A Property specifying the zIndex used for ordering ground geometry. Only has an effect if `clampToGround` is true and polylines on terrain is supported.
  24. */
  25. /**
  26. * Describes a polyline. The first two positions define a line segment,
  27. * and each additional position defines a line segment from the previous position. The segments
  28. * can be linear connected points, great arcs, or clamped to terrain.
  29. *
  30. * @alias PolylineGraphics
  31. * @constructor
  32. *
  33. * @param {PolylineGraphics.ConstructorOptions} [options] Object describing initialization options
  34. *
  35. * @see Entity
  36. * @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline.html|Cesium Sandcastle Polyline Demo}
  37. */
  38. function PolylineGraphics(options) {
  39. this._definitionChanged = new Event();
  40. this._show = undefined;
  41. this._showSubscription = undefined;
  42. this._positions = undefined;
  43. this._positionsSubscription = undefined;
  44. this._width = undefined;
  45. this._widthSubscription = undefined;
  46. this._granularity = undefined;
  47. this._granularitySubscription = undefined;
  48. this._material = undefined;
  49. this._materialSubscription = undefined;
  50. this._depthFailMaterial = undefined;
  51. this._depthFailMaterialSubscription = undefined;
  52. this._arcType = undefined;
  53. this._arcTypeSubscription = undefined;
  54. this._clampToGround = undefined;
  55. this._clampToGroundSubscription = undefined;
  56. this._shadows = undefined;
  57. this._shadowsSubscription = undefined;
  58. this._distanceDisplayCondition = undefined;
  59. this._distanceDisplayConditionSubscription = undefined;
  60. this._classificationType = undefined;
  61. this._classificationTypeSubscription = undefined;
  62. this._zIndex = undefined;
  63. this._zIndexSubscription = undefined;
  64. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  65. }
  66. Object.defineProperties(PolylineGraphics.prototype, {
  67. /**
  68. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  69. * @memberof PolylineGraphics.prototype
  70. *
  71. * @type {Event}
  72. * @readonly
  73. */
  74. definitionChanged: {
  75. get: function () {
  76. return this._definitionChanged;
  77. },
  78. },
  79. /**
  80. * Gets or sets the boolean Property specifying the visibility of the polyline.
  81. * @memberof PolylineGraphics.prototype
  82. * @type {Property|undefined}
  83. * @default true
  84. */
  85. show: createPropertyDescriptor("show"),
  86. /**
  87. * Gets or sets the Property specifying the array of {@link Cartesian3}
  88. * positions that define the line strip.
  89. * @memberof PolylineGraphics.prototype
  90. * @type {Property|undefined}
  91. */
  92. positions: createPropertyDescriptor("positions"),
  93. /**
  94. * Gets or sets the numeric Property specifying the width in pixels.
  95. * @memberof PolylineGraphics.prototype
  96. * @type {Property|undefined}
  97. * @default 1.0
  98. */
  99. width: createPropertyDescriptor("width"),
  100. /**
  101. * Gets or sets the numeric Property specifying the angular distance between each latitude and longitude if arcType is not ArcType.NONE and clampToGround is false.
  102. * @memberof PolylineGraphics.prototype
  103. * @type {Property|undefined}
  104. * @default Cesium.Math.RADIANS_PER_DEGREE
  105. */
  106. granularity: createPropertyDescriptor("granularity"),
  107. /**
  108. * Gets or sets the Property specifying the material used to draw the polyline.
  109. * @memberof PolylineGraphics.prototype
  110. * @type {MaterialProperty}
  111. * @default Color.WHITE
  112. */
  113. material: createMaterialPropertyDescriptor("material"),
  114. /**
  115. * Gets or sets the Property specifying the material used to draw the polyline when it fails the depth test.
  116. * <p>
  117. * Requires the EXT_frag_depth WebGL extension to render properly. If the extension is not supported,
  118. * there may be artifacts.
  119. * </p>
  120. * @memberof PolylineGraphics.prototype
  121. * @type {MaterialProperty}
  122. * @default undefined
  123. */
  124. depthFailMaterial: createMaterialPropertyDescriptor("depthFailMaterial"),
  125. /**
  126. * Gets or sets the {@link ArcType} Property specifying whether the line segments should be great arcs, rhumb lines or linearly connected.
  127. * @memberof PolylineGraphics.prototype
  128. * @type {Property|undefined}
  129. * @default ArcType.GEODESIC
  130. */
  131. arcType: createPropertyDescriptor("arcType"),
  132. /**
  133. * Gets or sets the boolean Property specifying whether the polyline
  134. * should be clamped to the ground.
  135. * @memberof PolylineGraphics.prototype
  136. * @type {Property|undefined}
  137. * @default false
  138. */
  139. clampToGround: createPropertyDescriptor("clampToGround"),
  140. /**
  141. * Get or sets the enum Property specifying whether the polyline
  142. * casts or receives shadows from light sources.
  143. * @memberof PolylineGraphics.prototype
  144. * @type {Property|undefined}
  145. * @default ShadowMode.DISABLED
  146. */
  147. shadows: createPropertyDescriptor("shadows"),
  148. /**
  149. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this polyline will be displayed.
  150. * @memberof PolylineGraphics.prototype
  151. * @type {Property|undefined}
  152. */
  153. distanceDisplayCondition: createPropertyDescriptor(
  154. "distanceDisplayCondition"
  155. ),
  156. /**
  157. * Gets or sets the {@link ClassificationType} Property specifying whether this polyline will classify terrain, 3D Tiles, or both when on the ground.
  158. * @memberof PolylineGraphics.prototype
  159. * @type {Property|undefined}
  160. * @default ClassificationType.BOTH
  161. */
  162. classificationType: createPropertyDescriptor("classificationType"),
  163. /**
  164. * Gets or sets the zIndex Property specifying the ordering of the polyline. Only has an effect if `clampToGround` is true and polylines on terrain is supported.
  165. * @memberof PolylineGraphics.prototype
  166. * @type {ConstantProperty|undefined}
  167. * @default 0
  168. */
  169. zIndex: createPropertyDescriptor("zIndex"),
  170. });
  171. /**
  172. * Duplicates this instance.
  173. *
  174. * @param {PolylineGraphics} [result] The object onto which to store the result.
  175. * @returns {PolylineGraphics} The modified result parameter or a new instance if one was not provided.
  176. */
  177. PolylineGraphics.prototype.clone = function (result) {
  178. if (!defined(result)) {
  179. return new PolylineGraphics(this);
  180. }
  181. result.show = this.show;
  182. result.positions = this.positions;
  183. result.width = this.width;
  184. result.granularity = this.granularity;
  185. result.material = this.material;
  186. result.depthFailMaterial = this.depthFailMaterial;
  187. result.arcType = this.arcType;
  188. result.clampToGround = this.clampToGround;
  189. result.shadows = this.shadows;
  190. result.distanceDisplayCondition = this.distanceDisplayCondition;
  191. result.classificationType = this.classificationType;
  192. result.zIndex = this.zIndex;
  193. return result;
  194. };
  195. /**
  196. * Assigns each unassigned property on this object to the value
  197. * of the same property on the provided source object.
  198. *
  199. * @param {PolylineGraphics} source The object to be merged into this object.
  200. */
  201. PolylineGraphics.prototype.merge = function (source) {
  202. //>>includeStart('debug', pragmas.debug);
  203. if (!defined(source)) {
  204. throw new DeveloperError("source is required.");
  205. }
  206. //>>includeEnd('debug');
  207. this.show = defaultValue(this.show, source.show);
  208. this.positions = defaultValue(this.positions, source.positions);
  209. this.width = defaultValue(this.width, source.width);
  210. this.granularity = defaultValue(this.granularity, source.granularity);
  211. this.material = defaultValue(this.material, source.material);
  212. this.depthFailMaterial = defaultValue(
  213. this.depthFailMaterial,
  214. source.depthFailMaterial
  215. );
  216. this.arcType = defaultValue(this.arcType, source.arcType);
  217. this.clampToGround = defaultValue(this.clampToGround, source.clampToGround);
  218. this.shadows = defaultValue(this.shadows, source.shadows);
  219. this.distanceDisplayCondition = defaultValue(
  220. this.distanceDisplayCondition,
  221. source.distanceDisplayCondition
  222. );
  223. this.classificationType = defaultValue(
  224. this.classificationType,
  225. source.classificationType
  226. );
  227. this.zIndex = defaultValue(this.zIndex, source.zIndex);
  228. };
  229. export default PolylineGraphics;