-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimation.html
More file actions
238 lines (192 loc) · 7.64 KB
/
animation.html
File metadata and controls
238 lines (192 loc) · 7.64 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Animated Shortest Paths</title>
<input type="file" name="file" id="file">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example creates a 2-pixel-wide red polyline showing the path of William
// Kingsford Smith's first trans-Pacific flight between Oakland, CA, and
// Brisbane, Australia.
//
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat: (37.7155 + 37.8085)/2, lng: (-121.741 + -121.994)/2},
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var flightPlanCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027},{lat: -32.467, lng: 150.027}
];
// flightPath.setMap(map);
// flightPath.setMap(null);
// flightPath = null;
var i = 1;
var startLat = 37.772; // set your counter to 1
function myLoop () { // create a loop function
setTimeout(function () { // call a 3s setTimeout when the loop is called
var path = [{lat: startLat, lng: -122.214},
{lat: 21.291, lng: -157.821}];
startLat += 2;
console.log(path)
var flightPath = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#FF00F0',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map)
// your code here
i++; // increment the counter
if (i < 10) { // if the counter < 10, call the loop function
myLoop(); // .. again which will trigger another
} // .. setTimeout()
}, 100)
}
// myLoop();
document.getElementById('file').onchange = function(){
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(progressEvent){
// Entire file
// console.log(this.result);
// By lines
var lines = this.result.split('\n');
var i = 2;
var latestU;
var latestF;
var latestB;
var FEnd = true;
var end = false;
function testLoop () { // create a loop function
setTimeout(function () { // call a 3s setTimeout when the loop is called
i++; // increment the counter
var temp = lines[i].split(/[ ,]+/);
console.log(temp)
if (String(temp[0])=="c"){
end = true;
}
while (String(temp[0])=="u" && end == false){
latestU = temp;
i++;
temp = lines[i].split(/[ ,]+/);
if (String(temp[0])=="c"){
end = true;
}
}
if (end){
i = i + 2;
while (i<lines.length){
temp1 = lines[i-1].split(/[ ,]+/);
temp2 = lines[i].split(/[ ,]+/);
path = [{lng: Number(temp1[1]), lat: Number(temp1[2])},{lng: Number(temp2[1]), lat: Number(temp2[2])}];
var flightPath = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 5
});
flightPath.setMap(map);
i++;
}
}
if (String(temp[0])=="b"){
latestB = temp;
FEnd = false;
}else{
latestF = temp;
FEnd = true;
}
console.log(i)
// console.log(latestA, latestU);
//9b59b6
if (end == false){
var path;
if (FEnd ){
path = [{lng: Number(latestU[1]), lat: Number(latestU[2])},{lng: Number(latestF[1]), lat: Number(latestF[2])}];
var flightPath = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#3498db',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
} else{
path = [{lng: Number(latestU[1]), lat: Number(latestU[2])},{lng: Number(latestB[1]), lat: Number(latestB[2])}];
var flightPath = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#9b59b6',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
}
console.log(path);
if (i < lines.length) { // if the counter < 10, call the loop function
testLoop(); // .. again which will trigger another
} // .. setTimeout()
}, 0)
}
testLoop();
var pastI = lines[1].split(/[ ,]+/);
var presentI = lines[2].split(/[ ,]+/);
var pathI = [{lng: Number(pastI[1]), lat: Number(pastI[2])},{lng: Number(presentI[1]), lat: Number(presentI[2])}];
var flightPath = new google.maps.Polyline({
path: pathI,
geodesic: true,
strokeColor: '#c0392b',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map)
// for(var line = 0; line < lines.length; line++){
// if (line > 1){
// var past = lines[line-1].split(/[ ,]+/);
// var present = lines[line].split(/[ ,]+/);
// var path = [{lng: Number(past[1]), lat: Number(past[2])},{lng: Number(present[1]), lat: Number(present[2])}];
// console.log(path);
// var flightPath = new google.maps.Polyline({
// path: path,
// geodesic: true,
// strokeColor: '#FF00F0',
// strokeOpacity: 1.0,
// strokeWeight: 2
// });
// flightPath.setMap(map)
// }
// if (line > 1000){
// break;
// }
// }
};
reader.readAsText(file);
};
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKs_s2gQvz_jdAZ77dWmIRuNe_oERtpek&callback=initMap">
</script>
</body>
</html>