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
import { Cartesian3 } from "../../Source/Cesium.js";
import { HeadingPitchRange } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { KmlLookAt } from "../../Source/Cesium.js";
import { KmlTour } from "../../Source/Cesium.js";
import { KmlTourFlyTo } from "../../Source/Cesium.js";
import { KmlTourWait } from "../../Source/Cesium.js";
import pollToPromise from "../pollToPromise.js";
 
describe("DataSources/KmlTour", function () {
  function getLookAt() {
    var position = Cartesian3.fromDegrees(40.0, 30.0, 1000);
    var hpr = new HeadingPitchRange(
      CesiumMath.toRadians(10.0),
      CesiumMath.toRadians(45.0),
      10000
    );
    return new KmlLookAt(position, hpr);
  }
 
  function createMockViewer() {
    var mockViewer = {};
    mockViewer.scene = {};
    mockViewer.scene.camera = {};
    mockViewer.scene.camera.flyTo = jasmine
      .createSpy("flyTo")
      .and.callFake(function (options) {
        if (options.complete) {
          options.complete();
        }
      });
    mockViewer.scene.camera.flyToBoundingSphere = jasmine
      .createSpy("flyToBoundingSphere")
      .and.callFake(function (boundingSphere, options) {
        if (options.complete) {
          options.complete();
        }
      });
    return mockViewer;
  }
 
  it("add entries to playlist", function () {
    var tour = new KmlTour("test", "test");
    var wait = new KmlTourWait(10);
    var flyTo = new KmlTourFlyTo(5, null, getLookAt());
    tour.addPlaylistEntry(wait);
    tour.addPlaylistEntry(flyTo);
 
    expect(tour.playlist.length).toEqual(2);
    expect(tour.playlist[0]).toBe(wait);
    expect(tour.playlist[1]).toBe(flyTo);
  });
 
  it("calls entries play", function () {
    var waitSpy = spyOn(KmlTourWait.prototype, "play").and.callFake(function (
      callback
    ) {
      callback();
    });
    var flySpy = spyOn(KmlTourFlyTo.prototype, "play").and.callFake(function (
      callback
    ) {
      callback();
    });
 
    var tour = new KmlTour("test", "test");
    var wait = new KmlTourWait(0.1);
    var flyTo = new KmlTourFlyTo(0.1, null, getLookAt());
    tour.addPlaylistEntry(wait);
    tour.addPlaylistEntry(flyTo);
 
    var mockViewer = createMockViewer();
    tour.play(mockViewer);
    return pollToPromise(function () {
      return waitSpy.calls.count() > 0 && flySpy.calls.count() > 0;
    }).then(function () {
      expect(waitSpy).toHaveBeenCalled();
      expect(flySpy).toHaveBeenCalled();
    });
  });
 
  it("calls events", function () {
    var tour = new KmlTour("test", "test");
    var wait1 = new KmlTourWait(0.05);
    var wait2 = new KmlTourWait(0.02);
 
    var tourStart = jasmine.createSpy("TourStart");
    var tourEnd = jasmine.createSpy("TourEnd");
    var entryStart = jasmine.createSpy("EntryStart");
    var entryEnd = jasmine.createSpy("EntryEnd");
 
    tour.addPlaylistEntry(wait1);
    tour.addPlaylistEntry(wait2);
 
    tour.tourStart.addEventListener(tourStart);
    tour.tourEnd.addEventListener(tourEnd);
    tour.entryStart.addEventListener(entryStart);
    tour.entryEnd.addEventListener(entryEnd);
 
    tour.play(createMockViewer());
    return pollToPromise(function () {
      return tourEnd.calls.count() > 0;
    }).then(function () {
      expect(tourStart).toHaveBeenCalled();
      expect(entryStart).toHaveBeenCalled();
      expect(entryEnd).toHaveBeenCalled();
      expect(tourEnd).toHaveBeenCalledWith(false);
    });
  });
 
  it("terminates playback", function () {
    var tour = new KmlTour("test", "test");
    var wait = new KmlTourWait(60);
    var flyTo = new KmlTourFlyTo(0.1, null, getLookAt());
 
    var tourStart = jasmine.createSpy("TourStart");
    var tourEnd = jasmine.createSpy("TourEnd");
    var entryStart = jasmine.createSpy("EntryStart");
    var entryEnd = jasmine.createSpy("EntryEnd");
 
    tour.addPlaylistEntry(wait);
    tour.addPlaylistEntry(flyTo);
 
    tour.tourStart.addEventListener(tourStart);
    tour.tourEnd.addEventListener(tourEnd);
    tour.entryStart.addEventListener(entryStart);
    tour.entryEnd.addEventListener(entryEnd);
 
    var mockViewer = createMockViewer();
    tour.play(mockViewer);
    setTimeout(function () {
      tour.stop();
      expect(tourStart).toHaveBeenCalled();
      // Wait entry have been started
      expect(entryStart).toHaveBeenCalledWith(wait);
      // Wait entry have been terminated
      expect(entryEnd).toHaveBeenCalledWith(wait, true);
      expect(tourEnd).toHaveBeenCalledWith(true);
 
      expect(entryStart.calls.count()).toEqual(1);
      expect(entryEnd.calls.count()).toEqual(1);
      expect(tourStart.calls.count()).toEqual(1);
      expect(tourEnd.calls.count()).toEqual(1);
 
      expect(mockViewer.scene.camera.flyTo.calls.count()).toEqual(0);
      expect(mockViewer.scene.camera.flyToBoundingSphere.calls.count()).toEqual(
        0
      );
    }, 5);
  });
});