LabelGraphics.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 label.
  19. * @alias LabelGraphics
  20. * @constructor
  21. */
  22. var LabelGraphics = function() {
  23. this._text = undefined;
  24. this._textSubscription = undefined;
  25. this._font = undefined;
  26. this._fontSubscription = undefined;
  27. this._style = undefined;
  28. this._styleSubscription = undefined;
  29. this._fillColor = undefined;
  30. this._fillColorSubscription = undefined;
  31. this._outlineColor = undefined;
  32. this._outlineColorSubscription = undefined;
  33. this._outlineWidth = undefined;
  34. this._outlineWidthSubscription = undefined;
  35. this._horizontalOrigin = undefined;
  36. this._horizontalOriginSubscription = undefined;
  37. this._verticalOrigin = undefined;
  38. this._verticalOriginSubscription = undefined;
  39. this._eyeOffset = undefined;
  40. this._eyeOffsetSubscription = undefined;
  41. this._pixelOffset = undefined;
  42. this._pixelOffsetSubscription = undefined;
  43. this._scale = undefined;
  44. this._scaleSubscription = undefined;
  45. this._show = undefined;
  46. this._showSubscription = undefined;
  47. this._translucencyByDistance = undefined;
  48. this._translucencyByDistanceSubscription = undefined;
  49. this._pixelOffsetScaleByDistance = undefined;
  50. this._pixelOffsetScaleByDistanceSubscription = undefined;
  51. this._definitionChanged = new Event();
  52. };
  53. defineProperties(LabelGraphics.prototype, {
  54. /**
  55. * Gets the event that is raised whenever a new property is assigned.
  56. * @memberof LabelGraphics.prototype
  57. *
  58. * @type {Event}
  59. * @readonly
  60. */
  61. definitionChanged : {
  62. get : function() {
  63. return this._definitionChanged;
  64. }
  65. },
  66. /**
  67. * Gets or sets the string {@link Property} specifying the the label's text.
  68. * @memberof LabelGraphics.prototype
  69. * @type {Property}
  70. */
  71. text : createPropertyDescriptor('text'),
  72. /**
  73. * Gets or sets the string {@link Property} specifying the the label's font.
  74. * @memberof LabelGraphics.prototype
  75. * @type {Property}
  76. */
  77. font : createPropertyDescriptor('font'),
  78. /**
  79. * Gets or sets the {@link LabelStyle} {@link Property} specifying the the label's style.
  80. * @memberof LabelGraphics.prototype
  81. * @type {Property}
  82. */
  83. style : createPropertyDescriptor('style'),
  84. /**
  85. * Gets or sets the {@link Color} {@link Property} specifying the the label's fill color.
  86. * @memberof LabelGraphics.prototype
  87. * @type {Property}
  88. */
  89. fillColor : createPropertyDescriptor('fillColor'),
  90. /**
  91. * Gets or sets the {@link Color} {@link Property} specifying the the label's outline color.
  92. * @memberof LabelGraphics.prototype
  93. * @type {Property}
  94. */
  95. outlineColor : createPropertyDescriptor('outlineColor'),
  96. /**
  97. * Gets or sets the numeric {@link Property} specifying the the label outline's width.
  98. * @memberof LabelGraphics.prototype
  99. * @type {Property}
  100. */
  101. outlineWidth : createPropertyDescriptor('outlineWidth'),
  102. /**
  103. * Gets or sets the {@link HorizontalOrigin} {@link Property} specifying the label's horizontal origin.
  104. * @memberof LabelGraphics.prototype
  105. * @type {Property}
  106. */
  107. horizontalOrigin : createPropertyDescriptor('horizontalOrigin'),
  108. /**
  109. * Gets or sets the {@link VerticalOrigin} {@link Property} specifying the label's vertical origin.
  110. * @memberof LabelGraphics.prototype
  111. * @type {Property}
  112. */
  113. verticalOrigin : createPropertyDescriptor('verticalOrigin'),
  114. /**
  115. * Gets or sets the {@link Cartesian3} {@link Property} specifying the label's eye offset.
  116. * @memberof LabelGraphics.prototype
  117. * @type {Property}
  118. */
  119. eyeOffset : createPropertyDescriptor('eyeOffset'),
  120. /**
  121. * Gets or sets the {@link Cartesian2} {@link Property} specifying the label's pixel offset.
  122. * @memberof LabelGraphics.prototype
  123. * @type {Property}
  124. */
  125. pixelOffset : createPropertyDescriptor('pixelOffset'),
  126. /**
  127. * Gets or sets the numeric {@link Property} specifying the label's scale.
  128. * @memberof LabelGraphics.prototype
  129. * @type {Property}
  130. */
  131. scale : createPropertyDescriptor('scale'),
  132. /**
  133. * Gets or sets the boolean {@link Property} specifying the label's visibility.
  134. * @memberof LabelGraphics.prototype
  135. * @type {Property}
  136. */
  137. show : createPropertyDescriptor('show'),
  138. /**
  139. * Gets or sets the {@link NearFarScalar} {@link Property} used to set translucency based on distance.
  140. * If undefined, a constant size is used.
  141. * @memberof LabelGraphics.prototype
  142. * @type {Property}
  143. */
  144. translucencyByDistance : createPropertyDescriptor('translucencyByDistance'),
  145. /**
  146. * Gets or sets the {@link NearFarScalar} {@link Property} used to set pixel offset scaling based on distance.
  147. * If undefined, no additional scale is applied to the pixel offset
  148. * @memberof LabelGraphics.prototype
  149. * @type {Property}
  150. */
  151. pixelOffsetScaleByDistance : createPropertyDescriptor('pixelOffsetScaleByDistance')
  152. });
  153. /**
  154. * Duplicates a LabelGraphics instance.
  155. *
  156. * @param {LabelGraphics} [result] The object onto which to store the result.
  157. * @returns {LabelGraphics} The modified result parameter or a new instance if one was not provided.
  158. */
  159. LabelGraphics.prototype.clone = function(result) {
  160. if (!defined(result)) {
  161. result = new LabelGraphics();
  162. }
  163. result.text = this.text;
  164. result.font = this.font;
  165. result.show = this.show;
  166. result.style = this.style;
  167. result.fillColor = this.fillColor;
  168. result.outlineColor = this.outlineColor;
  169. result.outlineWidth = this.outlineWidth;
  170. result.scale = this.scale;
  171. result.horizontalOrigin = this.horizontalOrigin;
  172. result.verticalOrigin = this.verticalOrigin;
  173. result.eyeOffset = this.eyeOffset;
  174. result.pixelOffset = this.pixelOffset;
  175. result.translucencyByDistance = this._translucencyByDistance;
  176. result.pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;
  177. return result;
  178. };
  179. /**
  180. * Assigns each unassigned property on this object to the value
  181. * of the same property on the provided source object.
  182. *
  183. * @param {LabelGraphics} source The object to be merged into this object.
  184. */
  185. LabelGraphics.prototype.merge = function(source) {
  186. //>>includeStart('debug', pragmas.debug);
  187. if (!defined(source)) {
  188. throw new DeveloperError('source is required.');
  189. }
  190. //>>includeEnd('debug');
  191. this.text = defaultValue(this.text, source.text);
  192. this.font = defaultValue(this.font, source.font);
  193. this.show = defaultValue(this.show, source.show);
  194. this.style = defaultValue(this.style, source.style);
  195. this.fillColor = defaultValue(this.fillColor, source.fillColor);
  196. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  197. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  198. this.scale = defaultValue(this.scale, source.scale);
  199. this.horizontalOrigin = defaultValue(this.horizontalOrigin, source.horizontalOrigin);
  200. this.verticalOrigin = defaultValue(this.verticalOrigin, source.verticalOrigin);
  201. this.eyeOffset = defaultValue(this.eyeOffset, source.eyeOffset);
  202. this.pixelOffset = defaultValue(this.pixelOffset, source.pixelOffset);
  203. this.translucencyByDistance = defaultValue(this._translucencyByDistance, source._translucencyByDistance);
  204. this.pixelOffsetScaleByDistance = defaultValue(this._pixelOffsetScaleByDistance, source._pixelOffsetScaleByDistance);
  205. };
  206. return LabelGraphics;
  207. });