/
SceneModePicker.js
171 lines (153 loc) · 7.17 KB
/
SceneModePicker.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
/*global define*/
define([
'../../Core/defineProperties',
'../../Core/destroyObject',
'../../Core/DeveloperError',
'../getElement',
'./SceneModePickerViewModel',
'../../ThirdParty/knockout'
], function(
defineProperties,
destroyObject,
DeveloperError,
getElement,
SceneModePickerViewModel,
knockout) {
"use strict";
/**
* <img src="images/sceneModePicker.png" style="float: left; margin: 3px; border: none; border-radius: 5px;" />
* <p>The SceneModePicker is a single button widget for switching between scene modes;
* shown to the left in its expanded state. Programatic switching of scene modes will
* be automatically reflected in the widget as long as the specified SceneTransitioner
* is used to perform the change.</p><p style="clear: both;"></p><br/>
*
* @alias SceneModePicker
* @constructor
*
* @param {Element|String} container The DOM element or ID that will contain the widget.
* @param {SceneTransitioner} transitioner The SceneTransitioner instance to use.
*
* @exception {DeveloperError} container is required.
* @exception {DeveloperError} Element with id "container" does not exist in the document.
* @exception {DeveloperError} transitioner is required.
*
* @see SceneTransitioner
*
* @example
* // In HTML head, include a link to the SceneModePicker.css stylesheet,
* // and in the body, include: <div id="sceneModePickerContainer"></div>
* // Note: This code assumed you already have a Scene instance.
*
* var transitioner = new SceneTransitioner(scene);
* var sceneModePicker = new SceneModePicker('sceneModePickerContainer', transitioner);
*/
var SceneModePicker = function(container, transitioner) {
if (typeof container === 'undefined') {
throw new DeveloperError('container is required.');
}
if (typeof transitioner === 'undefined') {
throw new DeveloperError('transitioner is required.');
}
container = getElement(container);
var viewModel = new SceneModePickerViewModel(transitioner);
this._viewModel = viewModel;
this._container = container;
this._element = document.createElement('span');
var widgetNode = this._element;
widgetNode.className = 'cesium-sceneModePicker-button';
widgetNode.setAttribute('data-bind', '\
css: { "cesium-sceneModePicker-button2D": sceneMode === _sceneMode.SCENE2D,\
"cesium-sceneModePicker-button3D": sceneMode === _sceneMode.SCENE3D,\
"cesium-sceneModePicker-buttonColumbusView": sceneMode === _sceneMode.COLUMBUS_VIEW,\
"cesium-sceneModePicker-selected": dropDownVisible},\
attr: { title: selectedTooltip }, click: toggleDropDown');
container.appendChild(widgetNode);
var node3D = document.createElement('span');
node3D.className = 'cesium-sceneModePicker-button cesium-sceneModePicker-button3D';
node3D.setAttribute('data-bind', '\
css: { "cesium-sceneModePicker-visible" : (dropDownVisible && (sceneMode !== _sceneMode.SCENE3D)) || (!dropDownVisible && (sceneMode === _sceneMode.SCENE3D)),\
"cesium-sceneModePicker-none" : sceneMode === _sceneMode.SCENE3D,\
"cesium-sceneModePicker-hidden" : !dropDownVisible},\
attr: { title: tooltip3D },\
click: morphTo3D');
container.appendChild(node3D);
this._node3D = node3D;
var node2D = document.createElement('span');
node2D.className = 'cesium-sceneModePicker-button cesium-sceneModePicker-button2D';
node2D.setAttribute('data-bind', '\
css: { "cesium-sceneModePicker-visible" : (dropDownVisible && (sceneMode !== _sceneMode.SCENE2D)),\
"cesium-sceneModePicker-none" : sceneMode === _sceneMode.SCENE2D,\
"cesium-sceneModePicker-hidden" : !dropDownVisible},\
attr: { title: tooltip2D },\
click: morphTo2D');
container.appendChild(node2D);
this._node2D = node2D;
var nodeColumbus = document.createElement('span');
nodeColumbus.className = 'cesium-sceneModePicker-button cesium-sceneModePicker-buttonColumbusView';
nodeColumbus.setAttribute('data-bind', '\
css: { "cesium-sceneModePicker-visible" : (dropDownVisible && (sceneMode !== _sceneMode.COLUMBUS_VIEW)) || (!dropDownVisible && (sceneMode === _sceneMode.COLUMBUS_VIEW)),\
"cesium-sceneModePicker-none" : sceneMode === _sceneMode.COLUMBUS_VIEW,\
"cesium-sceneModePicker-hidden" : !dropDownVisible},\
attr: { title: tooltipColumbusView },\
click: morphToColumbusView');
container.appendChild(nodeColumbus);
this._nodeColumbus = nodeColumbus;
knockout.applyBindings(viewModel, container);
this._closeDropDown = function(e) {
if (!container.contains(e.target)) {
viewModel.dropDownVisible = false;
}
};
document.addEventListener('mousedown', this._closeDropDown, true);
document.addEventListener('touchstart', this._closeDropDown, true);
};
defineProperties(SceneModePicker.prototype, {
/**
* Gets the parent container.
* @memberof SceneModePicker.prototype
*
* @type {Element}
*/
container : {
get : function() {
return this._container;
}
},
/**
* Gets the view model.
* @memberof SceneModePicker.prototype
*
* @type {SceneModePickerViewModel}
*/
viewModel : {
get : function() {
return this._viewModel;
}
}
});
/**
* @memberof SceneModePicker
* @returns {Boolean} true if the object has been destroyed, false otherwise.
*/
SceneModePicker.prototype.isDestroyed = function() {
return false;
};
/**
* Destroys the widget. Should be called if permanently
* removing the widget from layout.
* @memberof SceneModePicker
*/
SceneModePicker.prototype.destroy = function() {
this._viewModel.destroy();
document.removeEventListener('mousedown', this._closeDropDown, true);
document.removeEventListener('touchstart', this._closeDropDown, true);
var container = this._container;
knockout.cleanNode(container);
container.removeChild(this._element);
container.removeChild(this._node3D);
container.removeChild(this._node2D);
container.removeChild(this._nodeColumbus);
return destroyObject(this);
};
return SceneModePicker;
});