Source: DataSources/BillboardGraphics.js

  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. * Describes a two dimensional icon located at the position of the containing {@link Entity}.
  19. * <p>
  20. * <div align='center'>
  21. * <img src='images/Billboard.png' width='400' height='300' /><br />
  22. * Example billboards
  23. * </div>
  24. * </p>
  25. *
  26. * @alias BillboardGraphics
  27. * @constructor
  28. *
  29. * @param {Object} [options] Object with the following properties:
  30. * @param {Property} [options.image] A Property specifying the Image, URI, or Canvas to use for the billboard.
  31. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the billboard.
  32. * @param {Property} [options.scale=1.0] A numeric Property specifying the scale to apply to the image size.
  33. * @param {Property} [options.horizontalOrigin=HorizontalOrigin.CENTER] A Property specifying the {@link HorizontalOrigin}.
  34. * @param {Property} [options.verticalOrigin=VerticalOrigin.CENTER] A Property specifying the {@link VerticalOrigin}.
  35. * @param {Property} [options.eyeOffset=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the eye offset.
  36. * @param {Property} [options.pixelOffset=Cartesian2.ZERO] A {@link Cartesian2} Property specifying the pixel offset.
  37. * @param {Property} [options.rotation=0] A numeric Property specifying the rotation about the alignedAxis.
  38. * @param {Property} [options.alignedAxis=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the unit vector axis of rotation.
  39. * @param {Property} [options.width] A numeric Property specifying the width of the billboard in pixels, overriding the native size.
  40. * @param {Property} [options.height] A numeric Property specifying the height of the billboard in pixels, overriding the native size.
  41. * @param {Property} [options.color=Color.WHITE] A Property specifying the tint {@link Color} of the image.
  42. * @param {Property} [options.scaleByDistance] A {@link NearFarScalar} Property used to scale the point based on distance from the camera.
  43. * @param {Property} [options.translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera.
  44. * @param {Property} [options.pixelOffsetScaleByDistance] A {@link NearFarScalar} Property used to set pixelOffset based on distance from the camera.
  45. * @param {Property} [options.imageSubRegion] A Property specifying a {@link BoundingRectangle} that defines a sub-region of the image to use for the billboard, rather than the entire image, measured in pixels from the bottom-left.
  46. * @param {Property} [options.sizeInMeters] A boolean Property specifying whether this billboard's size should be measured in meters.
  47. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to.
  48. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this billboard will be displayed.
  49. *
  50. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Billboards.html|Cesium Sandcastle Billboard Demo}
  51. */
  52. function BillboardGraphics(options) {
  53. this._image = undefined;
  54. this._imageSubscription = undefined;
  55. this._imageSubRegion = undefined;
  56. this._imageSubRegionSubscription = undefined;
  57. this._width = undefined;
  58. this._widthSubscription = undefined;
  59. this._height = undefined;
  60. this._heightSubscription = undefined;
  61. this._scale = undefined;
  62. this._scaleSubscription = undefined;
  63. this._rotation = undefined;
  64. this._rotationSubscription = undefined;
  65. this._alignedAxis = undefined;
  66. this._alignedAxisSubscription = undefined;
  67. this._horizontalOrigin = undefined;
  68. this._horizontalOriginSubscription = undefined;
  69. this._verticalOrigin = undefined;
  70. this._verticalOriginSubscription = undefined;
  71. this._color = undefined;
  72. this._colorSubscription = undefined;
  73. this._eyeOffset = undefined;
  74. this._eyeOffsetSubscription = undefined;
  75. this._heightReference = undefined;
  76. this._heightReferenceSubscription = undefined;
  77. this._pixelOffset = undefined;
  78. this._pixelOffsetSubscription = undefined;
  79. this._show = undefined;
  80. this._showSubscription = undefined;
  81. this._scaleByDistance = undefined;
  82. this._scaleByDistanceSubscription = undefined;
  83. this._translucencyByDistance = undefined;
  84. this._translucencyByDistanceSubscription = undefined;
  85. this._pixelOffsetScaleByDistance = undefined;
  86. this._pixelOffsetScaleByDistanceSubscription = undefined;
  87. this._sizeInMeters = undefined;
  88. this._sizeInMetersSubscription = undefined;
  89. this._distanceDisplayCondition = undefined;
  90. this._distanceDisplayConditionSubscription = undefined;
  91. this._definitionChanged = new Event();
  92. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  93. }
  94. defineProperties(BillboardGraphics.prototype, {
  95. /**
  96. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  97. * @memberof BillboardGraphics.prototype
  98. *
  99. * @type {Event}
  100. * @readonly
  101. */
  102. definitionChanged : {
  103. get : function() {
  104. return this._definitionChanged;
  105. }
  106. },
  107. /**
  108. * Gets or sets the Property specifying the Image, URI, or Canvas to use for the billboard.
  109. * @memberof BillboardGraphics.prototype
  110. * @type {Property}
  111. */
  112. image : createPropertyDescriptor('image'),
  113. /**
  114. * Gets or sets the Property specifying a {@link BoundingRectangle} that defines a
  115. * sub-region of the <code>image</code> to use for the billboard, rather than the entire image,
  116. * measured in pixels from the bottom-left.
  117. * @memberof BillboardGraphics.prototype
  118. * @type {Property}
  119. */
  120. imageSubRegion : createPropertyDescriptor('imageSubRegion'),
  121. /**
  122. * Gets or sets the numeric Property specifying the uniform scale to apply to the image.
  123. * A scale greater than <code>1.0</code> enlarges the billboard while a scale less than <code>1.0</code> shrinks it.
  124. * <p>
  125. * <div align='center'>
  126. * <img src='images/Billboard.setScale.png' width='400' height='300' /><br/>
  127. * From left to right in the above image, the scales are <code>0.5</code>, <code>1.0</code>, and <code>2.0</code>.
  128. * </div>
  129. * </p>
  130. * @memberof BillboardGraphics.prototype
  131. * @type {Property}
  132. * @default 1.0
  133. */
  134. scale : createPropertyDescriptor('scale'),
  135. /**
  136. * Gets or sets the numeric Property specifying the rotation of the image
  137. * counter clockwise from the <code>alignedAxis</code>.
  138. * @memberof BillboardGraphics.prototype
  139. * @type {Property}
  140. * @default 0
  141. */
  142. rotation : createPropertyDescriptor('rotation'),
  143. /**
  144. * Gets or sets the {@link Cartesian3} Property specifying the unit vector axis of rotation
  145. * in the fixed frame. When set to Cartesian3.ZERO the rotation is from the top of the screen.
  146. * @memberof BillboardGraphics.prototype
  147. * @type {Property}
  148. * @default Cartesian3.ZERO
  149. */
  150. alignedAxis : createPropertyDescriptor('alignedAxis'),
  151. /**
  152. * Gets or sets the Property specifying the {@link HorizontalOrigin}.
  153. * @memberof BillboardGraphics.prototype
  154. * @type {Property}
  155. * @default HorizontalOrigin.CENTER
  156. */
  157. horizontalOrigin : createPropertyDescriptor('horizontalOrigin'),
  158. /**
  159. * Gets or sets the Property specifying the {@link VerticalOrigin}.
  160. * @memberof BillboardGraphics.prototype
  161. * @type {Property}
  162. * @default VerticalOrigin.CENTER
  163. */
  164. verticalOrigin : createPropertyDescriptor('verticalOrigin'),
  165. /**
  166. * Gets or sets the Property specifying the {@link Color} that is multiplied with the <code>image</code>.
  167. * This has two common use cases. First, the same white texture may be used by many different billboards,
  168. * each with a different color, to create colored billboards. Second, the color's alpha component can be
  169. * used to make the billboard translucent as shown below. An alpha of <code>0.0</code> makes the billboard
  170. * transparent, and <code>1.0</code> makes the billboard opaque.
  171. * <p>
  172. * <div align='center'>
  173. * <table border='0' cellpadding='5'><tr>
  174. * <td align='center'><code>default</code><br/><img src='images/Billboard.setColor.Alpha255.png' width='250' height='188' /></td>
  175. * <td align='center'><code>alpha : 0.5</code><br/><img src='images/Billboard.setColor.Alpha127.png' width='250' height='188' /></td>
  176. * </tr></table>
  177. * </div>
  178. * </p>
  179. * @memberof BillboardGraphics.prototype
  180. * @type {Property}
  181. * @default Color.WHITE
  182. */
  183. color : createPropertyDescriptor('color'),
  184. /**
  185. * Gets or sets the {@link Cartesian3} Property specifying the billboard's offset in eye coordinates.
  186. * Eye coordinates is a left-handed coordinate system, where <code>x</code> points towards the viewer's
  187. * right, <code>y</code> points up, and <code>z</code> points into the screen.
  188. * <p>
  189. * An eye offset is commonly used to arrange multiple billboards or objects at the same position, e.g., to
  190. * arrange a billboard above its corresponding 3D model.
  191. * </p>
  192. * Below, the billboard is positioned at the center of the Earth but an eye offset makes it always
  193. * appear on top of the Earth regardless of the viewer's or Earth's orientation.
  194. * <p>
  195. * <div align='center'>
  196. * <table border='0' cellpadding='5'><tr>
  197. * <td align='center'><img src='images/Billboard.setEyeOffset.one.png' width='250' height='188' /></td>
  198. * <td align='center'><img src='images/Billboard.setEyeOffset.two.png' width='250' height='188' /></td>
  199. * </tr></table>
  200. * <code>b.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);</code>
  201. * </div>
  202. * </p>
  203. * @memberof BillboardGraphics.prototype
  204. * @type {Property}
  205. * @default Cartesian3.ZERO
  206. */
  207. eyeOffset : createPropertyDescriptor('eyeOffset'),
  208. /**
  209. * Gets or sets the Property specifying the {@link HeightReference}.
  210. * @memberof BillboardGraphics.prototype
  211. * @type {Property}
  212. * @default HeightReference.NONE
  213. */
  214. heightReference : createPropertyDescriptor('heightReference'),
  215. /**
  216. * Gets or sets the {@link Cartesian2} Property specifying the billboard's pixel offset in screen space
  217. * from the origin of this billboard. This is commonly used to align multiple billboards and labels at
  218. * the same position, e.g., an image and text. The screen space origin is the top, left corner of the
  219. * canvas; <code>x</code> increases from left to right, and <code>y</code> increases from top to bottom.
  220. * <p>
  221. * <div align='center'>
  222. * <table border='0' cellpadding='5'><tr>
  223. * <td align='center'><code>default</code><br/><img src='images/Billboard.setPixelOffset.default.png' width='250' height='188' /></td>
  224. * <td align='center'><code>b.pixeloffset = new Cartesian2(50, 25);</code><br/><img src='images/Billboard.setPixelOffset.x50y-25.png' width='250' height='188' /></td>
  225. * </tr></table>
  226. * The billboard's origin is indicated by the yellow point.
  227. * </div>
  228. * </p>
  229. * @memberof BillboardGraphics.prototype
  230. * @type {Property}
  231. * @default Cartesian2.ZERO
  232. */
  233. pixelOffset : createPropertyDescriptor('pixelOffset'),
  234. /**
  235. * Gets or sets the boolean Property specifying the visibility of the billboard.
  236. * @memberof BillboardGraphics.prototype
  237. * @type {Property}
  238. * @default true
  239. */
  240. show : createPropertyDescriptor('show'),
  241. /**
  242. * Gets or sets the numeric Property specifying the billboard's width in pixels.
  243. * When undefined, the native width is used.
  244. * @memberof BillboardGraphics.prototype
  245. * @type {Property}
  246. */
  247. width : createPropertyDescriptor('width'),
  248. /**
  249. * Gets or sets the numeric Property specifying the height of the billboard in pixels.
  250. * When undefined, the native height is used.
  251. * @memberof BillboardGraphics.prototype
  252. * @type {Property}
  253. */
  254. height : createPropertyDescriptor('height'),
  255. /**
  256. * Gets or sets {@link NearFarScalar} Property specifying the scale of the billboard based on the distance from the camera.
  257. * A billboard's scale will interpolate between the {@link NearFarScalar#nearValue} and
  258. * {@link NearFarScalar#farValue} while the camera distance falls within the upper and lower bounds
  259. * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
  260. * Outside of these ranges the billboard's scale remains clamped to the nearest bound.
  261. * @memberof BillboardGraphics.prototype
  262. * @type {Property}
  263. */
  264. scaleByDistance : createPropertyDescriptor('scaleByDistance'),
  265. /**
  266. * Gets or sets {@link NearFarScalar} Property specifying the translucency of the billboard based on the distance from the camera.
  267. * A billboard's translucency will interpolate between the {@link NearFarScalar#nearValue} and
  268. * {@link NearFarScalar#farValue} while the camera distance falls within the upper and lower bounds
  269. * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
  270. * Outside of these ranges the billboard's translucency remains clamped to the nearest bound.
  271. * @memberof BillboardGraphics.prototype
  272. * @type {Property}
  273. */
  274. translucencyByDistance : createPropertyDescriptor('translucencyByDistance'),
  275. /**
  276. * Gets or sets {@link NearFarScalar} Property specifying the pixel offset of the billboard based on the distance from the camera.
  277. * A billboard's pixel offset will interpolate between the {@link NearFarScalar#nearValue} and
  278. * {@link NearFarScalar#farValue} while the camera distance falls within the upper and lower bounds
  279. * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
  280. * Outside of these ranges the billboard's pixel offset remains clamped to the nearest bound.
  281. * @memberof BillboardGraphics.prototype
  282. * @type {Property}
  283. */
  284. pixelOffsetScaleByDistance : createPropertyDescriptor('pixelOffsetScaleByDistance'),
  285. /**
  286. * Gets or sets the boolean Property specifying if this billboard's size will be measured in meters.
  287. * @memberof BillboardGraphics.prototype
  288. * @type {Property}
  289. * @default false
  290. */
  291. sizeInMeters : createPropertyDescriptor('sizeInMeters'),
  292. /**
  293. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this billboard will be displayed.
  294. * @memberof BillboardGraphics.prototype
  295. * @type {Property}
  296. */
  297. distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition')
  298. });
  299. /**
  300. * Duplicates this instance.
  301. *
  302. * @param {BillboardGraphics} [result] The object onto which to store the result.
  303. * @returns {BillboardGraphics} The modified result parameter or a new instance if one was not provided.
  304. */
  305. BillboardGraphics.prototype.clone = function(result) {
  306. if (!defined(result)) {
  307. return new BillboardGraphics(this);
  308. }
  309. result.color = this._color;
  310. result.eyeOffset = this._eyeOffset;
  311. result.heightReference = this._heightReference;
  312. result.horizontalOrigin = this._horizontalOrigin;
  313. result.image = this._image;
  314. result.imageSubRegion = this._imageSubRegion;
  315. result.pixelOffset = this._pixelOffset;
  316. result.scale = this._scale;
  317. result.rotation = this._rotation;
  318. result.alignedAxis = this._alignedAxis;
  319. result.show = this._show;
  320. result.verticalOrigin = this._verticalOrigin;
  321. result.width = this._width;
  322. result.height = this._height;
  323. result.scaleByDistance = this._scaleByDistance;
  324. result.translucencyByDistance = this._translucencyByDistance;
  325. result.pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;
  326. result.sizeInMeters = this._sizeInMeters;
  327. result.distanceDisplayCondition = this._distanceDisplayCondition;
  328. return result;
  329. };
  330. /**
  331. * Assigns each unassigned property on this object to the value
  332. * of the same property on the provided source object.
  333. *
  334. * @param {BillboardGraphics} source The object to be merged into this object.
  335. */
  336. BillboardGraphics.prototype.merge = function(source) {
  337. //>>includeStart('debug', pragmas.debug);
  338. if (!defined(source)) {
  339. throw new DeveloperError('source is required.');
  340. }
  341. //>>includeEnd('debug');
  342. this.color = defaultValue(this._color, source.color);
  343. this.eyeOffset = defaultValue(this._eyeOffset, source.eyeOffset);
  344. this.heightReference = defaultValue(this._heightReference, source.heightReference);
  345. this.horizontalOrigin = defaultValue(this._horizontalOrigin, source.horizontalOrigin);
  346. this.image = defaultValue(this._image, source.image);
  347. this.imageSubRegion = defaultValue(this._imageSubRegion, source.imageSubRegion);
  348. this.pixelOffset = defaultValue(this._pixelOffset, source.pixelOffset);
  349. this.scale = defaultValue(this._scale, source.scale);
  350. this.rotation = defaultValue(this._rotation, source.rotation);
  351. this.alignedAxis = defaultValue(this._alignedAxis, source.alignedAxis);
  352. this.show = defaultValue(this._show, source.show);
  353. this.verticalOrigin = defaultValue(this._verticalOrigin, source.verticalOrigin);
  354. this.width = defaultValue(this._width, source.width);
  355. this.height = defaultValue(this._height, source.height);
  356. this.scaleByDistance = defaultValue(this._scaleByDistance, source.scaleByDistance);
  357. this.translucencyByDistance = defaultValue(this._translucencyByDistance, source.translucencyByDistance);
  358. this.pixelOffsetScaleByDistance = defaultValue(this._pixelOffsetScaleByDistance, source.pixelOffsetScaleByDistance);
  359. this.sizeInMeters = defaultValue(this._sizeInMeters, source.sizeInMeters);
  360. this.distanceDisplayCondition = defaultValue(this._distanceDisplayCondition, source.distanceDisplayCondition);
  361. };
  362. return BillboardGraphics;
  363. });