-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinningglobe.html
203 lines (193 loc) · 5.22 KB
/
spinningglobe.html
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
203
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Spinning Globe</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.12/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#optionsDiv {
position: absolute;
bottom: 17px;
width: 100%;
padding: 20px 0;
z-index: 1;
text-align: center;
}
button {
background: white;
padding: 7px;
border: 1px solid #005e95;
font-size: 0.9em;
margin: 5px;
color: #005e95;
}
button:hover {
background: #005e95;
color: white;
cursor: pointer;
}
</style>
<script>
require(["esri/Map", "dojo/_base/lang", "esri/views/SceneView","esri/geometry/support/webMercatorUtils", "esri/WebScene"], function(Map, lang, SceneView,webMercatorUtils, WebScene) {
var playing = false;
var vizTimer = null;
var spinTimer = null;
var scene = new WebScene({
portalItem: {
id: "0501d86cca56496a801b680ee0fcfd6b"
}
});
var view = new SceneView({
container: "viewDiv",
map: scene,
zoom: 1
});
scene.load()
.then(function() {
// load the basemap to get its layers created
return scene.basemap.load();
})
.then(function() {
// grab all the layers and load them
var allLayers = scene.allLayers;
var promises = allLayers.map(function(layer) {
return layer.load();
});
return Promise.all(promises.toArray());
})
.then(function(layers) {
// each layer load promise resolves with the layer
console.log("all " + layers.length + " layers loaded");
_toggleVizTimer();
})
.catch(function(error) {
console.error(error);
});
//if(scene.loaded) {
// _toggleVizTimer();
//}
//scene
// .when(function() {
// console.log("inside watch");
// _toggleVizTimer();
//});
/*****************************************************************
*
* Add event listeners to go to a target point using animation options
*
*****************************************************************/
// The target point is a new camera obtained by shifting the current camera 30 degrees to the east
document
.getElementById("linearSlow")
.addEventListener("click", function() {
//console.log(playing);
_toggleVizTimer();
});
function _toggleVizTimer() {
var theText = document.getElementById("linearSlow");
console.log(theText.innerHTML);
if (theText.innerHTML == 'Playing') {
theText.innerHTML = "Play";
console.log("afterstopvis: " + theText.innerHTML);
_stopVizTimer();
}
else if (theText.innerHTML == "Play") {
theText.innerHTML = 'Playing';
console.log("toggleviz playing");
var text = document.getElementById("linearSlow").innerHTML;
console.log("elseif :" + text);
_startVizTimer();
}
else {
theText.innerHTML = 'Playing';
console.log("elsed playing");
var text = document.getElementById("linearSlow").innerHTML;
console.log("toggleviz:" + text);
_startVizTimer();
}
}
// stop spin
function _stopSpin() {
//console.log("stopping");
if (spinTimer) {
clearInterval(spinTimer);
spinTimer = null;
}
}
// do spin
function _doSpin() {
var pos = view.camera.position;
var posGeo = pos;
if (pos.spatialReference.isWebMercator) {
posGeo = webMercatorUtils.webMercatorToGeographic(pos);
}
var posX = posGeo.x - 1;
if (posX <= -180) {
posX = 179;
}
var posZ = pos.z;
if (posZ < 8000000) {
posZ = 8000000;
}
//console.log(posX)
view.goTo({
position: [posX, 0, posZ],
tilt: 5,
heading: 0
}, {
maxDuration: 900
});
}
// start spin
function _startSpin() {
_stopSpin();
//_doSpin();
spinTimer = setInterval(_doSpin, 100);
}
// start viz timer
function _startVizTimer() {
_stopVizTimer();
//vizTimer = setInterval(0, 100);
//if (view.viewingMode === "global") {
_startSpin();
//}
playing = true;
//domClass.add("btnPlay", "playing");
}
// stop viz timer
function _stopVizTimer() {
if (vizTimer) {
clearInterval(vizTimer);
vizTimer = null;
}
_stopSpin();
//playing = false;
//var theText = document.getElementById("linearSlow");
//theText.innerHTML="Play";
}
});
</script>
</head>
<body>
<div id="optionsDiv">
<button id="linearSlow">Start Animation</button>
</div>
<div id="viewDiv"></div>
</body>
</html>