-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathCanyon.js
More file actions
169 lines (157 loc) · 6.94 KB
/
Copy pathCanyon.js
File metadata and controls
169 lines (157 loc) · 6.94 KB
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
/*
* Copyright 2015-2017 WorldWind Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
requirejs(['./WorldWindShim'],
function (WorldWind) {
"use strict";
WorldWind.Logger.setLoggingLevel(WorldWind.Logger.LEVEL_WARNING);
var wwd = new WorldWind.WorldWindow("canvasOne");
var camera = wwd.camera;
var lookAt = new WorldWind.LookAt();
wwd.cameraAsLookAt(lookAt);
var layers = [
{layer: new WorldWind.BMNGLayer(), enabled: true},
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
{layer: new WorldWind.CompassLayer(), enabled: true},
{layer: new WorldWind.CoordinatesDisplayLayer(wwd), enabled: true}
];
for (var l = 0; l < layers.length; l++) {
layers[l].layer.enabled = layers[l].enabled;
wwd.addLayer(layers[l].layer);
}
var atmosphereLayer = new WorldWind.AtmosphereLayer();
wwd.addLayer(atmosphereLayer);
var canyonCheckBox = document.getElementById('canyon');
var canyonInterval = 0;
canyonCheckBox.addEventListener('change', onCanyonCheckBoxClick, false);
var canyonTour = [];
canyonTour.push({
position: new WorldWind.Position(36.17, -112.04, 2000),
heading: -150,
tilt: 70,
finished: false
});
canyonTour.push({
position: new WorldWind.Position(36.10, -112.10, 2000),
heading: 90,
tilt: 70,
finished: false
});
canyonTour.push({
position: new WorldWind.Position(36.10, -112.08, 2000),
heading: 120,
tilt: 70,
finished: false
});
canyonTour.push({
position: new WorldWind.Position(36.05, -111.98, 2000),
heading: 120,
tilt: 70,
finished: false
});
var canyonLatInc;
var canyonLonInc;
var headingInc;
var tiltInc;
var segmentStart = true;
var fromIndex = 0;
var toIndex = 1;
var fromNode = canyonTour[fromIndex];
var toNode = canyonTour[toIndex];
var traversalDir = 1, segHeading, segCompassHeading, headingSteps;
function goToCanyonStartComplete() {
runCanyonSimulation();
}
function onCanyonCheckBoxClick() {
if (this.checked) {
wwd.goTo(fromNode.position, goToCanyonStartComplete);
}
else {
clearInterval(canyonInterval);
wwd.redraw();
}
}
function runCanyonSimulation() {
canyonInterval = setInterval(function () {
if (toNode.finished) {
fromIndex = toIndex;
toIndex += traversalDir;
var reset = false;
if (toIndex === canyonTour.length) {
traversalDir = -1;
reset = true;
}
else if (toIndex < 0) {
traversalDir = 1;
reset = true;
}
if (reset) {
toIndex = fromIndex + traversalDir;
for (var i = 0; i < canyonTour.length; i++) {
canyonTour[i].finished = false;
}
}
fromNode = canyonTour[fromIndex];
toNode = canyonTour[toIndex];
segmentStart = true;
}
var camCompassHeading;
if (segmentStart) {
segmentStart = false;
var radiansPerFrame = 0.001 / 480
var numFrames = Math.ceil(WorldWind.Location.greatCircleDistance(fromNode.position, toNode.position) / radiansPerFrame);
canyonLatInc = (toNode.position.latitude - fromNode.position.latitude) / numFrames;
canyonLonInc = (toNode.position.longitude - fromNode.position.longitude) / numFrames;
segHeading = traversalDir < 0 ? WorldWind.Angle.normalizedDegrees(toNode.heading + 180) : fromNode.heading;
segCompassHeading = segHeading < 0 ? segHeading + 360 : segHeading;
camCompassHeading = camera.heading < 0 ? camera.heading + 360 : camera.heading;
var headingDiff = segCompassHeading - camCompassHeading;
if (Math.abs(headingDiff) >= 180) {
headingDiff = headingDiff < 0 ? headingDiff + 360 : headingDiff - 360;
}
var angleInc = 0.25;
headingSteps = Math.floor(Math.abs(headingDiff) / angleInc);
headingInc = Math.sign(headingDiff) * angleInc;
tiltInc = Math.sign(fromNode.tilt - camera.tilt) * angleInc;
camera.position.altitude = fromNode.position.altitude;
}
if (headingSteps > 0 || tiltInc !== 0) {
camCompassHeading = camera.heading < 0 ? camera.heading + 360 : camera.heading;
camera.heading = WorldWind.Angle.normalizedDegrees(camCompassHeading + headingInc);
camera.tilt += tiltInc;
headingSteps--;
if (headingSteps <= 0) {
headingInc = 0;
camera.heading = segHeading;
}
if ((tiltInc > 0 && camera.tilt >= fromNode.tilt) ||
(tiltInc < 0 && camera.tilt <= fromNode.tilt)) {
tiltInc = 0;
camera.tilt = fromNode.tilt;
}
} else {
camera.position.latitude += canyonLatInc;
camera.position.longitude += canyonLonInc;
if ((canyonLatInc > 0 && camera.position.latitude > toNode.position.latitude) ||
(canyonLatInc < 0 && camera.position.latitude < toNode.position.latitude) ||
(canyonLonInc > 0 && camera.position.longitude > toNode.position.longitude) ||
(canyonLonInc < 0 && camera.position.longitude < toNode.position.longitude)) {
toNode.finished = true;
}
}
wwd.redraw();
}, 25);
}
});