-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadingbar.html
More file actions
233 lines (217 loc) · 7.51 KB
/
Copy pathloadingbar.html
File metadata and controls
233 lines (217 loc) · 7.51 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fly Charts</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.5/socket.io.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.css" />
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
}
#map {
width: 100%;
height: 100%;
position: relative;
z-index: 1;
}
#loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #0e0e0e;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: white;
z-index: 1000;
transition: opacity 0.5s;
}
#loading-screen.hidden {
opacity: 0;
pointer-events: none;
}
#logo-container {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
}
#logo-img {
width: 230px;
height: auto;
filter: invert(100%) sepia(100%) saturate(500%) hue-rotate(180deg);
margin-right: 20px;
}
#logo-text {
font-size: 96px;
font-weight: bold;
}
#progress-bar-container {
width: 80vw;
height: 30px;
background: #001b35;
border-radius: 15px;
overflow: hidden;
}
#progress-bar {
width: 0;
height: 100%;
background: #ae00ff;
transition: width 0.3s ease-in-out;
}
#status-message {
margin-top: 20px;
font-size: 24px;
text-align: center;
}
#aircraft-marker {
width: 20px;
height: 20px;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="red"><path d="M12 2L2 9h4v6h4v4l2 2 2-2v-4h4V9h4z"/></svg>') no-repeat center;
background-size: contain;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div id="loading-screen">
<div id="logo-container">
<img id="logo-img" src="image/airplaneoutline.svg" alt="Fly Charts Logo">
<span id="logo-text">Fly Charts</span>
</div>
<div id="progress-bar-container">
<div id="progress-bar"></div>
</div>
<div id="status-message">Initializing...</div>
</div>
<div id="map"></div>
<script>
// Initialize Socket.IO
const socket = io('http://localhost:5500');
// Initialize Leaflet map with performance optimizations
const map = L.map('map', {
zoomControl: true,
attributionControl: false,
preferCanvas: true,
renderer: L.canvas(),
zoomAnimationThreshold: 4,
fadeAnimation: false,
maxBoundsViscosity: 1.0
});
// Debounce function for zoom events
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Tile layer with optimized settings
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
tileSize: 256,
zoomOffset: 0,
updateWhenIdle: true,
keepBuffer: 4,
edgeBufferTiles: 2
}).addTo(map);
// Aircraft marker
let aircraftMarker = null;
// Loading state
let loadingProgress = 0;
let totalSteps = 3;
let statusMessages = {
0: 'Initializing...',
1: 'Loading map tiles...',
2: 'Connecting to SimConnect...',
3: 'Fetching aircraft data...'
};
// Update loading progress
function updateLoadingProgress(step) {
loadingProgress = Math.min(step, totalSteps);
const percentage = (loadingProgress / totalSteps) * 100;
document.getElementById('progress-bar').style.width = `${percentage}%`;
document.getElementById('status-message').textContent = statusMessages[loadingProgress] || 'Loading...';
if (loadingProgress >= totalSteps) {
setTimeout(() => {
document.getElementById('loading-screen').classList.add('hidden');
}, 500);
}
}
// Initial loading step
updateLoadingProgress(0);
// Map tile loading events
map.on('load', () => {
updateLoadingProgress(1);
});
// Optimize zoom performance
const debouncedZoom = debounce(() => {
map._onZoomEnd();
}, 100);
map.on('zoomstart', () => {
map._onZoomStart();
clearTimeout(map._zoomEndTimeout);
});
map.on('zoomend', () => {
map._zoomEndTimeout = setTimeout(debouncedZoom, 100);
});
// Socket.IO event handlers
socket.on('connect', () => {
console.log('Connected to WebSocket');
socket.emit('request_status');
socket.emit('request_position');
updateLoadingProgress(2);
});
socket.on('simconnect_status', (status) => {
console.log('SimConnect status:', status);
if (status.connected && status.last_position) {
const pos = status.last_position;
map.setView([pos.latitude, pos.longitude], 10);
if (!aircraftMarker) {
aircraftMarker = L.marker([pos.latitude, pos.longitude], {
icon: L.divIcon({
className: 'aircraft-marker',
html: '<div id="aircraft-marker"></div>',
iconSize: [20, 20]
})
}).addTo(map);
}
updateLoadingProgress(3);
}
});
socket.on('aircraft_position_update', (position) => {
if (position && position.latitude && position.longitude) {
if (!map.getBounds().isValid()) {
map.setView([position.latitude, position.longitude], 10);
}
if (aircraftMarker) {
aircraftMarker.setLatLng([position.latitude, position.longitude]);
aircraftMarker.setRotationAngle(position.heading || 0);
}
updateLoadingProgress(3);
}
});
socket.on('disconnect', () => {
console.log('Disconnected from WebSocket');
updateLoadingProgress(0);
document.getElementById('loading-screen').classList.remove('hidden');
});
// Initial map setup
map.setView([0, 0], 2);
</script>
</body>
</html>