yzt
2023-05-05 4c558c77a6a9d23f057f094c4dc3e315eabef497
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
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 { BillboardGraphics } from "../../Source/Cesium.js";
import { ConstantProperty } from "../../Source/Cesium.js";
import { HeightReference } from "../../Source/Cesium.js";
import { HorizontalOrigin } from "../../Source/Cesium.js";
import { VerticalOrigin } from "../../Source/Cesium.js";
 
describe("DataSources/BillboardGraphics", function () {
  it("creates expected instance from raw assignment and construction", function () {
    var options = {
      image: "0",
      rotation: 1,
      alignedAxis: Cartesian3.UNIT_Z,
      color: Color.RED,
      heightReference: HeightReference.CLAMP_TO_GROUND,
      horizontalOrigin: HorizontalOrigin.LEFT,
      verticalOrigin: VerticalOrigin.BOTTOM,
      eyeOffset: new Cartesian3(5, 6, 7),
      pixelOffset: new Cartesian2(8, 9),
      scale: 10,
      show: true,
      width: 11,
      height: 12,
      scaleByDistance: new NearFarScalar(13, 14, 15, 16),
      translucencyByDistance: new NearFarScalar(17, 18, 19, 20),
      pixelOffsetScaleByDistance: new NearFarScalar(21, 22, 23, 24),
      sizeInMeters: true,
      distanceDisplayCondition: new DistanceDisplayCondition(10.0, 100.0),
      disableDepthTestDistance: 10.0,
    };
 
    var billboard = new BillboardGraphics(options);
    expect(billboard.image).toBeInstanceOf(ConstantProperty);
    expect(billboard.rotation).toBeInstanceOf(ConstantProperty);
    expect(billboard.alignedAxis).toBeInstanceOf(ConstantProperty);
    expect(billboard.color).toBeInstanceOf(ConstantProperty);
    expect(billboard.heightReference).toBeInstanceOf(ConstantProperty);
    expect(billboard.horizontalOrigin).toBeInstanceOf(ConstantProperty);
    expect(billboard.verticalOrigin).toBeInstanceOf(ConstantProperty);
    expect(billboard.eyeOffset).toBeInstanceOf(ConstantProperty);
    expect(billboard.scale).toBeInstanceOf(ConstantProperty);
    expect(billboard.show).toBeInstanceOf(ConstantProperty);
    expect(billboard.width).toBeInstanceOf(ConstantProperty);
    expect(billboard.height).toBeInstanceOf(ConstantProperty);
    expect(billboard.scaleByDistance).toBeInstanceOf(ConstantProperty);
    expect(billboard.translucencyByDistance).toBeInstanceOf(ConstantProperty);
    expect(billboard.pixelOffsetScaleByDistance).toBeInstanceOf(
      ConstantProperty
    );
    expect(billboard.sizeInMeters).toBeInstanceOf(ConstantProperty);
    expect(billboard.distanceDisplayCondition).toBeInstanceOf(ConstantProperty);
    expect(billboard.disableDepthTestDistance).toBeInstanceOf(ConstantProperty);
 
    expect(billboard.image.getValue()).toEqual(options.image);
    expect(billboard.rotation.getValue()).toEqual(options.rotation);
    expect(billboard.alignedAxis.getValue()).toEqual(options.alignedAxis);
    expect(billboard.color.getValue()).toEqual(options.color);
    expect(billboard.heightReference.getValue()).toEqual(
      options.heightReference
    );
    expect(billboard.horizontalOrigin.getValue()).toEqual(
      options.horizontalOrigin
    );
    expect(billboard.verticalOrigin.getValue()).toEqual(options.verticalOrigin);
    expect(billboard.eyeOffset.getValue()).toEqual(options.eyeOffset);
    expect(billboard.scale.getValue()).toEqual(options.scale);
    expect(billboard.show.getValue()).toEqual(options.show);
    expect(billboard.width.getValue()).toEqual(options.width);
    expect(billboard.height.getValue()).toEqual(options.height);
    expect(billboard.scaleByDistance.getValue()).toEqual(
      options.scaleByDistance
    );
    expect(billboard.translucencyByDistance.getValue()).toEqual(
      options.translucencyByDistance
    );
    expect(billboard.pixelOffsetScaleByDistance.getValue()).toEqual(
      options.pixelOffsetScaleByDistance
    );
    expect(billboard.sizeInMeters.getValue()).toEqual(options.sizeInMeters);
    expect(billboard.distanceDisplayCondition.getValue()).toEqual(
      options.distanceDisplayCondition
    );
    expect(billboard.disableDepthTestDistance.getValue()).toEqual(
      options.disableDepthTestDistance
    );
  });
 
  it("merge assigns unassigned properties", function () {
    var source = new BillboardGraphics();
    source.image = new ConstantProperty("");
    source.imageSubRegion = new ConstantProperty();
    source.rotation = new ConstantProperty(5);
    source.alignedAxis = new ConstantProperty(new Cartesian3());
    source.color = new ConstantProperty(Color.BLACK);
    source.heightReference = new ConstantProperty(
      HeightReference.CLAMP_TO_GROUND
    );
    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.width = new ConstantProperty(24);
    source.height = new ConstantProperty(36);
    source.scaleByDistance = new ConstantProperty(new NearFarScalar());
    source.translucencyByDistance = new ConstantProperty(new NearFarScalar());
    source.pixelOffsetScaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.sizeInMeters = new ConstantProperty(true);
    source.distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition(10.0, 100.0)
    );
    source.disableDepthTestDistance = 10.0;
 
    var target = new BillboardGraphics();
    target.merge(source);
 
    expect(target.image).toBe(source.image);
    expect(target.imageSubRegion).toBe(source.imageSubRegion);
    expect(target.rotation).toBe(source.rotation);
    expect(target.alignedAxis).toBe(source.alignedAxis);
    expect(target.color).toBe(source.color);
    expect(target.heightReference).toBe(source.heightReference);
    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.width).toBe(source.width);
    expect(target.height).toBe(source.height);
    expect(target.scaleByDistance).toBe(source.scaleByDistance);
    expect(target.translucencyByDistance).toBe(source.translucencyByDistance);
    expect(target.pixelOffsetScaleByDistance).toBe(
      source.pixelOffsetScaleByDistance
    );
    expect(target.sizeInMeters).toBe(source.sizeInMeters);
    expect(target.distanceDisplayCondition).toBe(
      source.distanceDisplayCondition
    );
    expect(target.disableDepthTestDistance).toBe(
      source.disableDepthTestDistance
    );
  });
 
  it("merge does not assign assigned properties", function () {
    var source = new BillboardGraphics();
    source.image = new ConstantProperty("");
    source.imageSubRegion = new ConstantProperty();
    source.rotation = new ConstantProperty(5);
    source.alignedAxis = new ConstantProperty(new Cartesian3());
    source.color = new ConstantProperty(Color.BLACK);
    source.heightReference = new ConstantProperty(
      HeightReference.CLAMP_TO_GROUND
    );
    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.width = new ConstantProperty(24);
    source.height = new ConstantProperty(36);
    source.scaleByDistance = new ConstantProperty(new NearFarScalar());
    source.translucencyByDistance = new ConstantProperty(new NearFarScalar());
    source.pixelOffsetScaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.sizeInMeters = new ConstantProperty(true);
    source.distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition(10.0, 100.0)
    );
    source.disableDepthTestDistance = new ConstantProperty(10.0);
 
    var image = new ConstantProperty("");
    var imageSubRegion = new ConstantProperty();
    var rotation = new ConstantProperty(5);
    var alignedAxis = new ConstantProperty(new Cartesian3());
    var color = new ConstantProperty(Color.BLACK);
    var heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND);
    var horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT);
    var verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM);
    var eyeOffset = new ConstantProperty(Cartesian3.UNIT_Y);
    var pixelOffset = new ConstantProperty(Cartesian2.UNIT_X);
    var scale = new ConstantProperty(1);
    var show = new ConstantProperty(false);
    var width = new ConstantProperty(2);
    var height = new ConstantProperty(3);
    var scaleByDistance = new ConstantProperty(new NearFarScalar());
    var translucencyByDistance = new ConstantProperty(new NearFarScalar());
    var pixelOffsetScaleByDistance = new ConstantProperty(new NearFarScalar());
    var sizeInMeters = new ConstantProperty(true);
    var distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition()
    );
    var disableDepthTestDistance = new ConstantProperty(10.0);
 
    var target = new BillboardGraphics();
    target.image = image;
    target.imageSubRegion = imageSubRegion;
    target.rotation = rotation;
    target.alignedAxis = alignedAxis;
    target.color = color;
    target.heightReference = heightReference;
    target.horizontalOrigin = horizontalOrigin;
    target.verticalOrigin = verticalOrigin;
    target.eyeOffset = eyeOffset;
    target.pixelOffset = pixelOffset;
    target.scale = scale;
    target.show = show;
    target.width = width;
    target.height = height;
    target.scaleByDistance = scaleByDistance;
    target.translucencyByDistance = translucencyByDistance;
    target.pixelOffsetScaleByDistance = pixelOffsetScaleByDistance;
    target.sizeInMeters = sizeInMeters;
    target.distanceDisplayCondition = distanceDisplayCondition;
    target.disableDepthTestDistance = disableDepthTestDistance;
 
    target.merge(source);
 
    expect(target.image).toBe(image);
    expect(target.imageSubRegion).toBe(imageSubRegion);
    expect(target.rotation).toBe(rotation);
    expect(target.alignedAxis).toBe(alignedAxis);
    expect(target.color).toBe(color);
    expect(target.heightReference).toBe(heightReference);
    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.width).toBe(width);
    expect(target.height).toBe(height);
    expect(target.scaleByDistance).toBe(scaleByDistance);
    expect(target.translucencyByDistance).toBe(translucencyByDistance);
    expect(target.pixelOffsetScaleByDistance).toBe(pixelOffsetScaleByDistance);
    expect(target.sizeInMeters).toBe(sizeInMeters);
    expect(target.distanceDisplayCondition).toBe(distanceDisplayCondition);
    expect(target.disableDepthTestDistance).toBe(disableDepthTestDistance);
  });
 
  it("clone works", function () {
    var source = new BillboardGraphics();
    source.image = new ConstantProperty("");
    source.imageSubRegion = new ConstantProperty();
    source.rotation = new ConstantProperty(5);
    source.alignedAxis = new ConstantProperty(new Cartesian3());
    source.color = new ConstantProperty(Color.BLACK);
    source.heightReference = new ConstantProperty(
      HeightReference.CLAMP_TO_GROUND
    );
    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.width = new ConstantProperty(24);
    source.height = new ConstantProperty(36);
    source.scaleByDistance = new ConstantProperty(new NearFarScalar());
    source.translucencyByDistance = new ConstantProperty(new NearFarScalar());
    source.pixelOffsetScaleByDistance = new ConstantProperty(
      new NearFarScalar(1.0, 0.0, 3.0e9, 0.0)
    );
    source.sizeInMeters = new ConstantProperty(true);
    source.distanceDisplayCondition = new ConstantProperty(
      new DistanceDisplayCondition(10.0, 100.0)
    );
    source.disableDepthTestDistance = new ConstantProperty(10.0);
 
    var result = source.clone();
    expect(result.image).toBe(source.image);
    expect(result.imageSubRegion).toBe(source.imageSubRegion);
    expect(result.rotation).toBe(source.rotation);
    expect(result.alignedAxis).toBe(source.alignedAxis);
    expect(result.color).toBe(source.color);
    expect(result.heightReference).toBe(source.heightReference);
    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.width).toBe(source.width);
    expect(result.height).toBe(source.height);
    expect(result.scaleByDistance).toBe(source.scaleByDistance);
    expect(result.translucencyByDistance).toBe(source.translucencyByDistance);
    expect(result.pixelOffsetScaleByDistance).toBe(
      source.pixelOffsetScaleByDistance
    );
    expect(result.sizeInMeters).toBe(source.sizeInMeters);
    expect(result.distanceDisplayCondition).toBe(
      source.distanceDisplayCondition
    );
    expect(result.disableDepthTestDistance).toBe(
      source.disableDepthTestDistance
    );
  });
 
  it("merge throws if source undefined", function () {
    var target = new BillboardGraphics();
    expect(function () {
      target.merge(undefined);
    }).toThrowDeveloperError();
  });
});