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
import { Cartesian2 } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { JulianDate } from "../../Source/Cesium.js";
import { TimeInterval } from "../../Source/Cesium.js";
import { ConstantProperty } from "../../Source/Cesium.js";
import { ImageMaterialProperty } from "../../Source/Cesium.js";
import { TimeIntervalCollectionProperty } from "../../Source/Cesium.js";
 
describe("DataSources/ImageMaterialProperty", function () {
  it("constructor provides the expected defaults", function () {
    var property = new ImageMaterialProperty();
    expect(property.getType()).toEqual("Image");
 
    var result = property.getValue();
    expect(result.image).toBeUndefined();
    expect(result.repeat).toEqual(new Cartesian2(1.0, 1.0));
    expect(result.color).toEqual(Color.WHITE);
  });
 
  it("constructor sets options and allows raw assignment", function () {
    var options = {
      image: "test.invalid",
      repeat: new Cartesian2(1, 2),
      color: Color.RED.withAlpha(0.5),
      transparent: true,
    };
 
    var property = new ImageMaterialProperty(options);
    expect(property.image).toBeInstanceOf(ConstantProperty);
    expect(property.repeat).toBeInstanceOf(ConstantProperty);
    expect(property.color).toBeInstanceOf(ConstantProperty);
    expect(property.transparent).toBeInstanceOf(ConstantProperty);
 
    expect(property.image.getValue()).toEqual(options.image);
    expect(property.repeat.getValue()).toEqual(options.repeat);
    expect(property.color.getValue()).toEqual(options.color);
    expect(property.transparent.getValue()).toEqual(options.transparent);
  });
 
  it("works with constant values", function () {
    var property = new ImageMaterialProperty();
    property.image = new ConstantProperty("http://test.invalid/image.png");
    property.repeat = new ConstantProperty(new Cartesian2(2, 3));
 
    var result = property.getValue(JulianDate.now());
    expect(result.image).toEqual("http://test.invalid/image.png");
    expect(result.repeat).toEqual(new Cartesian2(2, 3));
  });
 
  it("works with dynamic values", function () {
    var property = new ImageMaterialProperty();
    property.image = new TimeIntervalCollectionProperty();
    property.repeat = new TimeIntervalCollectionProperty();
 
    var start = new JulianDate(1, 0);
    var stop = new JulianDate(2, 0);
    property.image.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: "http://test.invalid/image.png",
      })
    );
    property.repeat.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: new Cartesian2(2, 3),
      })
    );
 
    var result = property.getValue(start);
    expect(result.image).toEqual("http://test.invalid/image.png");
    expect(result.repeat).toEqual(new Cartesian2(2, 3));
  });
 
  it("works with a result parameter", function () {
    var property = new ImageMaterialProperty();
    property.image = new ConstantProperty("http://test.invalid/image.png");
    property.repeat = new ConstantProperty(new Cartesian2(2, 3));
 
    var result = {};
    var returnedResult = property.getValue(JulianDate.now(), result);
    expect(result).toBe(returnedResult);
    expect(result.image).toEqual("http://test.invalid/image.png");
    expect(result.repeat).toEqual(new Cartesian2(2, 3));
  });
 
  it("equals works", function () {
    var left = new ImageMaterialProperty();
    left.image = new ConstantProperty("http://test.invalid/image.png");
    left.repeat = new ConstantProperty(new Cartesian2(2, 3));
 
    var right = new ImageMaterialProperty();
    right.image = new ConstantProperty("http://test.invalid/image.png");
    right.repeat = new ConstantProperty(new Cartesian2(2, 3));
 
    expect(left.equals(right)).toEqual(true);
 
    right.image = new ConstantProperty("http://test.invalid/image2.png");
    expect(left.equals(right)).toEqual(false);
 
    right.image = left.image;
    right.repeat = new ConstantProperty(new Cartesian2(3, 2));
    expect(left.equals(right)).toEqual(false);
 
    right.repeat = left.repeat;
    expect(left.equals(right)).toEqual(true);
  });
 
  it("raises definitionChanged when a property is assigned or modified", function () {
    var property = new ImageMaterialProperty();
    var listener = jasmine.createSpy("listener");
    property.definitionChanged.addEventListener(listener);
 
    var oldValue = property.image;
    property.image = new ConstantProperty("http://test.invalid/image.png");
    expect(listener).toHaveBeenCalledWith(
      property,
      "image",
      property.image,
      oldValue
    );
    listener.calls.reset();
 
    property.image.setValue("http://test.invalid/image2.png");
    expect(listener).toHaveBeenCalledWith(
      property,
      "image",
      property.image,
      property.image
    );
    listener.calls.reset();
 
    property.image = property.image;
    expect(listener.calls.count()).toEqual(0);
    listener.calls.reset();
 
    oldValue = property.repeat;
    property.repeat = new ConstantProperty(new Cartesian2(1.5, 1.5));
    expect(listener).toHaveBeenCalledWith(
      property,
      "repeat",
      property.repeat,
      oldValue
    );
    listener.calls.reset();
 
    property.repeat.setValue(new Cartesian2(1.0, 1.0));
    expect(listener).toHaveBeenCalledWith(
      property,
      "repeat",
      property.repeat,
      property.repeat
    );
    listener.calls.reset();
 
    property.repeat = property.repeat;
    expect(listener.calls.count()).toEqual(0);
  });
 
  it("isConstant is only true when all properties are constant or undefined", function () {
    var property = new ImageMaterialProperty();
    expect(property.isConstant).toBe(true);
 
    property.image = undefined;
    property.repeat = undefined;
    expect(property.isConstant).toBe(true);
 
    var start = new JulianDate(1, 0);
    var stop = new JulianDate(2, 0);
    property.image = new TimeIntervalCollectionProperty();
    property.image.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: "http://test.invalid/image.png",
      })
    );
    expect(property.isConstant).toBe(false);
 
    property.image = undefined;
    expect(property.isConstant).toBe(true);
    property.repeat = new TimeIntervalCollectionProperty();
    property.repeat.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: new Cartesian2(2, 3),
      })
    );
    expect(property.isConstant).toBe(false);
  });
});