/
ProjectionPickerViewModel.js
202 lines (177 loc) · 5.91 KB
/
ProjectionPickerViewModel.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
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
define([
'../../Core/defined',
'../../Core/defineProperties',
'../../Core/destroyObject',
'../../Core/DeveloperError',
'../../Core/EventHelper',
'../../Core/OrthographicFrustum',
'../../Scene/SceneMode',
'../../ThirdParty/knockout',
'../createCommand'
], function(
defined,
defineProperties,
destroyObject,
DeveloperError,
EventHelper,
OrthographicFrustum,
SceneMode,
knockout,
createCommand) {
'use strict';
/**
* The view model for {@link ProjectionPicker}.
* @alias ProjectionPickerViewModel
* @constructor
*
* @param {Scene} scene The Scene to switch projections.
*/
function ProjectionPickerViewModel(scene) {
//>>includeStart('debug', pragmas.debug);
if (!defined(scene)) {
throw new DeveloperError('scene is required.');
}
//>>includeEnd('debug');
this._scene = scene;
this._orthographic = scene.camera.frustum instanceof OrthographicFrustum;
this._flightInProgress = false;
/**
* Gets or sets whether the button drop-down is currently visible. This property is observable.
* @type {Boolean}
* @default false
*/
this.dropDownVisible = false;
/**
* Gets or sets the perspective projection tooltip. This property is observable.
* @type {String}
* @default 'Perspective Projection'
*/
this.tooltipPerspective = 'Perspective Projection';
/**
* Gets or sets the orthographic projection tooltip. This property is observable.
* @type {String}
* @default 'Orthographic Projection'
*/
this.tooltipOrthographic = 'Orthographic Projection';
/**
* Gets the currently active tooltip. This property is observable.
* @type {String}
*/
this.selectedTooltip = undefined;
/**
* Gets or sets the current SceneMode. This property is observable.
* @type {SceneMode}
*/
this.sceneMode = scene.mode;
knockout.track(this, ['_orthographic', '_flightInProgress', 'sceneMode', 'dropDownVisible', 'tooltipPerspective', 'tooltipOrthographic']);
var that = this;
knockout.defineProperty(this, 'selectedTooltip', function() {
if (that._orthographic) {
return that.tooltipOrthographic;
}
return that.tooltipPerspective;
});
this._toggleDropDown = createCommand(function() {
if (that.sceneMode === SceneMode.SCENE2D || that._flightInProgress) {
return;
}
that.dropDownVisible = !that.dropDownVisible;
});
this._eventHelper = new EventHelper();
this._eventHelper.add(scene.morphComplete, function(transitioner, oldMode, newMode, isMorphing) {
that.sceneMode = newMode;
that._orthographic = newMode === SceneMode.SCENE2D || that._scene.camera.frustum instanceof OrthographicFrustum;
});
this._eventHelper.add(scene.preRender, function() {
that._flightInProgress = defined(scene.camera._currentFlight);
});
this._switchToPerspective = createCommand(function() {
if (that.sceneMode === SceneMode.SCENE2D) {
return;
}
that._scene.camera.switchToPerspectiveFrustum();
that._orthographic = false;
that.dropDownVisible = false;
});
this._switchToOrthographic = createCommand(function() {
if (that.sceneMode === SceneMode.SCENE2D) {
return;
}
that._scene.camera.switchToOrthographicFrustum();
that._orthographic = true;
that.dropDownVisible = false;
});
//Used by knockout
this._sceneMode = SceneMode;
}
defineProperties(ProjectionPickerViewModel.prototype, {
/**
* Gets the scene
* @memberof ProjectionPickerViewModel.prototype
* @type {Scene}
*/
scene : {
get : function() {
return this._scene;
}
},
/**
* Gets the command to toggle the drop down box.
* @memberof ProjectionPickerViewModel.prototype
*
* @type {Command}
*/
toggleDropDown : {
get : function() {
return this._toggleDropDown;
}
},
/**
* Gets the command to switch to a perspective projection.
* @memberof ProjectionPickerViewModel.prototype
*
* @type {Command}
*/
switchToPerspective : {
get : function() {
return this._switchToPerspective;
}
},
/**
* Gets the command to switch to orthographic projection.
* @memberof ProjectionPickerViewModel.prototype
*
* @type {Command}
*/
switchToOrthographic : {
get : function() {
return this._switchToOrthographic;
}
},
/**
* Gets whether the scene is currently using an orthographic projection.
* @memberof ProjectionPickerViewModel.prototype
*
* @type {Command}
*/
isOrthographicProjection : {
get : function() {
return this._orthographic;
}
}
});
/**
* @returns {Boolean} true if the object has been destroyed, false otherwise.
*/
ProjectionPickerViewModel.prototype.isDestroyed = function() {
return false;
};
/**
* Destroys the view model.
*/
ProjectionPickerViewModel.prototype.destroy = function() {
this._eventHelper.removeAll();
destroyObject(this);
};
return ProjectionPickerViewModel;
});