15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
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
import { Cartesian2 } from "../../Source/Cesium.js";
import { Cartesian3 } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { DistanceDisplayCondition } from "../../Source/Cesium.js";
import { NearFarScalar } from "../../Source/Cesium.js";
import { ConstantProperty } from "../../Source/Cesium.js";
import { LabelGraphics } from "../../Source/Cesium.js";
import { HorizontalOrigin } from "../../Source/Cesium.js";
import { LabelStyle } from "../../Source/Cesium.js";
import { VerticalOrigin } from "../../Source/Cesium.js";
 
describe("DataSources/LabelGraphics", function () {
  it("creates expected instance from raw assignment and construction", function () {
    var options = {
      text: "0",
      font: "1",
      style: LabelStyle.FILL,
      fillColor: Color.RED,
      outlineColor: Color.BLUE,
      outlineWidth: 2,
      horizontalOrigin: HorizontalOrigin.LEFT,
      verticalOrigin: VerticalOrigin.BOTTOM,
      eyeOffset: new Cartesian3(3, 4, 5),
      pixelOffset: new Cartesian2(6, 7),
      scale: 8,
      show: true,
      translucencyByDistance: new NearFarScalar(9, 10, 11, 12),
      pixelOffsetScaleByDistance: new NearFarScalar(13, 14, 15, 16),
      scaleByDistance: new NearFarScalar(17, 18, 19, 20),
      distanceDisplayCondition: new DistanceDisplayCondition(10.0, 100.0),
      disableDepthTestDistance: 10.0,
    };
 
    var label = new LabelGraphics(options);
    expect(label.text).toBeInstanceOf(ConstantProperty);
    expect(label.font).toBeInstanceOf(ConstantProperty);
    expect(label.style).toBeInstanceOf(ConstantProperty);
    expect(label.fillColor).toBeInstanceOf(ConstantProperty);
    expect(label.outlineColor).toBeInstanceOf(ConstantProperty);
    expect(label.outlineWidth).toBeInstanceOf(ConstantProperty);
    expect(label.horizontalOrigin).toBeInstanceOf(ConstantProperty);
    expect(label.verticalOrigin).toBeInstanceOf(ConstantProperty);
    expect(label.eyeOffset).toBeInstanceOf(ConstantProperty);
    expect(label.scale).toBeInstanceOf(ConstantProperty);
    expect(label.show).toBeInstanceOf(ConstantProperty);
    expect(label.translucencyByDistance).toBeInstanceOf(ConstantProperty);
    expect(label.pixelOffsetScaleByDistance).toBeInstanceOf(ConstantProperty);
    expect(label.scaleByDistance).toBeInstanceOf(ConstantProperty);
    expect(label.distanceDisplayCondition).toBeInstanceOf(ConstantProperty);
    expect(label.disableDepthTestDistance).toBeInstanceOf(ConstantProperty);
 
    expect(label.text.getValue()).toEqual(options.text);
    expect(label.font.getValue()).toEqual(options.font);
    expect(label.style.getValue()).toEqual(options.style);
    expect(label.fillColor.getValue()).toEqual(options.fillColor);
    expect(label.outlineColor.getValue()).toEqual(options.outlineColor);
    expect(label.outlineWidth.getValue()).toEqual(options.outlineWidth);
    expect(label.horizontalOrigin.getValue()).toEqual(options.horizontalOrigin);
    expect(label.verticalOrigin.getValue()).toEqual(options.verticalOrigin);
    expect(label.eyeOffset.getValue()).toEqual(options.eyeOffset);
    expect(label.scale.getValue()).toEqual(options.scale);
    expect(label.show.getValue()).toEqual(options.show);
    expect(label.translucencyByDistance.getValue()).toEqual(
      options.translucencyByDistance
    );
    expect(label.pixelOffsetScaleByDistance.getValue()).toEqual(
      options.pixelOffsetScaleByDistance
    );
    expect(label.scaleByDistance.getValue()).toEqual(options.scaleByDistance);
    expect(label.distanceDisplayCondition.getValue()).toEqual(
      options.distanceDisplayCondition
    );
    expect(label.disableDepthTestDistance.getValue()).toEqual(
      options.disableDepthTestDistance
    );
  });
 
  it("merge assigns unassigned properties", function () {
    var source = new LabelGraphics();
    source.text = new ConstantProperty("not it");
    source.font = new ConstantProperty("arial");
    source.style = new ConstantProperty(LabelStyle.FILL);
    source.fillColor = new ConstantProperty(Color.BLACK);
    source.outlineColor = new ConstantProperty(Color.BLUE);
    source.outlineWidth = new ConstantProperty(5);
    source.horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT);
    source.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM);
    source.eyeOffset = new ConstantProperty(Cartesian3.UNIT_Y);
    source.pixelOffset = new ConstantProperty(Cartesian2.UNIT_X);
    source.scale = new ConstantProperty(1);
    source.show = new ConstantProperty(false);
    source.translucencyByDistance = new ConstantProperty(new NearFarScalar());
    source.pixelOffsetScaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.scaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition(10.0, 100.0)
    );
    source.disableDepthTestDistance = new ConstantProperty(10.0);
 
    var target = new LabelGraphics();
    target.merge(source);
 
    expect(target.text).toBe(source.text);
    expect(target.font).toBe(source.font);
    expect(target.style).toBe(source.style);
    expect(target.fillColor).toBe(source.fillColor);
    expect(target.outlineColor).toBe(source.outlineColor);
    expect(target.outlineWidth).toBe(source.outlineWidth);
    expect(target.horizontalOrigin).toBe(source.horizontalOrigin);
    expect(target.verticalOrigin).toBe(source.verticalOrigin);
    expect(target.eyeOffset).toBe(source.eyeOffset);
    expect(target.pixelOffset).toBe(source.pixelOffset);
    expect(target.scale).toBe(source.scale);
    expect(target.show).toBe(source.show);
    expect(target.translucencyByDistance).toBe(source.translucencyByDistance);
    expect(target.pixelOffsetScaleByDistance).toBe(
      source.pixelOffsetScaleByDistance
    );
    expect(target.scaleByDistance).toBe(source.scaleByDistance);
    expect(target.distanceDisplayCondition).toBe(
      source.distanceDisplayCondition
    );
    expect(target.disableDepthTestDistance).toBe(
      source.disableDepthTestDistance
    );
  });
 
  it("merge does not assign assigned properties", function () {
    var source = new LabelGraphics();
    source.text = new ConstantProperty("not it");
    source.font = new ConstantProperty("arial");
    source.style = new ConstantProperty(LabelStyle.FILL);
    source.fillColor = new ConstantProperty(Color.BLACK);
    source.outlineColor = new ConstantProperty(Color.BLUE);
    source.outlineWidth = new ConstantProperty(5);
    source.horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT);
    source.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM);
    source.eyeOffset = new ConstantProperty(Cartesian3.UNIT_Y);
    source.pixelOffset = new ConstantProperty(Cartesian2.UNIT_X);
    source.scale = new ConstantProperty(1);
    source.show = new ConstantProperty(false);
    source.translucencyByDistance = new ConstantProperty(new NearFarScalar());
    source.pixelOffsetScaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.scaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition(10.0, 100.0)
    );
    source.disableDepthTestDistance = new ConstantProperty(10.0);
 
    var text = new ConstantProperty("my text");
    var font = new ConstantProperty("10px serif");
    var style = new ConstantProperty(LabelStyle.OUTLINE);
    var fillColor = new ConstantProperty(Color.RED);
    var outlineColor = new ConstantProperty(Color.WHITE);
    var outlineWidth = new ConstantProperty(4);
    var horizontalOrigin = new ConstantProperty(HorizontalOrigin.RIGHT);
    var verticalOrigin = new ConstantProperty(VerticalOrigin.TOP);
    var eyeOffset = new ConstantProperty(Cartesian3.UNIT_Z);
    var pixelOffset = new ConstantProperty(Cartesian2.UNIT_Y);
    var scale = new ConstantProperty(2);
    var show = new ConstantProperty(true);
    var translucencyByDistance = new ConstantProperty(new NearFarScalar());
    var pixelOffsetScaleByDistance = new ConstantProperty(new NearFarScalar());
    var scaleByDistance = new ConstantProperty(new NearFarScalar());
    var distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition()
    );
    var disableDepthTestDistance = new ConstantProperty(20.0);
 
    var target = new LabelGraphics();
    target.text = text;
    target.font = font;
    target.style = style;
    target.fillColor = fillColor;
    target.outlineColor = outlineColor;
    target.outlineWidth = outlineWidth;
    target.horizontalOrigin = horizontalOrigin;
    target.verticalOrigin = verticalOrigin;
    target.eyeOffset = eyeOffset;
    target.pixelOffset = pixelOffset;
    target.scale = scale;
    target.show = show;
    target.translucencyByDistance = translucencyByDistance;
    target.pixelOffsetScaleByDistance = pixelOffsetScaleByDistance;
    target.scaleByDistance = scaleByDistance;
    target.distanceDisplayCondition = distanceDisplayCondition;
    target.disableDepthTestDistance = disableDepthTestDistance;
 
    target.merge(source);
 
    expect(target.text).toBe(text);
    expect(target.font).toBe(font);
    expect(target.style).toBe(style);
    expect(target.fillColor).toBe(fillColor);
    expect(target.outlineColor).toBe(outlineColor);
    expect(target.outlineWidth).toBe(outlineWidth);
    expect(target.horizontalOrigin).toBe(horizontalOrigin);
    expect(target.verticalOrigin).toBe(verticalOrigin);
    expect(target.eyeOffset).toBe(eyeOffset);
    expect(target.pixelOffset).toBe(pixelOffset);
    expect(target.scale).toBe(scale);
    expect(target.show).toBe(show);
    expect(target.translucencyByDistance).toBe(translucencyByDistance);
    expect(target.pixelOffsetScaleByDistance).toBe(pixelOffsetScaleByDistance);
    expect(target.scaleByDistance).toBe(scaleByDistance);
    expect(target.distanceDisplayCondition).toBe(distanceDisplayCondition);
    expect(target.disableDepthTestDistance).toBe(disableDepthTestDistance);
  });
 
  it("clone works", function () {
    var source = new LabelGraphics();
    source.text = new ConstantProperty("not it");
    source.font = new ConstantProperty("arial");
    source.style = new ConstantProperty(LabelStyle.FILL);
    source.fillColor = new ConstantProperty(Color.BLACK);
    source.outlineColor = new ConstantProperty(Color.BLUE);
    source.outlineWidth = new ConstantProperty(5);
    source.horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT);
    source.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM);
    source.eyeOffset = new ConstantProperty(Cartesian3.UNIT_Y);
    source.pixelOffset = new ConstantProperty(Cartesian2.UNIT_X);
    source.scale = new ConstantProperty(1);
    source.show = new ConstantProperty(false);
    source.translucencyByDistance = new ConstantProperty(new NearFarScalar());
    source.pixelOffsetScaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.scaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition(10.0, 100.0)
    );
    source.disableDepthTestDistance = new ConstantProperty(10.0);
 
    var result = source.clone();
    expect(result.text).toBe(source.text);
    expect(result.font).toBe(source.font);
    expect(result.style).toBe(source.style);
    expect(result.fillColor).toBe(source.fillColor);
    expect(result.outlineColor).toBe(source.outlineColor);
    expect(result.outlineWidth).toBe(source.outlineWidth);
    expect(result.horizontalOrigin).toBe(source.horizontalOrigin);
    expect(result.verticalOrigin).toBe(source.verticalOrigin);
    expect(result.eyeOffset).toBe(source.eyeOffset);
    expect(result.pixelOffset).toBe(source.pixelOffset);
    expect(result.scale).toBe(source.scale);
    expect(result.show).toBe(source.show);
    expect(result.translucencyByDistance).toBe(source.translucencyByDistance);
    expect(result.pixelOffsetScaleByDistance).toBe(
      source.pixelOffsetScaleByDistance
    );
    expect(result.scaleByDistance).toBe(source.scaleByDistance);
    expect(result.distanceDisplayCondition).toBe(
      source.distanceDisplayCondition
    );
    expect(result.disableDepthTestDistance).toBe(
      source.disableDepthTestDistance
    );
  });
 
  it("merge throws if source undefined", function () {
    var target = new LabelGraphics();
    expect(function () {
      target.merge(undefined);
    }).toThrowDeveloperError();
  });
});