BillboardGraphics.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/defined',
  5. '../Core/defineProperties',
  6. '../Core/DeveloperError',
  7. '../Core/Event',
  8. './createPropertyDescriptor'
  9. ], function(
  10. defaultValue,
  11. defined,
  12. defineProperties,
  13. DeveloperError,
  14. Event,
  15. createPropertyDescriptor) {
  16. "use strict";
  17. /**
  18. * An optionally time-dynamic billboard.
  19. *
  20. * @alias BillboardGraphics
  21. * @constructor
  22. */
  23. var BillboardGraphics = function() {
  24. this._image = undefined;
  25. this._imageSubscription = undefined;
  26. this._width = undefined;
  27. this._widthSubscription = undefined;
  28. this._height = undefined;
  29. this._heightSubscription = undefined;
  30. this._scale = undefined;
  31. this._scaleSubscription = undefined;
  32. this._rotation = undefined;
  33. this._rotationSubscription = undefined;
  34. this._alignedAxis = undefined;
  35. this._alignedAxisSubscription = undefined;
  36. this._horizontalOrigin = undefined;
  37. this._horizontalOriginSubscription = undefined;
  38. this._verticalOrigin = undefined;
  39. this._verticalOriginSubscription = undefined;
  40. this._color = undefined;
  41. this._colorSubscription = undefined;
  42. this._eyeOffset = undefined;
  43. this._eyeOffsetSubscription = undefined;
  44. this._pixelOffset = undefined;
  45. this._pixelOffsetSubscription = undefined;
  46. this._show = undefined;
  47. this._showSubscription = undefined;
  48. this._scaleByDistance = undefined;
  49. this._scaleByDistanceSubscription = undefined;
  50. this._translucencyByDistance = undefined;
  51. this._translucencyByDistanceSubscription = undefined;
  52. this._pixelOffsetScaleByDistance = undefined;
  53. this._pixelOffsetScaleByDistanceSubscription = undefined;
  54. this._definitionChanged = new Event();
  55. };
  56. defineProperties(BillboardGraphics.prototype, {
  57. /**
  58. * Gets the event that is raised whenever a new property is assigned.
  59. * @memberof BillboardGraphics.prototype
  60. *
  61. * @type {Event}
  62. * @readonly
  63. */
  64. definitionChanged : {
  65. get : function() {
  66. return this._definitionChanged;
  67. }
  68. },
  69. /**
  70. * Gets or sets the Image, URL, or Canvas {@link Property} specifying the billboard's texture.
  71. * @memberof BillboardGraphics.prototype
  72. * @type {Property}
  73. */
  74. image : createPropertyDescriptor('image'),
  75. /**
  76. * Gets or sets the numeric {@link Property} specifying the billboard's scale.
  77. * @memberof BillboardGraphics.prototype
  78. * @type {Property}
  79. */
  80. scale : createPropertyDescriptor('scale'),
  81. /**
  82. * Gets or sets the numeric {@link Property} specifying the billboard's rotation.
  83. * @memberof BillboardGraphics.prototype
  84. * @type {Property}
  85. */
  86. rotation : createPropertyDescriptor('rotation'),
  87. /**
  88. * Gets or sets the {@link Cartesian3} {@link Property} specifying the billboard rotation's aligned axis.
  89. * @memberof BillboardGraphics.prototype
  90. * @type {Property}
  91. */
  92. alignedAxis : createPropertyDescriptor('alignedAxis'),
  93. /**
  94. * Gets or sets the {@link HorizontalOrigin} {@link Property} specifying the billboard's horizontal origin.
  95. * @memberof BillboardGraphics.prototype
  96. * @type {Property}
  97. */
  98. horizontalOrigin : createPropertyDescriptor('horizontalOrigin'),
  99. /**
  100. * Gets or sets the {@link VerticalOrigin} {@link Property} specifying the billboard's vertical origin.
  101. * @memberof BillboardGraphics.prototype
  102. * @type {Property}
  103. */
  104. verticalOrigin : createPropertyDescriptor('verticalOrigin'),
  105. /**
  106. * Gets or sets the {@link Color} {@link Property} specifying the billboard's color.
  107. * @memberof BillboardGraphics.prototype
  108. * @type {Property}
  109. */
  110. color : createPropertyDescriptor('color'),
  111. /**
  112. * Gets or sets the {@link Cartesian3} {@link Property} specifying the billboard's eye offset.
  113. * @memberof BillboardGraphics.prototype
  114. * @type {Property}
  115. */
  116. eyeOffset : createPropertyDescriptor('eyeOffset'),
  117. /**
  118. * Gets or sets the {@link Cartesian2} {@link Property} specifying the billboard's pixel offset.
  119. * @memberof BillboardGraphics.prototype
  120. * @type {Property}
  121. */
  122. pixelOffset : createPropertyDescriptor('pixelOffset'),
  123. /**
  124. * Gets or sets the boolean {@link Property} specifying the billboard's visibility.
  125. * @memberof BillboardGraphics.prototype
  126. * @type {Property}
  127. */
  128. show : createPropertyDescriptor('show'),
  129. /**
  130. * Gets or sets the numeric {@link Property} specifying the billboard's width in pixels.
  131. * If undefined, the native width is used.
  132. * @memberof BillboardGraphics.prototype
  133. * @type {Property}
  134. */
  135. width : createPropertyDescriptor('width'),
  136. /**
  137. * Gets or sets the numeric {@link Property} specifying the billboard's height in pixels.
  138. * If undefined, the native height is used.
  139. * @memberof BillboardGraphics.prototype
  140. * @type {Property}
  141. */
  142. height : createPropertyDescriptor('height'),
  143. /**
  144. * Gets or sets the {@link NearFarScalar} {@link Property} used to scale billboards based on distance.
  145. * If undefined, a constant size is used.
  146. * @memberof BillboardGraphics.prototype
  147. * @type {Property}
  148. */
  149. scaleByDistance : createPropertyDescriptor('scaleByDistance'),
  150. /**
  151. * Gets or sets the {@link NearFarScalar} {@link Property} used to set translucency based on distance.
  152. * If undefined, a constant size is used.
  153. * @memberof BillboardGraphics.prototype
  154. * @type {Property}
  155. */
  156. translucencyByDistance : createPropertyDescriptor('translucencyByDistance'),
  157. /**
  158. * Gets or sets the {@link NearFarScalar} {@link Property} used to set pixel offset scaling based on distance.
  159. * If undefined, no additional scale is applied to the pixel offset
  160. * @memberof BillboardGraphics.prototype
  161. * @type {Property}
  162. */
  163. pixelOffsetScaleByDistance : createPropertyDescriptor('pixelOffsetScaleByDistance')
  164. });
  165. /**
  166. * Duplicates a BillboardGraphics instance.
  167. *
  168. * @param {BillboardGraphics} [result] The object onto which to store the result.
  169. * @returns {BillboardGraphics} The modified result parameter or a new instance if one was not provided.
  170. */
  171. BillboardGraphics.prototype.clone = function(result) {
  172. if (!defined(result)) {
  173. result = new BillboardGraphics();
  174. }
  175. result.color = this._color;
  176. result.eyeOffset = this._eyeOffset;
  177. result.horizontalOrigin = this._horizontalOrigin;
  178. result.image = this._image;
  179. result.pixelOffset = this._pixelOffset;
  180. result.scale = this._scale;
  181. result.rotation = this._rotation;
  182. result.alignedAxis = this._alignedAxis;
  183. result.show = this._show;
  184. result.verticalOrigin = this._verticalOrigin;
  185. result.width = this._width;
  186. result.height = this._height;
  187. result.scaleByDistance = this._scaleByDistance;
  188. result.translucencyByDistance = this._translucencyByDistance;
  189. result.pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;
  190. return result;
  191. };
  192. /**
  193. * Assigns each unassigned property on this object to the value
  194. * of the same property on the provided source object.
  195. *
  196. * @param {BillboardGraphics} source The object to be merged into this object.
  197. */
  198. BillboardGraphics.prototype.merge = function(source) {
  199. //>>includeStart('debug', pragmas.debug);
  200. if (!defined(source)) {
  201. throw new DeveloperError('source is required.');
  202. }
  203. //>>includeEnd('debug');
  204. this.color = defaultValue(this._color, source._color);
  205. this.eyeOffset = defaultValue(this._eyeOffset, source._eyeOffset);
  206. this.horizontalOrigin = defaultValue(this._horizontalOrigin, source._horizontalOrigin);
  207. this.image = defaultValue(this._image, source._image);
  208. this.pixelOffset = defaultValue(this._pixelOffset, source._pixelOffset);
  209. this.scale = defaultValue(this._scale, source._scale);
  210. this.rotation = defaultValue(this._rotation, source._rotation);
  211. this.alignedAxis = defaultValue(this._alignedAxis, source._alignedAxis);
  212. this.show = defaultValue(this._show, source._show);
  213. this.verticalOrigin = defaultValue(this._verticalOrigin, source._verticalOrigin);
  214. this.width = defaultValue(this._width, source._width);
  215. this.height = defaultValue(this._height, source._height);
  216. this.scaleByDistance = defaultValue(this._scaleByDistance, source._scaleByDistance);
  217. this.translucencyByDistance = defaultValue(this._translucencyByDistance, source._translucencyByDistance);
  218. this.pixelOffsetScaleByDistance = defaultValue(this._pixelOffsetScaleByDistance, source._pixelOffsetScaleByDistance);
  219. };
  220. return BillboardGraphics;
  221. });