PointGraphics.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 createPropertyDescriptor from "./createPropertyDescriptor.js";
  6. /**
  7. * @typedef {object} PointGraphics.ConstructorOptions
  8. *
  9. * Initialization options for the PointGraphics constructor
  10. *
  11. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the point.
  12. * @property {Property | number} [pixelSize=1] A numeric Property specifying the size in pixels.
  13. * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.
  14. * @property {Property | Color} [color=Color.WHITE] A Property specifying the {@link Color} of the point.
  15. * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  16. * @property {Property | number} [outlineWidth=0] A numeric Property specifying the the outline width in pixels.
  17. * @property {Property | NearFarScalar} [scaleByDistance] A {@link NearFarScalar} Property used to scale the point based on distance.
  18. * @property {Property | NearFarScalar} [translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera.
  19. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this point will be displayed.
  20. * @property {Property | number} [disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to.
  21. */
  22. /**
  23. * Describes a graphical point located at the position of the containing {@link Entity}.
  24. *
  25. * @alias PointGraphics
  26. * @constructor
  27. *
  28. * @param {PointGraphics.ConstructorOptions} [options] Object describing initialization options
  29. */
  30. function PointGraphics(options) {
  31. this._definitionChanged = new Event();
  32. this._show = undefined;
  33. this._showSubscription = undefined;
  34. this._pixelSize = undefined;
  35. this._pixelSizeSubscription = undefined;
  36. this._heightReference = undefined;
  37. this._heightReferenceSubscription = undefined;
  38. this._color = undefined;
  39. this._colorSubscription = undefined;
  40. this._outlineColor = undefined;
  41. this._outlineColorSubscription = undefined;
  42. this._outlineWidth = undefined;
  43. this._outlineWidthSubscription = undefined;
  44. this._scaleByDistance = undefined;
  45. this._scaleByDistanceSubscription = undefined;
  46. this._translucencyByDistance = undefined;
  47. this._translucencyByDistanceSubscription = undefined;
  48. this._distanceDisplayCondition = undefined;
  49. this._distanceDisplayConditionSubscription = undefined;
  50. this._disableDepthTestDistance = undefined;
  51. this._disableDepthTestDistanceSubscription = undefined;
  52. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  53. }
  54. Object.defineProperties(PointGraphics.prototype, {
  55. /**
  56. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  57. * @memberof PointGraphics.prototype
  58. *
  59. * @type {Event}
  60. * @readonly
  61. */
  62. definitionChanged: {
  63. get: function () {
  64. return this._definitionChanged;
  65. },
  66. },
  67. /**
  68. * Gets or sets the boolean Property specifying the visibility of the point.
  69. * @memberof PointGraphics.prototype
  70. * @type {Property|undefined}
  71. * @default true
  72. */
  73. show: createPropertyDescriptor("show"),
  74. /**
  75. * Gets or sets the numeric Property specifying the size in pixels.
  76. * @memberof PointGraphics.prototype
  77. * @type {Property|undefined}
  78. * @default 1
  79. */
  80. pixelSize: createPropertyDescriptor("pixelSize"),
  81. /**
  82. * Gets or sets the Property specifying the {@link HeightReference}.
  83. * @memberof PointGraphics.prototype
  84. * @type {Property|undefined}
  85. * @default HeightReference.NONE
  86. */
  87. heightReference: createPropertyDescriptor("heightReference"),
  88. /**
  89. * Gets or sets the Property specifying the {@link Color} of the point.
  90. * @memberof PointGraphics.prototype
  91. * @type {Property|undefined}
  92. * @default Color.WHITE
  93. */
  94. color: createPropertyDescriptor("color"),
  95. /**
  96. * Gets or sets the Property specifying the {@link Color} of the outline.
  97. * @memberof PointGraphics.prototype
  98. * @type {Property|undefined}
  99. * @default Color.BLACK
  100. */
  101. outlineColor: createPropertyDescriptor("outlineColor"),
  102. /**
  103. * Gets or sets the numeric Property specifying the the outline width in pixels.
  104. * @memberof PointGraphics.prototype
  105. * @type {Property|undefined}
  106. * @default 0
  107. */
  108. outlineWidth: createPropertyDescriptor("outlineWidth"),
  109. /**
  110. * Gets or sets the {@link NearFarScalar} Property used to scale the point based on distance.
  111. * If undefined, a constant size is used.
  112. * @memberof PointGraphics.prototype
  113. * @type {Property|undefined}
  114. */
  115. scaleByDistance: createPropertyDescriptor("scaleByDistance"),
  116. /**
  117. * Gets or sets {@link NearFarScalar} Property specifying the translucency of the point based on the distance from the camera.
  118. * A point's translucency will interpolate between the {@link NearFarScalar#nearValue} and
  119. * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds
  120. * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
  121. * Outside of these ranges the points's translucency remains clamped to the nearest bound.
  122. * @memberof PointGraphics.prototype
  123. * @type {Property|undefined}
  124. */
  125. translucencyByDistance: createPropertyDescriptor("translucencyByDistance"),
  126. /**
  127. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this point will be displayed.
  128. * @memberof PointGraphics.prototype
  129. * @type {Property|undefined}
  130. */
  131. distanceDisplayCondition: createPropertyDescriptor(
  132. "distanceDisplayCondition"
  133. ),
  134. /**
  135. * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
  136. * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
  137. * @memberof PointGraphics.prototype
  138. * @type {Property|undefined}
  139. */
  140. disableDepthTestDistance: createPropertyDescriptor(
  141. "disableDepthTestDistance"
  142. ),
  143. });
  144. /**
  145. * Duplicates this instance.
  146. *
  147. * @param {PointGraphics} [result] The object onto which to store the result.
  148. * @returns {PointGraphics} The modified result parameter or a new instance if one was not provided.
  149. */
  150. PointGraphics.prototype.clone = function (result) {
  151. if (!defined(result)) {
  152. return new PointGraphics(this);
  153. }
  154. result.show = this.show;
  155. result.pixelSize = this.pixelSize;
  156. result.heightReference = this.heightReference;
  157. result.color = this.color;
  158. result.outlineColor = this.outlineColor;
  159. result.outlineWidth = this.outlineWidth;
  160. result.scaleByDistance = this.scaleByDistance;
  161. result.translucencyByDistance = this._translucencyByDistance;
  162. result.distanceDisplayCondition = this.distanceDisplayCondition;
  163. result.disableDepthTestDistance = this.disableDepthTestDistance;
  164. return result;
  165. };
  166. /**
  167. * Assigns each unassigned property on this object to the value
  168. * of the same property on the provided source object.
  169. *
  170. * @param {PointGraphics} source The object to be merged into this object.
  171. */
  172. PointGraphics.prototype.merge = function (source) {
  173. //>>includeStart('debug', pragmas.debug);
  174. if (!defined(source)) {
  175. throw new DeveloperError("source is required.");
  176. }
  177. //>>includeEnd('debug');
  178. this.show = defaultValue(this.show, source.show);
  179. this.pixelSize = defaultValue(this.pixelSize, source.pixelSize);
  180. this.heightReference = defaultValue(
  181. this.heightReference,
  182. source.heightReference
  183. );
  184. this.color = defaultValue(this.color, source.color);
  185. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  186. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  187. this.scaleByDistance = defaultValue(
  188. this.scaleByDistance,
  189. source.scaleByDistance
  190. );
  191. this.translucencyByDistance = defaultValue(
  192. this._translucencyByDistance,
  193. source.translucencyByDistance
  194. );
  195. this.distanceDisplayCondition = defaultValue(
  196. this.distanceDisplayCondition,
  197. source.distanceDisplayCondition
  198. );
  199. this.disableDepthTestDistance = defaultValue(
  200. this.disableDepthTestDistance,
  201. source.disableDepthTestDistance
  202. );
  203. };
  204. export default PointGraphics;