PointGraphics.js 8.9 KB

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