-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathgmap.html
More file actions
389 lines (344 loc) · 14.3 KB
/
gmap.html
File metadata and controls
389 lines (344 loc) · 14.3 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<title>Dump1090</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"
integrity="sha512-2SwdPD6INVrV/lHTZbO2nodKhrnDdJK9/kg2XD1r9uGqPo1cUbujc+IYdlYdEErWNu69gVcYgdxlmVmzTWnetw=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
/* Base styles */
body {
margin: 0;
padding: 0;
height: 100dvh;
}
/* Map block */
.map {
width: 100%;
height: 100%;
}
/* Plane icon block */
.plane-icon {
padding: 0;
margin: 0;
cursor: pointer;
transition: transform 500ms linear;
}
.plane-icon__symbol {
font-size: 24px;
line-height: 32px;
width: 32px;
height: 32px;
text-align: center;
cursor: pointer;
color: #ffd700;
-webkit-text-stroke: 1px #000000;
}
.plane-icon__symbol--selected {
color: #ff6b6b;
}
/* Info panel block */
.info-panel {
position: absolute;
top: 20px;
right: 20px;
width: 260px;
background-color: rgba(20, 20, 30, 0.6);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
font-family: system-ui, sans-serif;
z-index: 1000;
touch-action: none;
user-select: none;
color: #ffffff;
}
.info-panel__header {
padding: 12px 16px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
cursor: move;
}
.info-panel__title {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #ffffff;
}
.info-panel__content {
padding: 12px 16px;
margin: 0;
}
.info-panel__text {
font-size: 14px;
color: rgba(255, 255, 255, 0.85);
margin: 0 0 8px 0;
line-height: 1.5;
}
.info-panel__text:last-child {
margin-bottom: 0;
}
.info-panel__flight {
font-size: 20px;
font-weight: 700;
color: #ffffff;
margin: 0 0 4px 0;
}
.info-panel__icao {
font-size: 12px;
color: rgba(255, 255, 255, 0.5);
margin: 0 0 12px 0;
font-family: monospace;
}
.info-panel__grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.info-panel__item {
display: flex;
flex-direction: column;
gap: 2px;
}
.info-panel__label {
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: rgba(255, 255, 255, 0.5);
}
.info-panel__value {
font-size: 15px;
font-weight: 500;
color: #ffffff;
}
.info-panel__coords {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
font-size: 12px;
font-family: monospace;
color: rgba(255, 255, 255, 0.7);
}
</style>
</head>
<body>
<!-- Canvas for Leaflet map -->
<div id="canvas" class="map"></div>
<!-- Floating info panel -->
<div class="info-panel" id="info-panel">
<div class="info-panel__header">
<h1 class="info-panel__title">Dump1090</h1>
</div>
<div class="info-panel__content">
<p id="generalInfo" class="info-panel__text"></p>
<p id="planeInfo" class="info-panel__text">Click on a plane for info</p>
</div>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="https://cdn.jsdelivr.net/npm/interactjs@1.10.27/dist/interact.min.js"></script>
<script type="module">
// Leaflet map instance and planes state
let map = null;
const planes = {};
let selectedPlane = null;
let copyingHex = null; // tracks which plane's info is being shown as "copied"
// Update panel general info
const updateGeneralInfo = () => {
const el = document.getElementById('generalInfo');
const planesCount = Object.keys(planes).length;
el.innerHTML = `
<span class="info-panel__value">${planesCount}</span>
<span class="info-panel__label">aircraft tracked</span>
`;
};
// Update panel with new plane info
const updatePlaneInfo = (newPlane) => {
// Exit if new plane is not found, or if we're currently showing "Copied!" feedback
if (!newPlane || copyingHex === newPlane.hex) return;
// Update selected plane info
const el = document.getElementById('planeInfo');
el.innerHTML = `
<div class="info-panel__flight" data-copy="${newPlane.flight || '—'}" onclick="copyField(this)" title="Click to copy">${newPlane.flight || '—'}</div>
<div class="info-panel__icao" data-copy="${newPlane.hex}" onclick="copyField(this)" title="Click to copy">${newPlane.hex}</div>
<div class="info-panel__grid">
<div class="info-panel__item">
<span class="info-panel__label">Altitude</span>
<span class="info-panel__value" data-copy="${newPlane.altitude ?? '—'}" onclick="copyField(this)" title="Click to copy">${newPlane.altitude ?? '—'} ft</span>
</div>
<div class="info-panel__item">
<span class="info-panel__label">Speed</span>
<span class="info-panel__value" data-copy="${newPlane.speed ?? '—'}" onclick="copyField(this)" title="Click to copy">${newPlane.speed ?? '—'} kts</span>
</div>
<div class="info-panel__item">
<span class="info-panel__label">Heading</span>
<span class="info-panel__value" data-copy="${newPlane.track ?? '—'}" onclick="copyField(this)" title="Click to copy">${newPlane.track ?? '—'}°</span>
</div>
</div>
<div class="info-panel__coords" data-copy="${newPlane.lat.toFixed(4)}, ${newPlane.lon.toFixed(4)}" onclick="copyField(this)" title="Click to copy">${newPlane.lat.toFixed(4)}, ${newPlane.lon.toFixed(4)}</div>
`;
};
// Copy text to clipboard when clicking on value elements
// Defines copyField function on the global window object to be accessible from inline onclick handlers
window.copyField = (el) => {
const text = el.dataset.copy;
if (!text || text === '—') return;
copyingHex = selectedPlane?.hex;
const finish = () => {
const original = el.innerHTML;
el.innerHTML = 'Copied!';
setTimeout(() => {
el.innerHTML = original;
copyingHex = null;
}, 1500);
};
if (navigator.clipboard) {
navigator.clipboard.writeText(text).then(finish);
} else {
// non-secure contexts (not on https or localhost)
const ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
finish();
}
};
// Create a custom marker with Font Awesome plane icon
const getIconForPlane = (plane) => {
const icon = L.divIcon({
html: `
<div
class="plane-icon__symbol${selectedPlane?.hex === plane.hex ? ' plane-icon__symbol--selected' : ''}"
style="transform: rotate(${plane.track ?? 0}deg);"
>
<i class="fa-solid fa-plane-up"></i>
</div>
`,
className: 'plane-icon',
iconSize: [32, 32],
iconAnchor: [16, 16]
});
return icon;
};
// Select a new plane
const selectPlane = (newPlane) => {
// Exit if new plane is not found
if (!newPlane) return;
// Update plane selection
const oldPlane = planes[selectedPlane?.hex];
selectedPlane = newPlane;
// Remove highlighting from the previously selected plane
oldPlane?.marker.setIcon(getIconForPlane(oldPlane));
// Update currently selected plane
newPlane.marker.setIcon(getIconForPlane(newPlane));
updatePlaneInfo(newPlane);
};
// Fetch planes data from the server
const fetchData = async () => {
try {
const response = await fetch('/data.json');
if (!response.ok) return;
const data = await response.json();
const activePlanes = {};
for (const plane of data) {
// Skip planes without valid coordinates
if (plane.lat == null || plane.lon == null) continue;
// Build the plane list from the fetched data
let marker = null;
activePlanes[plane.hex] = true;
plane.flight = plane.flight?.trim() || '';
const existingPlane = planes[plane.hex];
if (existingPlane) {
// Update existing plane marker position
marker = existingPlane.marker;
marker.setLatLng([plane.lat, plane.lon]);
// Update existing plane marker icon if track changed significantly
if (existingPlane.track != null && plane.track != null) {
let trackDelta = Math.abs(existingPlane.track - plane.track);
if (trackDelta > 180) trackDelta = 360 - trackDelta;
if (trackDelta > 5) marker.setIcon(getIconForPlane(plane));
}
// Update existing plane properties
existingPlane.altitude = plane.altitude;
existingPlane.speed = plane.speed;
existingPlane.lat = plane.lat;
existingPlane.lon = plane.lon;
existingPlane.track = plane.track;
existingPlane.flight = plane.flight;
// Update existing plane info in the panel if it is selected
if (existingPlane.hex === selectedPlane?.hex) {
updatePlaneInfo(existingPlane);
}
} else {
// Create a new marker for new planes
const icon = getIconForPlane(plane);
marker = L.marker([plane.lat, plane.lon], { icon: icon }).addTo(map);
plane.marker = marker;
planes[plane.hex] = plane;
marker.on('click', () => selectPlane(planes[plane.hex]));
}
}
// Remove idle planes
for (const plane of Object.values(planes)) {
if (!activePlanes[plane.hex]) {
map.removeLayer(plane.marker);
delete planes[plane.hex];
if (selectedPlane?.hex === plane.hex) {
selectedPlane = null;
document.getElementById('planeInfo').innerHTML = 'Click on a plane for info';
}
}
}
} catch (error) {
console.error('Error fetching data:', error);
}
};
// Make info panel draggable
interact('#info-panel').draggable({
allowFrom: '.info-panel__header',
listeners: {
move: (event) => {
const target = event.target;
const x = (parseFloat(target.dataset.x) || 0) + event.dx;
const y = (parseFloat(target.dataset.y) || 0) + event.dy;
target.style.transform = `translate(${x}px, ${y}px)`;
target.dataset.x = x;
target.dataset.y = y;
}
}
});
// Initialize Leaflet instance
const savedView = JSON.parse(localStorage.getItem('mapView'));
map = L.map('canvas').setView(
savedView ? [savedView.lat, savedView.lng] : [37.0, 13.0],
savedView ? savedView.zoom : 8
);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
map.on('moveend', () => {
const center = map.getCenter();
localStorage.setItem('mapView', JSON.stringify({
lat: center.lat,
lng: center.lng,
zoom: map.getZoom()
}));
});
// Setup a timer to poll from the server
setInterval(() => {
fetchData();
updateGeneralInfo();
}, 100);
</script>
</body>
</html>