/
LabelGraphics.js
396 lines (368 loc) · 19.1 KB
/
LabelGraphics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
define([
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/Event',
'./createPropertyDescriptor'
], function(
defaultValue,
defined,
defineProperties,
DeveloperError,
Event,
createPropertyDescriptor) {
'use strict';
/**
* Describes a two dimensional label located at the position of the containing {@link Entity}.
* <p>
* <div align='center'>
* <img src='Images/Label.png' width='400' height='300' /><br />
* Example labels
* </div>
* </p>
*
* @alias LabelGraphics
* @constructor
*
* @param {Object} [options] Object with the following properties:
* @param {Property} [options.text] A Property specifying the text. Explicit newlines '\n' are supported.
* @param {Property} [options.font='10px sans-serif'] A Property specifying the CSS font.
* @param {Property} [options.style=LabelStyle.FILL] A Property specifying the {@link LabelStyle}.
* @param {Property} [options.fillColor=Color.WHITE] A Property specifying the fill {@link Color}.
* @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the outline {@link Color}.
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the outline width.
* @param {Property} [options.show=true] A boolean Property specifying the visibility of the label.
* @param {Property} [options.showBackground=false] A boolean Property specifying the visibility of the background behind the label.
* @param {Property} [options.backgroundColor=new Color(0.165, 0.165, 0.165, 0.8)] A Property specifying the background {@link Color}.
* @param {Property} [options.backgroundPadding=new Cartesian2(7, 5)] A {@link Cartesian2} Property specifying the horizontal and vertical background padding in pixels.
* @param {Property} [options.scale=1.0] A numeric Property specifying the scale to apply to the text.
* @param {Property} [options.horizontalOrigin=HorizontalOrigin.CENTER] A Property specifying the {@link HorizontalOrigin}.
* @param {Property} [options.verticalOrigin=VerticalOrigin.CENTER] A Property specifying the {@link VerticalOrigin}.
* @param {Property} [options.eyeOffset=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the eye offset.
* @param {Property} [options.pixelOffset=Cartesian2.ZERO] A {@link Cartesian2} Property specifying the pixel offset.
* @param {Property} [options.translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera.
* @param {Property} [options.pixelOffsetScaleByDistance] A {@link NearFarScalar} Property used to set pixelOffset based on distance from the camera.
* @param {Property} [options.scaleByDistance] A {@link NearFarScalar} Property used to set scale based on distance from the camera.
* @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to.
* @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this label will be displayed.
* @param {Property} [options.disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to.
*
* @demo {@link https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Labels.html|Cesium Sandcastle Labels Demo}
*/
function LabelGraphics(options) {
this._text = undefined;
this._textSubscription = undefined;
this._font = undefined;
this._fontSubscription = undefined;
this._style = undefined;
this._styleSubscription = undefined;
this._fillColor = undefined;
this._fillColorSubscription = undefined;
this._outlineColor = undefined;
this._outlineColorSubscription = undefined;
this._outlineWidth = undefined;
this._outlineWidthSubscription = undefined;
this._horizontalOrigin = undefined;
this._horizontalOriginSubscription = undefined;
this._verticalOrigin = undefined;
this._verticalOriginSubscription = undefined;
this._eyeOffset = undefined;
this._eyeOffsetSubscription = undefined;
this._heightReference = undefined;
this._heightReferenceSubscription = undefined;
this._pixelOffset = undefined;
this._pixelOffsetSubscription = undefined;
this._scale = undefined;
this._scaleSubscription = undefined;
this._show = undefined;
this._showSubscription = undefined;
this._showBackground = undefined;
this._showBackgroundSubscription = undefined;
this._backgroundColor = undefined;
this._backgroundColorSubscription = undefined;
this._backgroundPadding = undefined;
this._backgroundPaddingSubscription = undefined;
this._translucencyByDistance = undefined;
this._translucencyByDistanceSubscription = undefined;
this._pixelOffsetScaleByDistance = undefined;
this._pixelOffsetScaleByDistanceSubscription = undefined;
this._scaleByDistance = undefined;
this._scaleByDistanceSubscription = undefined;
this._distanceDisplayCondition = undefined;
this._distanceDisplayConditionSubscription = undefined;
this._disableDepthTestDistance = undefined;
this._disableDepthTestDistanceSubscription = undefined;
this._definitionChanged = new Event();
this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
}
defineProperties(LabelGraphics.prototype, {
/**
* Gets the event that is raised whenever a property or sub-property is changed or modified.
* @memberof LabelGraphics.prototype
*
* @type {Event}
* @readonly
*/
definitionChanged : {
get : function() {
return this._definitionChanged;
}
},
/**
* Gets or sets the string Property specifying the text of the label.
* Explicit newlines '\n' are supported.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
text : createPropertyDescriptor('text'),
/**
* Gets or sets the string Property specifying the font in CSS syntax.
* @memberof LabelGraphics.prototype
* @type {Property}
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/font|CSS font on MDN}
*/
font : createPropertyDescriptor('font'),
/**
* Gets or sets the Property specifying the {@link LabelStyle}.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
style : createPropertyDescriptor('style'),
/**
* Gets or sets the Property specifying the fill {@link Color}.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
fillColor : createPropertyDescriptor('fillColor'),
/**
* Gets or sets the Property specifying the outline {@link Color}.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
outlineColor : createPropertyDescriptor('outlineColor'),
/**
* Gets or sets the numeric Property specifying the outline width.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
outlineWidth : createPropertyDescriptor('outlineWidth'),
/**
* Gets or sets the Property specifying the {@link HorizontalOrigin}.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
horizontalOrigin : createPropertyDescriptor('horizontalOrigin'),
/**
* Gets or sets the Property specifying the {@link VerticalOrigin}.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
verticalOrigin : createPropertyDescriptor('verticalOrigin'),
/**
* Gets or sets the {@link Cartesian3} Property specifying the label's offset in eye coordinates.
* Eye coordinates is a left-handed coordinate system, where <code>x</code> points towards the viewer's
* right, <code>y</code> points up, and <code>z</code> points into the screen.
* <p>
* An eye offset is commonly used to arrange multiple labels or objects at the same position, e.g., to
* arrange a label above its corresponding 3D model.
* </p>
* Below, the label is positioned at the center of the Earth but an eye offset makes it always
* appear on top of the Earth regardless of the viewer's or Earth's orientation.
* <p>
* <div align='center'>
* <table border='0' cellpadding='5'><tr>
* <td align='center'><img src='Images/Billboard.setEyeOffset.one.png' width='250' height='188' /></td>
* <td align='center'><img src='Images/Billboard.setEyeOffset.two.png' width='250' height='188' /></td>
* </tr></table>
* <code>l.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);</code><br /><br />
* </div>
* </p>
* @memberof LabelGraphics.prototype
* @type {Property}
* @default Cartesian3.ZERO
*/
eyeOffset : createPropertyDescriptor('eyeOffset'),
/**
* Gets or sets the Property specifying the {@link HeightReference}.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default HeightReference.NONE
*/
heightReference : createPropertyDescriptor('heightReference'),
/**
* Gets or sets the {@link Cartesian2} Property specifying the label's pixel offset in screen space
* from the origin of this label. This is commonly used to align multiple labels and labels at
* the same position, e.g., an image and text. The screen space origin is the top, left corner of the
* canvas; <code>x</code> increases from left to right, and <code>y</code> increases from top to bottom.
* <p>
* <div align='center'>
* <table border='0' cellpadding='5'><tr>
* <td align='center'><code>default</code><br/><img src='Images/Label.setPixelOffset.default.png' width='250' height='188' /></td>
* <td align='center'><code>l.pixeloffset = new Cartesian2(25, 75);</code><br/><img src='Images/Label.setPixelOffset.x50y-25.png' width='250' height='188' /></td>
* </tr></table>
* The label's origin is indicated by the yellow point.
* </div>
* </p>
* @memberof LabelGraphics.prototype
* @type {Property}
* @default Cartesian2.ZERO
*/
pixelOffset : createPropertyDescriptor('pixelOffset'),
/**
* Gets or sets the numeric Property specifying the uniform scale to apply to the image.
* A scale greater than <code>1.0</code> enlarges the label while a scale less than <code>1.0</code> shrinks it.
* <p>
* <div align='center'>
* <img src='Images/Label.setScale.png' width='400' height='300' /><br/>
* From left to right in the above image, the scales are <code>0.5</code>, <code>1.0</code>,
* and <code>2.0</code>.
* </div>
* </p>
* @memberof LabelGraphics.prototype
* @type {Property}
* @default 1.0
*/
scale : createPropertyDescriptor('scale'),
/**
* Gets or sets the boolean Property specifying the visibility of the label.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
show : createPropertyDescriptor('show'),
/**
* Gets or sets the boolean Property specifying the visibility of the background behind the label.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default false
*/
showBackground : createPropertyDescriptor('showBackground'),
/**
* Gets or sets the Property specifying the background {@link Color}.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default new Color(0.165, 0.165, 0.165, 0.8)
*/
backgroundColor : createPropertyDescriptor('backgroundColor'),
/**
* Gets or sets the {@link Cartesian2} Property specifying the label's horizontal and vertical
* background padding in pixels.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default new Cartesian2(7, 5)
*/
backgroundPadding : createPropertyDescriptor('backgroundPadding'),
/**
* Gets or sets {@link NearFarScalar} Property specifying the translucency of the label based on the distance from the camera.
* A label's translucency will interpolate between the {@link NearFarScalar#nearValue} and
* {@link NearFarScalar#farValue} while the camera distance falls within the upper and lower bounds
* of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
* Outside of these ranges the label's translucency remains clamped to the nearest bound.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
translucencyByDistance : createPropertyDescriptor('translucencyByDistance'),
/**
* Gets or sets {@link NearFarScalar} Property specifying the pixel offset of the label based on the distance from the camera.
* A label's pixel offset will interpolate between the {@link NearFarScalar#nearValue} and
* {@link NearFarScalar#farValue} while the camera distance falls within the upper and lower bounds
* of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
* Outside of these ranges the label's pixel offset remains clamped to the nearest bound.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
pixelOffsetScaleByDistance : createPropertyDescriptor('pixelOffsetScaleByDistance'),
/**
* Gets or sets near and far scaling properties of a Label based on the label's distance from the camera.
* A label's scale will interpolate between the {@link NearFarScalar#nearValue} and
* {@link NearFarScalar#farValue} while the camera distance falls within the upper and lower bounds
* of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
* Outside of these ranges the label's scale remains clamped to the nearest bound. If undefined,
* scaleByDistance will be disabled.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
scaleByDistance : createPropertyDescriptor('scaleByDistance'),
/**
* Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this label will be displayed.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition'),
/**
* Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
* When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
disableDepthTestDistance : createPropertyDescriptor('disableDepthTestDistance')
});
/**
* Duplicates this instance.
*
* @param {LabelGraphics} [result] The object onto which to store the result.
* @returns {LabelGraphics} The modified result parameter or a new instance if one was not provided.
*/
LabelGraphics.prototype.clone = function(result) {
if (!defined(result)) {
return new LabelGraphics(this);
}
result.text = this.text;
result.font = this.font;
result.show = this.show;
result.style = this.style;
result.fillColor = this.fillColor;
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.showBackground = this.showBackground;
result.backgroundColor = this.backgroundColor;
result.backgroundPadding = this.backgroundPadding;
result.scale = this.scale;
result.horizontalOrigin = this.horizontalOrigin;
result.verticalOrigin = this.verticalOrigin;
result.eyeOffset = this.eyeOffset;
result.heightReference = this.heightReference;
result.pixelOffset = this.pixelOffset;
result.translucencyByDistance = this.translucencyByDistance;
result.pixelOffsetScaleByDistance = this.pixelOffsetScaleByDistance;
result.scaleByDistance = this.scaleByDistance;
result.distanceDisplayCondition = this.distanceDisplayCondition;
result.disableDepthTestDistance = this.disableDepthTestDistance;
return result;
};
/**
* Assigns each unassigned property on this object to the value
* of the same property on the provided source object.
*
* @param {LabelGraphics} source The object to be merged into this object.
*/
LabelGraphics.prototype.merge = function(source) {
//>>includeStart('debug', pragmas.debug);
if (!defined(source)) {
throw new DeveloperError('source is required.');
}
//>>includeEnd('debug');
this.text = defaultValue(this.text, source.text);
this.font = defaultValue(this.font, source.font);
this.show = defaultValue(this.show, source.show);
this.style = defaultValue(this.style, source.style);
this.fillColor = defaultValue(this.fillColor, source.fillColor);
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.showBackground = defaultValue(this.showBackground, source.showBackground);
this.backgroundColor = defaultValue(this.backgroundColor, source.backgroundColor);
this.backgroundPadding = defaultValue(this.backgroundPadding, source.backgroundPadding);
this.scale = defaultValue(this.scale, source.scale);
this.horizontalOrigin = defaultValue(this.horizontalOrigin, source.horizontalOrigin);
this.verticalOrigin = defaultValue(this.verticalOrigin, source.verticalOrigin);
this.eyeOffset = defaultValue(this.eyeOffset, source.eyeOffset);
this.heightReference = defaultValue(this.heightReference, source.heightReference);
this.pixelOffset = defaultValue(this.pixelOffset, source.pixelOffset);
this.translucencyByDistance = defaultValue(this.translucencyByDistance, source.translucencyByDistance);
this.pixelOffsetScaleByDistance = defaultValue(this.pixelOffsetScaleByDistance, source.pixelOffsetScaleByDistance);
this.scaleByDistance = defaultValue(this.scaleByDistance, source.scaleByDistance);
this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
this.disableDepthTestDistance = defaultValue(this.disableDepthTestDistance, source.disableDepthTestDistance);
};
return LabelGraphics;
});