PolylineGraphics.js 11 KB

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