-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
402 lines (333 loc) · 18.2 KB
/
index.html
File metadata and controls
402 lines (333 loc) · 18.2 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
390
391
392
393
394
395
396
397
398
399
400
401
402
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Waypoints</title>
<script src="https://cdn.tailwindcss.com"></script>
<!-- Phosphor Icons -->
<script src="https://unpkg.com/@phosphor-icons/web"></script>
<!-- Load User's Airport Data -->
<!-- Ensure airports_data.js is in the same directory -->
<script src="airports_data.js"></script>
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #f3f4f6;
}
.loader {
border: 3px solid #f3f3f3;
border-radius: 50%;
border-top: 3px solid #3b82f6;
width: 20px;
height: 20px;
-webkit-animation: spin 1s linear infinite; /* Safari */
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Tooltip animation for copy feedback */
.fade-in-out {
animation: fadeInOut 2s ease-in-out forwards;
}
@keyframes fadeInOut {
0% { opacity: 0; transform: translateY(10px); }
20% { opacity: 1; transform: translateY(0); }
80% { opacity: 1; transform: translateY(0); }
100% { opacity: 0; transform: translateY(-10px); }
}
</style>
</head>
<body class="flex items-center justify-center min-h-screen p-4">
<div class="bg-white rounded-xl shadow-lg w-full max-w-md overflow-hidden">
<!-- Header -->
<div class="bg-blue-600 p-6 text-center">
<h1 class="text-2xl font-bold text-white flex items-center justify-center gap-2">
<i class="ph ph-map-trifold"></i> Waypoints
</h1>
</div>
<!-- Content -->
<div class="p-6">
<form id="geoForm" class="space-y-4">
<div>
<textarea
id="address"
rows="2"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition resize-none"
placeholder="e.g. Kitty Hawk, North Carolina"
required></textarea>
</div>
<button
type="submit"
id="submitBtn"
class="w-full bg-blue-600 text-white font-semibold py-2 px-4 rounded-lg hover:bg-blue-700 transition duration-200 flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed">
<span>Get Coordinates</span>
<i class="ph ph-magnifying-glass"></i>
</button>
</form>
<!-- Loading State -->
<div id="loading" class="hidden mt-6 text-center text-gray-500 flex flex-col items-center">
<div class="loader mb-2"></div>
<p class="text-sm">Searching global database...</p>
</div>
<!-- Error Message -->
<div id="errorMessage" class="hidden mt-6 bg-red-50 border-l-4 border-red-500 p-4 rounded">
<div class="flex items-center">
<i class="ph ph-warning-circle text-red-500 text-xl mr-2"></i>
<p class="text-red-700 font-medium" id="errorText">Address not found.</p>
</div>
</div>
<!-- Result Card -->
<div id="resultCard" class="hidden mt-6 bg-gray-50 border border-gray-200 rounded-lg p-4 relative">
<div class="space-y-3 mb-4">
<!-- Bubble 0: Found Address (Click to Copy) -->
<div id="addressBubble" class="group bg-white p-3 rounded shadow-sm border border-gray-100 cursor-pointer hover:bg-blue-50 hover:border-blue-200 transition relative">
<div class="flex justify-between items-start gap-2">
<p id="foundAddress" class="text-sm text-gray-700 italic leading-relaxed font-medium break-words"></p>
<i class="ph ph-copy text-gray-400 group-hover:text-blue-500 flex-shrink-0 mt-1"></i>
</div>
<div id="copyFeedbackAddress" class="hidden absolute top-[-30px] right-0 bg-gray-800 text-white text-xs py-1 px-2 rounded shadow-lg z-10">Copied!</div>
</div>
<!-- Bubble 1: DMS (Degrees Minutes Seconds) -->
<div id="dmsBubble" class="group bg-white p-3 rounded shadow-sm border border-gray-100 cursor-pointer hover:bg-blue-50 hover:border-blue-200 transition relative">
<div class="flex justify-between items-center h-full">
<div>
<div class="font-mono font-bold text-gray-800 text-lg leading-tight">
<div id="dmsLat" class="whitespace-pre">--</div>
<div id="dmsLon" class="whitespace-pre">--</div>
</div>
</div>
<i class="ph ph-copy text-gray-400 group-hover:text-blue-500 flex-shrink-0 ml-auto"></i>
</div>
<div id="copyFeedbackDms" class="hidden absolute top-[-30px] right-0 bg-gray-800 text-white text-xs py-1 px-2 rounded shadow-lg z-10">Copied!</div>
</div>
<!-- Bubble 2: ForeFlight (Decimal / Decimal) -->
<div id="foreflightBubble" class="group bg-white p-3 rounded shadow-sm border border-gray-100 cursor-pointer hover:bg-blue-50 hover:border-blue-200 transition relative">
<div class="flex justify-between items-center h-full">
<div>
<div id="foreflightDisplay" class="font-mono font-bold text-blue-600 text-lg break-all">--</div>
</div>
<i class="ph ph-copy text-gray-400 group-hover:text-blue-500 flex-shrink-0 ml-auto"></i>
</div>
<div id="copyFeedbackForeflight" class="hidden absolute top-[-30px] right-0 bg-gray-800 text-white text-xs py-1 px-2 rounded shadow-lg z-10">Copied!</div>
</div>
</div>
<!-- Nearest Airports Section -->
<div id="airportSection" class="hidden mb-4">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-wider mb-2">Closest Airports</h3>
<div id="airportList" class="space-y-2">
<!-- Populated by JS -->
</div>
</div>
<!-- VFR Map Section -->
<div id="vfrMapSection" class="hidden relative rounded-lg overflow-hidden border border-gray-300 shadow-sm group">
<!-- Overlay Link (Invisible, covers map to capture clicks) -->
<a id="chartLink" href="#" target="_blank" class="absolute inset-0 z-10 cursor-pointer" title="Click to open full chart in SkyVector">
</a>
<!-- Embedded Map (VFRMap as proxy for visual style) -->
<iframe id="vfrFrame" class="w-full h-48 border-0" scrolling="no" src=""></iframe>
</div>
</div>
</div>
<div class="bg-gray-50 px-6 py-3 border-t border-gray-100">
<p class="text-xs text-center text-gray-400">Powered by OpenStreetMap & Nominatim</p>
</div>
</div>
<script>
const form = document.getElementById('geoForm');
const addressInput = document.getElementById('address');
const submitBtn = document.getElementById('submitBtn');
const loading = document.getElementById('loading');
const resultCard = document.getElementById('resultCard');
const errorMessage = document.getElementById('errorMessage');
const errorText = document.getElementById('errorText');
const dmsLat = document.getElementById('dmsLat');
const dmsLon = document.getElementById('dmsLon');
const foreflightDisplay = document.getElementById('foreflightDisplay');
const foundAddress = document.getElementById('foundAddress');
const addressBubble = document.getElementById('addressBubble');
const dmsBubble = document.getElementById('dmsBubble');
const foreflightBubble = document.getElementById('foreflightBubble');
const airportSection = document.getElementById('airportSection');
const airportList = document.getElementById('airportList');
const vfrMapSection = document.getElementById('vfrMapSection');
const vfrFrame = document.getElementById('vfrFrame');
const chartLink = document.getElementById('chartLink');
// Haversine Formula for Spherical Earth
function getDistanceNM(lat1, lon1, lat2, lon2) {
const R = 3440.065; // Earth Radius in Nautical Miles
const toRad = (value) => value * Math.PI / 180;
const dLat = toRad(lat2 - lat1);
const dLon = toRad(lon2 - lon1);
const a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
function findClosestAirports(lat, lon) {
if (typeof AIRPORTS_DATA === 'undefined' || !Array.isArray(AIRPORTS_DATA)) {
console.warn("AIRPORTS_DATA not found. Make sure airports_data.js is loaded.");
return [];
}
// Map distances
const airportsWithDist = AIRPORTS_DATA.map(airport => {
// Schema: [gps_code, latitude_deg, longitude_deg, longest_runway_ft, name]
const dist = getDistanceNM(lat, lon, airport[1], airport[2]);
return {
code: airport[0],
lat: airport[1],
lon: airport[2],
runway: airport[3],
name: airport[4],
dist: dist
};
});
// Sort by distance ascending
airportsWithDist.sort((a, b) => a.dist - b.dist);
// Return top 3
return airportsWithDist.slice(0, 3);
}
function renderAirports(airports, originLat, originLon) {
airportList.innerHTML = '';
if (airports.length === 0) {
airportSection.classList.add('hidden');
return;
}
airports.forEach(apt => {
const item = document.createElement('div');
item.className = "bg-gray-50 p-2 rounded border border-gray-100 flex items-center justify-between";
// Format runway length (e.g. 10000 -> 10,000)
const rwy = apt.runway ? `${apt.runway.toLocaleString()}ft` : "N/A";
// Google Maps Driving Directions: From Airport TO Waypoint
// Origin: Airport, Dest: Waypoint
const driveLink = `https://www.google.com/maps/dir/?api=1&origin=${apt.lat},${apt.lon}&destination=${originLat},${originLon}&travelmode=driving`;
// AirNav Link
const airnavLink = `https://www.airnav.com/airport/${apt.code}`;
item.innerHTML = `
<div class="flex-1 min-w-0 pr-2">
<div class="flex items-center gap-2">
<a href="${airnavLink}" target="_blank" class="text-blue-600 font-bold hover:underline font-mono text-sm">${apt.code}</a>
<span class="text-xs text-gray-500 font-mono">${apt.dist.toFixed(1)}nm</span>
</div>
<div class="text-xs text-gray-800 truncate" title="${apt.name}">${apt.name}</div>
<div class="text-[10px] text-gray-400">Rwy: ${rwy}</div>
</div>
<a href="${driveLink}" target="_blank" title="Drive from Airport to Waypoint" class="flex-shrink-0 w-8 h-8 flex items-center justify-center bg-white border border-gray-200 rounded-full text-blue-600 hover:bg-blue-50 transition">
<i class="ph ph-car text-lg"></i>
</a>
`;
airportList.appendChild(item);
});
airportSection.classList.remove('hidden');
}
// Updated Function: Degrees Minutes Seconds (DMS)
function toDMS(coordinate, isLat) {
const absolute = Math.abs(coordinate);
const degrees = Math.floor(absolute);
// Get remainder for minutes
const minutesDecimal = (absolute - degrees) * 60;
const minutes = Math.floor(minutesDecimal);
// Get remainder for seconds
const seconds = (minutesDecimal - minutes) * 60;
const minutesStr = minutes.toString().padStart(2, '0');
const secondsStr = seconds.toFixed(2).padStart(5, '0');
let direction = "";
let degreesStr = degrees.toString();
if (isLat) {
// Space after direction for Lat
direction = coordinate >= 0 ? "N " : "S ";
} else {
direction = coordinate >= 0 ? "E" : "W";
degreesStr = degrees.toString().padStart(3, '0');
}
// Format: N 36°45'30.50"
return `${direction}${degreesStr}°${minutesStr}'${secondsStr}"`;
}
function toForeFlightDecimal(lat, lon) {
return `${lat.toFixed(5)}/${lon.toFixed(5)}`;
}
// Generic Copy Function
function setupCopy(element, textGetter, feedbackId) {
const feedbackEl = document.getElementById(feedbackId);
element.addEventListener('click', () => {
const textToCopy = textGetter();
if(textToCopy && !textToCopy.includes('--')) {
navigator.clipboard.writeText(textToCopy).then(() => {
feedbackEl.classList.remove('hidden');
feedbackEl.classList.add('fade-in-out');
setTimeout(() => {
feedbackEl.classList.add('hidden');
feedbackEl.classList.remove('fade-in-out');
}, 2000);
}).catch(err => {
console.error('Failed to copy text: ', err);
});
}
});
}
// Setup Copy Listeners
setupCopy(addressBubble, () => foundAddress.textContent, 'copyFeedbackAddress');
setupCopy(dmsBubble, () => {
return `${dmsLat.textContent}\n${dmsLon.textContent}`;
}, 'copyFeedbackDms');
setupCopy(foreflightBubble, () => foreflightDisplay.textContent, 'copyFeedbackForeflight');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const address = addressInput.value.trim();
if (!address) return;
// Reset UI
errorMessage.classList.add('hidden');
resultCard.classList.add('hidden');
airportSection.classList.add('hidden');
vfrMapSection.classList.add('hidden');
loading.classList.remove('hidden');
submitBtn.disabled = true;
submitBtn.querySelector('span').textContent = "Searching...";
try {
// Request address details to help build AirNav link
const url = `https://nominatim.openstreetmap.org/search?format=json&addressdetails=1&q=${encodeURIComponent(address)}&limit=1`;
const response = await fetch(url, {
headers: {
'Accept-Language': 'en-US,en;q=0.5'
}
});
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
if (data.length === 0) {
throw new Error('Address could not be found. Please try being more specific.');
}
const result = data[0];
const lat = parseFloat(result.lat);
const lon = parseFloat(result.lon);
// Bubble 1: DMS (Degrees Minutes Seconds)
dmsLat.textContent = toDMS(lat, true);
dmsLon.textContent = toDMS(lon, false);
// Bubble 2: ForeFlight
foreflightDisplay.textContent = toForeFlightDecimal(lat, lon);
// Address Bubble
foundAddress.textContent = result.display_name;
// --- Calculate Closest Airports ---
const closestAirports = findClosestAirports(lat, lon);
renderAirports(closestAirports, lat, lon);
// --- VFR Map Section ---
// SkyVector Link (Actual Destination for the marker/reticle)
chartLink.href = `https://skyvector.com/?ll=${lat},${lon}&chart=301&zoom=3`;
// VFRMap Embed (Visual Proxy because it allows iframing)
vfrFrame.src = `https://vfrmap.com/map.html?lat=${lat}&lon=${lon}&zoom=10&map=sec`;
vfrMapSection.classList.remove('hidden');
resultCard.classList.remove('hidden');
} catch (error) {
console.error(error);
errorText.textContent = error.message;
errorMessage.classList.remove('hidden');
} finally {
loading.classList.add('hidden');
submitBtn.disabled = false;
submitBtn.querySelector('span').textContent = "Get Coordinates";
}
});
</script>
</body>
</html>