forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKmlTourFlyToSpec.js
149 lines (134 loc) · 4.82 KB
/
KmlTourFlyToSpec.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
import { Cartesian3 } from "../../Source/Cesium.js";
import { HeadingPitchRange } from "../../Source/Cesium.js";
import { HeadingPitchRoll } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { KmlCamera } from "../../Source/Cesium.js";
import { KmlLookAt } from "../../Source/Cesium.js";
import { KmlTourFlyTo } from "../../Source/Cesium.js";
import pollToPromise from "../pollToPromise.js";
describe("DataSources/KmlTourFlyTo", function () {
it("generates camera options for KmlLookAt", function () {
const position = Cartesian3.fromDegrees(40.0, 30.0, 1000);
const hpr = new HeadingPitchRange(
CesiumMath.toRadians(10.0),
CesiumMath.toRadians(45.0),
10000
);
const flyto = new KmlTourFlyTo(10, "bounce", new KmlLookAt(position, hpr));
const options = flyto.getCameraOptions();
expect(options.duration).toEqual(10);
expect(options.complete).toBeUndefined();
expect(options.easingFunction).toBeUndefined();
expect(options.offset).toBe(hpr);
expect(options.destination).toBeUndefined();
expect(options.orientation).toBeUndefined();
});
it("generates camera options for KmlCamera", function () {
const position = Cartesian3.fromDegrees(40.0, 30.0, 1000);
const hpr = new HeadingPitchRoll(
CesiumMath.toRadians(10.0),
CesiumMath.toRadians(45.0),
0
);
const flyto = new KmlTourFlyTo(10, "bounce", new KmlCamera(position, hpr));
const options = flyto.getCameraOptions();
expect(options.duration).toEqual(10);
expect(options.complete).toBeUndefined();
expect(options.easingFunction).toBeUndefined();
expect(options.offset).toBeUndefined();
expect(options.destination.x).toEqual(position.x);
expect(options.destination.y).toEqual(position.y);
expect(options.destination.z).toEqual(position.z);
expect(options.orientation).toBe(hpr);
});
it("adds activeCallback to options", function () {
const position = Cartesian3.fromDegrees(40.0, 30.0, 1000);
const hpr = new HeadingPitchRange(
CesiumMath.toRadians(10.0),
CesiumMath.toRadians(45.0),
10000
);
const flyto = new KmlTourFlyTo(10, "bounce", new KmlLookAt(position, hpr));
flyto.activeCallback = jasmine.createSpy("activeCallback");
const options = flyto.getCameraOptions();
expect(options.complete).toBeDefined();
options.complete();
expect(options.complete).toHaveBeenCalled();
});
it("calls camera flyTo for KmlCamera", function () {
const position = Cartesian3.fromDegrees(40.0, 30.0, 1000);
const hpr = new HeadingPitchRoll(
CesiumMath.toRadians(10.0),
CesiumMath.toRadians(45.0),
0
);
const flyto = new KmlTourFlyTo(
0.01,
"bounce",
new KmlCamera(position, hpr)
);
const doneSpy = jasmine.createSpy("cameraDone");
const flyFake = jasmine.createSpy("flyTo").and.callFake(function (options) {
if (options.complete) {
options.complete();
}
});
const fakeCamera = {
flyTo: flyFake,
};
flyto.play(doneSpy, fakeCamera);
return pollToPromise(function () {
return doneSpy.calls.count() > 0;
}).then(function () {
expect(fakeCamera.flyTo).toHaveBeenCalled();
expect(fakeCamera.flyTo.calls.mostRecent().args[0].destination).toBe(
position
);
expect(fakeCamera.flyTo.calls.mostRecent().args[0].orientation).toBe(hpr);
expect(doneSpy).toHaveBeenCalled();
});
});
it("calls camera flyToBoundingSphere for KmlLookAt", function () {
const position = Cartesian3.fromDegrees(40.0, 30.0, 1000);
const hpr = new HeadingPitchRange(
CesiumMath.toRadians(10.0),
CesiumMath.toRadians(45.0),
10000
);
const flyto = new KmlTourFlyTo(
0.01,
"bounce",
new KmlLookAt(position, hpr)
);
const doneSpy = jasmine.createSpy("cameraDone");
const flyFake = jasmine
.createSpy("flyToBoundingSphere")
.and.callFake(function (sphere, options) {
if (options.complete) {
options.complete();
}
});
const fakeCamera = {
flyToBoundingSphere: flyFake,
};
flyto.play(doneSpy, fakeCamera);
return pollToPromise(function () {
return doneSpy.calls.count() > 0;
}).then(function () {
expect(fakeCamera.flyToBoundingSphere).toHaveBeenCalled();
expect(
fakeCamera.flyToBoundingSphere.calls.mostRecent().args[0].center.x
).toEqual(position.x);
expect(
fakeCamera.flyToBoundingSphere.calls.mostRecent().args[0].center.y
).toEqual(position.y);
expect(
fakeCamera.flyToBoundingSphere.calls.mostRecent().args[0].center.z
).toEqual(position.z);
expect(
fakeCamera.flyToBoundingSphere.calls.mostRecent().args[1].offset
).toBe(hpr);
expect(doneSpy).toHaveBeenCalled();
});
});
});